ETCTouchPadInspector.cs 8.9 KB

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