ETCDPadInspector.cs 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using UnityEngine.UI;
  5. #if UNITY_5_3
  6. using UnityEditor.SceneManagement;
  7. #endif
  8. [CustomEditor(typeof(ETCDPad))]
  9. public class ETCDPadInspector : Editor {
  10. public string[] unityAxes;
  11. void OnEnable(){
  12. var inputManager = AssetDatabase.LoadAllAssetsAtPath("ProjectSettings/InputManager.asset")[0];
  13. SerializedObject obj = new SerializedObject(inputManager);
  14. SerializedProperty axisArray = obj.FindProperty("m_Axes");
  15. if (axisArray.arraySize > 0){
  16. unityAxes = new string[axisArray.arraySize];
  17. for( int i = 0; i < axisArray.arraySize; ++i ){
  18. var axis = axisArray.GetArrayElementAtIndex(i);
  19. unityAxes[i] = axis.FindPropertyRelative("m_Name").stringValue;
  20. }
  21. }
  22. }
  23. public override void OnInspectorGUI(){
  24. ETCDPad t = (ETCDPad)target;
  25. EditorGUILayout.Space();
  26. t.activated = ETCGuiTools.Toggle("Activated",t.activated,true);
  27. t.visible = ETCGuiTools.Toggle("Visible",t.visible,true);
  28. EditorGUILayout.Space();
  29. t.useFixedUpdate = ETCGuiTools.Toggle("Use Fixed Updae",t.useFixedUpdate,true);
  30. t.isUnregisterAtDisable = ETCGuiTools.Toggle("Unregister at disabling time",t.isUnregisterAtDisable,true);
  31. #region Position & Size
  32. t.showPSInspector = ETCGuiTools.BeginFoldOut( "Position & Size",t.showPSInspector);
  33. if (t.showPSInspector){
  34. ETCGuiTools.BeginGroup();{
  35. // Anchor
  36. t.anchor = (ETCBase.RectAnchor)EditorGUILayout.EnumPopup( "Anchor",t.anchor);
  37. if (t.anchor != ETCBase.RectAnchor.UserDefined){
  38. t.anchorOffet = EditorGUILayout.Vector2Field("Offset",t.anchorOffet);
  39. }
  40. EditorGUILayout.Space();
  41. // Area sprite ratio
  42. Rect rect = t.GetComponent<Image>().sprite.rect;
  43. float ratio = rect.width / rect.height;
  44. // Area Size
  45. if (ratio>=1){
  46. float s = EditorGUILayout.FloatField("Size", t.rectTransform().rect.width);
  47. t.rectTransform().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,s);
  48. t.rectTransform().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,s/ratio);
  49. }
  50. else{
  51. float s = EditorGUILayout.FloatField("Size", t.rectTransform().rect.height);
  52. t.rectTransform().SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical,s);
  53. t.rectTransform().SetSizeWithCurrentAnchors(RectTransform.Axis.Horizontal,s*ratio);
  54. }
  55. t.buttonSizeCoef = EditorGUILayout.FloatField("Button size coef",t.buttonSizeCoef);
  56. }ETCGuiTools.EndGroup();
  57. }
  58. #endregion
  59. #region Axes properties
  60. t.showBehaviourInspector = ETCGuiTools.BeginFoldOut( "Axes properties",t.showBehaviourInspector);
  61. if (t.showBehaviourInspector){
  62. ETCGuiTools.BeginGroup();{
  63. EditorGUILayout.Space();
  64. t.enableKeySimulation = ETCGuiTools.Toggle("Enable key simulation",t.enableKeySimulation,true);
  65. if (t.enableKeySimulation){
  66. t.allowSimulationStandalone = ETCGuiTools.Toggle("Allow simulation on standalone",t.allowSimulationStandalone,true);
  67. t.visibleOnStandalone = ETCGuiTools.Toggle("Force visible",t.visibleOnStandalone,true);
  68. }
  69. EditorGUILayout.Space();
  70. t.dPadAxisCount = (ETCDPad.DPadAxis)EditorGUILayout.EnumPopup("Axes count",t.dPadAxisCount);
  71. EditorGUILayout.Space();
  72. ETCGuiTools.BeginGroup(5);{
  73. ETCAxisInspector.AxisInspector( t.axisX,"Horizontal", ETCBase.ControlType.DPad,false,unityAxes);
  74. }ETCGuiTools.EndGroup();
  75. ETCGuiTools.BeginGroup(5);{
  76. ETCAxisInspector.AxisInspector( t.axisY,"Vertical" ,ETCBase.ControlType.DPad,false,unityAxes);
  77. }ETCGuiTools.EndGroup();
  78. }ETCGuiTools.EndGroup();
  79. }
  80. #endregion
  81. #region Sprite
  82. t.showSpriteInspector = ETCGuiTools.BeginFoldOut( "Sprites",t.showSpriteInspector);
  83. if (t.showSpriteInspector){
  84. ETCGuiTools.BeginGroup();{
  85. Sprite frameSprite = t.GetComponent<Image>().sprite;
  86. EditorGUILayout.BeginHorizontal();
  87. t.GetComponent<Image>().sprite = (Sprite)EditorGUILayout.ObjectField("Frame",t.GetComponent<Image>().sprite,typeof(Sprite),true,GUILayout.MinWidth(100));
  88. t.GetComponent<Image>().color = EditorGUILayout.ColorField("",t.GetComponent<Image>().color,GUILayout.Width(50));
  89. EditorGUILayout.EndHorizontal();
  90. EditorGUILayout.Space();
  91. Rect spriteRect = new Rect( frameSprite.rect.x/ frameSprite.texture.width,
  92. frameSprite.rect.y/ frameSprite.texture.height,
  93. frameSprite.rect.width/ frameSprite.texture.width,
  94. frameSprite.rect.height/ frameSprite.texture.height);
  95. GUILayout.Space(8);
  96. Rect lastRect = GUILayoutUtility.GetLastRect();
  97. lastRect.x = 20;
  98. lastRect.width = 100;
  99. lastRect.height = 100;
  100. GUILayout.Space(100);
  101. ETCGuiTools.DrawTextureRectPreview( lastRect,spriteRect,t.GetComponent<Image>().sprite.texture,Color.white);
  102. }ETCGuiTools.EndGroup();
  103. }
  104. #endregion
  105. #region Events
  106. t.showEventInspector = ETCGuiTools.BeginFoldOut( "Move Events",t.showEventInspector);
  107. if (t.showEventInspector){
  108. ETCGuiTools.BeginGroup();{
  109. serializedObject.Update();
  110. SerializedProperty movestartEvent = serializedObject.FindProperty("onMoveStart");
  111. EditorGUILayout.PropertyField(movestartEvent, true, null);
  112. serializedObject.ApplyModifiedProperties();
  113. serializedObject.Update();
  114. SerializedProperty moveEvent = serializedObject.FindProperty("onMove");
  115. EditorGUILayout.PropertyField(moveEvent, true, null);
  116. serializedObject.ApplyModifiedProperties();
  117. serializedObject.Update();
  118. SerializedProperty moveSpeedEvent = serializedObject.FindProperty("onMoveSpeed");
  119. EditorGUILayout.PropertyField(moveSpeedEvent, true, null);
  120. serializedObject.ApplyModifiedProperties();
  121. serializedObject.Update();
  122. SerializedProperty moveEndEvent = serializedObject.FindProperty("onMoveEnd");
  123. EditorGUILayout.PropertyField(moveEndEvent, true, null);
  124. serializedObject.ApplyModifiedProperties();
  125. }ETCGuiTools.EndGroup();
  126. }
  127. t.showTouchEventInspector = ETCGuiTools.BeginFoldOut( "Touch Events",t.showTouchEventInspector);
  128. if (t.showTouchEventInspector){
  129. ETCGuiTools.BeginGroup();{
  130. serializedObject.Update();
  131. SerializedProperty touchStartEvent = serializedObject.FindProperty("onTouchStart");
  132. EditorGUILayout.PropertyField(touchStartEvent, true, null);
  133. serializedObject.ApplyModifiedProperties();
  134. serializedObject.Update();
  135. SerializedProperty touchUpEvent = serializedObject.FindProperty("onTouchUp");
  136. EditorGUILayout.PropertyField(touchUpEvent, true, null);
  137. serializedObject.ApplyModifiedProperties();
  138. }ETCGuiTools.EndGroup();
  139. }
  140. t.showDownEventInspector = ETCGuiTools.BeginFoldOut( "Down Events",t.showDownEventInspector);
  141. if (t.showDownEventInspector){
  142. ETCGuiTools.BeginGroup();{
  143. serializedObject.Update();
  144. SerializedProperty downUpEvent = serializedObject.FindProperty("OnDownUp");
  145. EditorGUILayout.PropertyField(downUpEvent, true, null);
  146. serializedObject.ApplyModifiedProperties();
  147. serializedObject.Update();
  148. SerializedProperty downRightEvent = serializedObject.FindProperty("OnDownRight");
  149. EditorGUILayout.PropertyField(downRightEvent, true, null);
  150. serializedObject.ApplyModifiedProperties();
  151. serializedObject.Update();
  152. SerializedProperty downDownEvent = serializedObject.FindProperty("OnDownDown");
  153. EditorGUILayout.PropertyField(downDownEvent, true, null);
  154. serializedObject.ApplyModifiedProperties();
  155. serializedObject.Update();
  156. SerializedProperty downLeftEvent = serializedObject.FindProperty("OnDownLeft");
  157. EditorGUILayout.PropertyField(downLeftEvent, true, null);
  158. serializedObject.ApplyModifiedProperties();
  159. }ETCGuiTools.EndGroup();
  160. }
  161. t.showPressEventInspector = ETCGuiTools.BeginFoldOut( "Press Events",t.showPressEventInspector);
  162. if (t.showPressEventInspector){
  163. ETCGuiTools.BeginGroup();{
  164. serializedObject.Update();
  165. SerializedProperty pressUpEvent = serializedObject.FindProperty("OnPressUp");
  166. EditorGUILayout.PropertyField(pressUpEvent, true, null);
  167. serializedObject.ApplyModifiedProperties();
  168. serializedObject.Update();
  169. SerializedProperty pressRightEvent = serializedObject.FindProperty("OnPressRight");
  170. EditorGUILayout.PropertyField(pressRightEvent, true, null);
  171. serializedObject.ApplyModifiedProperties();
  172. serializedObject.Update();
  173. SerializedProperty pressDownEvent = serializedObject.FindProperty("OnPressDown");
  174. EditorGUILayout.PropertyField(pressDownEvent, true, null);
  175. serializedObject.ApplyModifiedProperties();
  176. serializedObject.Update();
  177. SerializedProperty pressLeftEvent = serializedObject.FindProperty("OnPressLeft");
  178. EditorGUILayout.PropertyField(pressLeftEvent, true, null);
  179. serializedObject.ApplyModifiedProperties();
  180. }ETCGuiTools.EndGroup();
  181. }
  182. #endregion
  183. t.SetAnchorPosition();
  184. if (GUI.changed){
  185. EditorUtility.SetDirty(t);
  186. #if UNITY_5_3
  187. EditorSceneManager.MarkSceneDirty( EditorSceneManager.GetActiveScene());
  188. #endif
  189. }
  190. }
  191. }