FSkillSingEventInspector.cs 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. using UnityEngine;
  2. using UnityEditor;
  3. using Flux;
  4. namespace FluxEditor
  5. {
  6. [CustomEditor(typeof(FSkillSingEvent))]
  7. public class FSkillSingEventInspector : FEventInspector
  8. {
  9. private FSkillSingEvent _skillSingEvent = null;
  10. private SerializedProperty _effectId = null;
  11. private SerializedProperty _startOffset = null;
  12. private SerializedProperty _effectPrefab = null;
  13. private SerializedProperty _effectLink = null;
  14. private string[] animClipNames = null;
  15. private int animIdx = -1;
  16. private int effectLinkIdx = -1;
  17. protected override void OnEnable()
  18. {
  19. base.OnEnable();
  20. _skillSingEvent = (FSkillSingEvent)target;
  21. _startOffset = serializedObject.FindProperty("_startOffset");
  22. _effectPrefab = serializedObject.FindProperty("_effectPrefab");
  23. _effectLink = serializedObject.FindProperty("_effectLink");
  24. _effectId = serializedObject.FindProperty("_effectId");
  25. if (_skillSingEvent.animator!=null)
  26. {
  27. RuntimeAnimatorController ctrl = _skillSingEvent.animator.runtimeAnimatorController;
  28. UnityEditor.Animations.AnimatorController ac = ctrl as UnityEditor.Animations.AnimatorController;
  29. animClipNames = new string[ac.layers[0].stateMachine.states.Length];
  30. for (int i = 0; i < animClipNames.Length; i++)
  31. {
  32. animClipNames[i] = ac.layers[0].stateMachine.states[i].state.name;
  33. }
  34. if(animClipNames!=null)
  35. {
  36. for (int i = 0; i < animClipNames.Length; i++)
  37. {
  38. if (_skillSingEvent._animName == animClipNames[i])
  39. {
  40. animIdx = i;
  41. break;
  42. }
  43. }
  44. }
  45. }
  46. for (int idx = 0; idx < linkPoints.Length; idx++)
  47. {
  48. if (linkPoints[idx] == _effectLink.stringValue)
  49. {
  50. effectLinkIdx = idx;
  51. break;
  52. }
  53. }
  54. }
  55. public override void OnInspectorGUI()
  56. {
  57. AudioClip currentClip = _skillSingEvent.AudioClip;
  58. base.OnInspectorGUI();
  59. serializedObject.Update();
  60. _startOffset.intValue = Mathf.Clamp(_startOffset.intValue, 0, int.MaxValue);
  61. EditorGUI.BeginChangeCheck();
  62. EditorGUILayout.IntSlider(_startOffset, 0, int.MaxValue);
  63. if (EditorGUI.EndChangeCheck())
  64. {
  65. if (FSequenceEditorWindow.instance != null)
  66. FSequenceEditorWindow.instance.Repaint();
  67. }
  68. EditorGUILayout.BeginHorizontal();
  69. GUILayout.Label("吟唱特效ID:", EditorStyles.label, GUILayout.Width(140));
  70. _effectId.intValue = EditorGUILayout.IntField(_effectId.intValue, GUILayout.Width(300));
  71. EditorGUILayout.EndHorizontal();
  72. EditorGUILayout.BeginHorizontal();
  73. GUILayout.Label("吟唱特效预设:", EditorStyles.label, GUILayout.Width(140));
  74. _effectPrefab.objectReferenceValue = EditorGUILayout.ObjectField(_effectPrefab.objectReferenceValue, typeof(GameObject), false, GUILayout.Width(300));
  75. EditorGUILayout.EndHorizontal();
  76. EditorGUILayout.BeginHorizontal();
  77. GUILayout.Label("挂载点:", EditorStyles.label, GUILayout.Width(140));
  78. effectLinkIdx = EditorGUILayout.Popup(effectLinkIdx, linkPoints, GUILayout.Width(300));
  79. if (effectLinkIdx >= 0)
  80. _effectLink.stringValue = linkPoints[effectLinkIdx];
  81. EditorGUILayout.EndHorizontal();
  82. serializedObject.ApplyModifiedProperties();
  83. if(animClipNames!=null)
  84. {
  85. EditorGUILayout.BeginHorizontal();
  86. GUILayout.Label("吟唱动作", EditorStyles.label, GUILayout.Width(140));
  87. animIdx = EditorGUILayout.Popup(animIdx, animClipNames);
  88. if (animIdx >= 0)
  89. {
  90. _skillSingEvent._animName = animClipNames[animIdx];
  91. }
  92. EditorGUILayout.EndHorizontal();
  93. }
  94. }
  95. }
  96. }