MegaMorphLinkEditor.cs 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. 
  2. using UnityEngine;
  3. using UnityEditor;
  4. [CanEditMultipleObjects, CustomEditor(typeof(MegaMorphLink))]
  5. public class MegaMorphLinkEditor : Editor
  6. {
  7. int GetIndex(string name, string[] channels)
  8. {
  9. int index = -1;
  10. for ( int i = 0; i < channels.Length; i++ )
  11. {
  12. if ( channels[i] == name )
  13. {
  14. index = i;
  15. break;
  16. }
  17. }
  18. return index;
  19. }
  20. // TODO: Need none in the popup to clear a channel
  21. public override void OnInspectorGUI()
  22. {
  23. MegaMorphLink anim = (MegaMorphLink)target;
  24. anim.morph = (MegaMorph)EditorGUILayout.ObjectField("Morph", anim.morph, typeof(MegaMorph), true);
  25. MegaMorph morph = anim.morph; //gameObject.GetComponent<MegaMorph>();
  26. if ( morph != null )
  27. {
  28. if ( GUILayout.Button("Add Link") )
  29. {
  30. MegaMorphLinkDesc desc = new MegaMorphLinkDesc();
  31. anim.links.Add(desc);
  32. }
  33. string[] channels = morph.GetChannelNames();
  34. for ( int i = 0; i < anim.links.Count; i++ )
  35. {
  36. MegaMorphLinkDesc md = anim.links[i];
  37. md.name = EditorGUILayout.TextField("Name", md.name);
  38. //md.active = EditorGUILayout.Toggle("Active", md.active);
  39. //if ( md.active )
  40. md.active = EditorGUILayout.BeginToggleGroup("Active", md.active);
  41. {
  42. md.channel = EditorGUILayout.Popup("Channel", md.channel, channels);
  43. md.target = (Transform)EditorGUILayout.ObjectField("Target", md.target, typeof(Transform), true);
  44. md.src = (MegaLinkSrc)EditorGUILayout.EnumPopup("Source", md.src);
  45. if ( md.src != MegaLinkSrc.Angle && md.src != MegaLinkSrc.DotRotation )
  46. md.axis = (MegaAxis)EditorGUILayout.EnumPopup("Axis", md.axis);
  47. EditorGUILayout.LabelField("Val", md.GetVal().ToString());
  48. md.min = EditorGUILayout.FloatField("Min", md.min);
  49. md.max = EditorGUILayout.FloatField("Max", md.max);
  50. md.low = EditorGUILayout.FloatField("Low", md.low);
  51. md.high = EditorGUILayout.FloatField("High", md.high);
  52. md.useCurve = EditorGUILayout.BeginToggleGroup("Use Curve", md.useCurve);
  53. md.curve = EditorGUILayout.CurveField("Curve", md.curve);
  54. EditorGUILayout.EndToggleGroup();
  55. if ( md.src == MegaLinkSrc.Angle || md.src == MegaLinkSrc.DotRotation )
  56. {
  57. EditorGUILayout.BeginHorizontal();
  58. if ( GUILayout.Button("Set Start Rot") )
  59. {
  60. if ( md.target )
  61. md.rot = md.target.localRotation;
  62. }
  63. //if ( GUILayout.Button("Set End Rot") )
  64. //{
  65. //if ( md.target )
  66. //{
  67. //Quaternion rot = md.target.localRotation;
  68. // md.max = md.GetVal();
  69. //}
  70. //}
  71. EditorGUILayout.EndHorizontal();
  72. }
  73. EditorGUILayout.BeginHorizontal();
  74. if ( GUILayout.Button("Set Min Val") )
  75. {
  76. if ( md.target )
  77. md.min = md.GetVal();
  78. //md.rot = md.target.localRotation;
  79. }
  80. if ( GUILayout.Button("Set Max Val") )
  81. {
  82. if ( md.target )
  83. {
  84. //Quaternion rot = md.target.localRotation;
  85. md.max = md.GetVal();
  86. }
  87. }
  88. EditorGUILayout.EndHorizontal();
  89. }
  90. EditorGUILayout.EndToggleGroup();
  91. if ( GUILayout.Button("Delete") )
  92. {
  93. anim.links.RemoveAt(i);
  94. i--;
  95. }
  96. }
  97. if ( GUI.changed )
  98. {
  99. EditorUtility.SetDirty(target);
  100. }
  101. }
  102. }
  103. }