ETCAxisInspector.cs 6.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192
  1. using UnityEngine;
  2. using UnityEditor;
  3. using System.Collections;
  4. using System.Collections.Generic;
  5. public class ETCAxisInspector{
  6. public static void AxisInspector(ETCAxis axis, string label, ETCBase.ControlType type, bool turnMove = false, string[] unityAxes=null){
  7. EditorGUILayout.BeginHorizontal();
  8. //GUI.color = color;
  9. axis.enable = ETCGuiTools.Toggle(label + " axis : ",axis.enable,true,125,true);
  10. //GUI.color = Color.white;
  11. axis.name = EditorGUILayout.TextField("",axis.name,GUILayout.MinWidth(50));
  12. EditorGUILayout.EndHorizontal();
  13. if (axis.enable){
  14. EditorGUI.indentLevel++;
  15. #region General
  16. //EditorGUILayout.LabelField( "General",EditorStyles.boldLabel);
  17. axis.showGeneralInspector = EditorGUILayout.Foldout(axis.showGeneralInspector,"General setting");
  18. if (axis.showGeneralInspector){
  19. ETCGuiTools.BeginGroup(20);{
  20. EditorGUI.indentLevel--;
  21. axis.actionOn = (ETCAxis.ActionOn)EditorGUILayout.EnumPopup("React on",axis.actionOn );
  22. EditorGUILayout.Space();
  23. if (type == ETCBase.ControlType.Joystick ){
  24. axis.valueMethod = (ETCAxis.AxisValueMethod)EditorGUILayout.EnumPopup("Dead zone method",axis.valueMethod);
  25. switch (axis.valueMethod){
  26. case ETCAxis.AxisValueMethod.Classical:
  27. axis.deadValue = EditorGUILayout.Slider("Dead length",axis.deadValue,0f,1f);
  28. break;
  29. case ETCAxis.AxisValueMethod.Curve:
  30. if (axis.curveValue == null){
  31. axis.InitDeadCurve();
  32. }
  33. axis.curveValue = EditorGUILayout.CurveField("Sensitivity curve", axis.curveValue);
  34. break;
  35. }
  36. }
  37. EditorGUILayout.Space();
  38. axis.invertedAxis = ETCGuiTools.Toggle("Inverted axis",axis.invertedAxis,true);
  39. EditorGUILayout.Space();
  40. #region Button & DPAD Value over the time
  41. if (type == ETCBase.ControlType.Button || type == ETCBase.ControlType.DPad){
  42. axis.isValueOverTime = ETCGuiTools.Toggle("Value over the time",axis.isValueOverTime,true);
  43. if (axis.isValueOverTime){
  44. //EditorGUI.indentLevel--;
  45. ETCGuiTools.BeginGroup(5);{
  46. axis.overTimeStep = EditorGUILayout.FloatField("Step",axis.overTimeStep);
  47. axis.maxOverTimeValue = EditorGUILayout.FloatField("Max value",axis.maxOverTimeValue);
  48. }ETCGuiTools.EndGroup();
  49. //EditorGUI.indentLevel++;
  50. }
  51. }
  52. #endregion
  53. #region Joysick
  54. if (type == ETCBase.ControlType.Joystick ){
  55. axis.axisThreshold = EditorGUILayout.Slider("On/Off Threshold",axis.axisThreshold,0f,1f);
  56. }
  57. #endregion
  58. if (!turnMove){
  59. string labelspeed = "Speed";
  60. if (type== ETCBase.ControlType.TouchPad){
  61. labelspeed ="Sensitivity";
  62. }
  63. axis.speed = EditorGUILayout.FloatField(labelspeed,axis.speed);
  64. }
  65. EditorGUI.indentLevel++;
  66. }ETCGuiTools.EndGroup();
  67. }
  68. #endregion
  69. if (!turnMove){
  70. #region Direction Action
  71. axis.showDirectInspector = EditorGUILayout.Foldout(axis.showDirectInspector,"Direction ation (optional)");
  72. if (axis.showDirectInspector){
  73. ETCGuiTools.BeginGroup(20);{
  74. EditorGUI.indentLevel--;
  75. //EditorGUILayout.BeginHorizontal();
  76. axis.autoLinkTagPlayer = EditorGUILayout.ToggleLeft("Auto link on tag",axis.autoLinkTagPlayer, GUILayout.Width(200));
  77. if (axis.autoLinkTagPlayer){
  78. axis.autoTag = EditorGUILayout.TagField("",axis.autoTag);
  79. }
  80. //EditorGUILayout.EndHorizontal();
  81. if (!axis.autoLinkTagPlayer){
  82. axis.directTransform = (Transform)EditorGUILayout.ObjectField("Direct action to",axis.directTransform,typeof(Transform),true);
  83. }
  84. axis.directAction = (ETCAxis.DirectAction ) EditorGUILayout.EnumPopup( "Action",axis.directAction);
  85. if (axis.directAction != ETCAxis.DirectAction.Jump){
  86. axis.axisInfluenced = (ETCAxis.AxisInfluenced) EditorGUILayout.EnumPopup("Affected axis",axis.axisInfluenced);
  87. }
  88. else{
  89. EditorGUILayout.HelpBox("Required character controller", MessageType.Info);
  90. }
  91. if ((axis.directCharacterController || axis.autoLinkTagPlayer) && (axis.directAction == ETCAxis.DirectAction.Translate || axis.directAction == ETCAxis.DirectAction.TranslateLocal)){
  92. axis.isLockinJump = EditorGUILayout.Toggle("Lock in jump",axis.isLockinJump);
  93. if (axis.autoLinkTagPlayer)
  94. EditorGUILayout.HelpBox("Required character controller", MessageType.Info);
  95. }
  96. EditorGUI.indentLevel++;
  97. }ETCGuiTools.EndGroup();
  98. }
  99. #endregion
  100. #region smooth & inertia
  101. axis.showInertiaInspector = EditorGUILayout.Foldout(axis.showInertiaInspector,"Gravity-Inertia-smoothing...");
  102. if (axis.showInertiaInspector){
  103. ETCGuiTools.BeginGroup(20);{
  104. EditorGUI.indentLevel--;
  105. if ( axis.directCharacterController!=null || axis.autoLinkTagPlayer){
  106. axis.gravity = EditorGUILayout.FloatField("Gravity",axis.gravity);
  107. }
  108. // Inertia
  109. axis.isEnertia = ETCGuiTools.Toggle("Enable inertia", axis.isEnertia,true);
  110. if (axis.isEnertia){
  111. //EditorGUI.indentLevel--;
  112. ETCGuiTools.BeginGroup(5);{
  113. axis.inertia = EditorGUILayout.Slider("Inertia",axis.inertia,1f,500f);
  114. axis.inertiaThreshold = EditorGUILayout.FloatField("Threshold",axis.inertiaThreshold);
  115. }ETCGuiTools.EndGroup();
  116. //EditorGUI.indentLevel++;
  117. }
  118. // AutoStab & clamp rotation
  119. if (axis.directAction == ETCAxis.DirectAction.RotateLocal ){
  120. //AutoStab
  121. axis.isAutoStab = ETCGuiTools.Toggle("Automatic stabilization",axis.isAutoStab,true);
  122. if (axis.isAutoStab){
  123. //EditorGUI.indentLevel--;
  124. ETCGuiTools.BeginGroup(5);{
  125. axis.autoStabSpeed = EditorGUILayout.FloatField("Speed",axis.autoStabSpeed);
  126. axis.autoStabThreshold = EditorGUILayout.FloatField("Threshold ", axis.autoStabThreshold);
  127. }ETCGuiTools.EndGroup();
  128. //EditorGUI.indentLevel++;
  129. }
  130. // clamp rotation
  131. axis.isClampRotation = ETCGuiTools.Toggle("Clamp rotation",axis.isClampRotation,true);
  132. if (axis.isClampRotation){
  133. //EditorGUI.indentLevel--;
  134. ETCGuiTools.BeginGroup(5);{
  135. axis.maxAngle = EditorGUILayout.FloatField("Max angle",axis.maxAngle);
  136. axis.minAngle = EditorGUILayout.FloatField("Min angle",axis.minAngle);
  137. }ETCGuiTools.EndGroup();
  138. //EditorGUI.indentLevel++;
  139. }
  140. }
  141. EditorGUI.indentLevel++;
  142. }ETCGuiTools.EndGroup();
  143. }
  144. #endregion
  145. }
  146. #region Unity axes
  147. axis.showSimulatinInspector = EditorGUILayout.Foldout(axis.showSimulatinInspector,"Unity axes");
  148. if (axis.showSimulatinInspector){
  149. ETCGuiTools.BeginGroup(20);{
  150. EditorGUI.indentLevel--;
  151. int index = System.Array.IndexOf(unityAxes,axis.unityAxis );
  152. int tmpIndex = EditorGUILayout.Popup(index,unityAxes);
  153. if (tmpIndex != index){
  154. axis.unityAxis = unityAxes[tmpIndex];
  155. }
  156. EditorGUI.indentLevel++;
  157. }ETCGuiTools.EndGroup();
  158. }
  159. #endregion
  160. EditorGUI.indentLevel--;
  161. }
  162. }
  163. }