FEventInspector.cs 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255
  1. using UnityEngine;
  2. using UnityEditor;
  3. using UnityEditorInternal;
  4. using System;
  5. using System.Collections.Generic;
  6. using Flux;
  7. namespace FluxEditor
  8. {
  9. [CustomEditor( typeof( Flux.FEvent ), true )]
  10. [CanEditMultipleObjects]
  11. public class FEventInspector : Editor
  12. {
  13. //目标挂载点
  14. public static string[] linkPoints = new string[] { "Foot_Point", "Base_Point", "Hit_Point", "Head_Point", "Weapon_Point", "LHand_Point", "RHand_Point", "Add1_Point", "Add2_Point", "Add3_Point" };
  15. private const string FRAMERANGE_START_FIELD_ID = "FrameRange.Start";
  16. private FEvent _evt;
  17. private bool _allEventsSameType = true;
  18. // protected SerializedProperty _script;
  19. protected SerializedProperty _triggerOnSkip;
  20. protected virtual void OnEnable()
  21. {
  22. if( target == null )
  23. {
  24. DestroyImmediate( this );
  25. return;
  26. }
  27. _evt = (Flux.FEvent)target;
  28. Type evtType = _evt.GetType();
  29. for( int i = 0; i != targets.Length; ++i )
  30. {
  31. FEvent evt = (FEvent)targets[i];
  32. if( evtType != evt.GetType() )
  33. {
  34. _allEventsSameType = false;
  35. break;
  36. }
  37. }
  38. // _script = serializedObject.FindProperty("m_Script");
  39. if( _allEventsSameType )
  40. {
  41. _triggerOnSkip = serializedObject.FindProperty( "_triggerOnSkip");
  42. }
  43. }
  44. public override void OnInspectorGUI()
  45. {
  46. // EditorGUILayout.PropertyField( _script );
  47. if( _allEventsSameType )
  48. {
  49. serializedObject.Update();
  50. EditorGUILayout.PropertyField( _triggerOnSkip );
  51. }
  52. else
  53. {
  54. bool triggerOnSkipMatch = true;
  55. for( int i = 0; i != targets.Length; ++i )
  56. {
  57. if( ((FEvent)targets[i]).TriggerOnSkip != _evt.TriggerOnSkip )
  58. {
  59. triggerOnSkipMatch = false;
  60. break;
  61. }
  62. }
  63. EditorGUI.BeginChangeCheck();
  64. bool triggerOnSkip = EditorGUILayout.Toggle( "Trigger On Skip", _evt.TriggerOnSkip, triggerOnSkipMatch ? EditorStyles.toggle : "ToggleMixed" );
  65. if( EditorGUI.EndChangeCheck() )
  66. {
  67. Undo.RecordObjects( targets, " Inspector" );
  68. for( int i = 0; i != targets.Length; ++i )
  69. {
  70. FEvent evt = (FEvent)targets[i];
  71. evt.TriggerOnSkip = triggerOnSkip;
  72. }
  73. }
  74. }
  75. // EditorGUILayout.IntField( "Instance ID", _evt.GetInstanceID() );
  76. float startFrame = _evt.Start;
  77. float endFrame = _evt.End;
  78. FrameRange validRange = _evt.Track != null ? _evt.Track.GetValidRange( _evt ) : new FrameRange(_evt.Start, _evt.End);
  79. EditorGUI.BeginChangeCheck();
  80. EditorGUILayout.BeginHorizontal();
  81. GUILayout.Label( "开始帧:", EditorStyles.label );
  82. GUI.SetNextControlName( FRAMERANGE_START_FIELD_ID );
  83. startFrame = EditorGUILayout.IntField( _evt.Start );
  84. GUILayout.Label( "结束帧:", EditorStyles.label );
  85. endFrame = EditorGUILayout.IntField( _evt.End );
  86. EditorGUILayout.EndHorizontal();
  87. if( EditorGUI.EndChangeCheck() )
  88. {
  89. bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID;
  90. for( int i = 0; i != targets.Length; ++i )
  91. {
  92. FEvent evt = (FEvent)targets[i];
  93. FrameRange newFrameRange = evt.FrameRange;
  94. if( changedStart )
  95. {
  96. if( startFrame <= newFrameRange.End )
  97. newFrameRange.Start = (int)startFrame;
  98. }
  99. else if( endFrame >= newFrameRange.Start )
  100. newFrameRange.End = (int)endFrame;
  101. if( newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength() )
  102. {
  103. FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent( evt, newFrameRange );
  104. FEventEditor.FinishMovingEventEditors();
  105. // FUtility.Resize( evt, newFrameRange );
  106. }
  107. }
  108. }
  109. if( targets.Length == 1 )
  110. {
  111. EditorGUI.BeginChangeCheck();
  112. EditorGUILayout.BeginHorizontal();
  113. GUILayout.Space( EditorGUIUtility.labelWidth );
  114. float sliderStartFrame = startFrame;
  115. float sliderEndFrame = endFrame;
  116. EditorGUILayout.MinMaxSlider( ref sliderStartFrame, ref sliderEndFrame, validRange.Start, validRange.End );
  117. EditorGUILayout.EndHorizontal();
  118. if( EditorGUI.EndChangeCheck() )
  119. {
  120. FrameRange newFrameRange = new FrameRange( (int)sliderStartFrame, (int)sliderEndFrame );
  121. if( newFrameRange.Length < _evt.GetMinLength() )
  122. {
  123. if( sliderStartFrame != startFrame ) // changed start
  124. newFrameRange.Start = newFrameRange.End - _evt.GetMinLength();
  125. else
  126. newFrameRange.Length = _evt.GetMinLength();
  127. }
  128. // FUtility.Resize( _evt, newFrameRange );
  129. FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent( _evt, newFrameRange );
  130. FEventEditor.FinishMovingEventEditors();
  131. }
  132. }
  133. if( _allEventsSameType )
  134. {
  135. serializedObject.ApplyModifiedProperties();
  136. base.OnInspectorGUI();
  137. }
  138. }
  139. public static void OnInspectorGUIGeneric( List<FEvent> evts )
  140. {
  141. if( evts.Count == 0 )
  142. return;
  143. bool triggerOnSkipMatch = true;
  144. int startFrame = evts[0].Start;
  145. int endFrame = evts[0].End;
  146. bool startFrameMatch = true;
  147. bool endFrameMatch = true;
  148. for( int i = 1; i < evts.Count; ++i )
  149. {
  150. if( evts[i].TriggerOnSkip != evts[0].TriggerOnSkip )
  151. {
  152. triggerOnSkipMatch = false;
  153. }
  154. if( evts[i].Start != startFrame )
  155. {
  156. startFrameMatch = false;
  157. }
  158. if( evts[i].End != endFrame )
  159. {
  160. endFrameMatch = false;
  161. }
  162. }
  163. EditorGUI.BeginChangeCheck();
  164. bool triggerOnSkip = EditorGUILayout.Toggle( "Trigger On Skip", evts[0].TriggerOnSkip, triggerOnSkipMatch ? EditorStyles.toggle : "ToggleMixed" );
  165. if( EditorGUI.EndChangeCheck() )
  166. {
  167. Undo.RecordObjects( evts.ToArray(), "Inspector" );
  168. for( int i = 0; i < evts.Count; ++i )
  169. {
  170. evts[i].TriggerOnSkip = triggerOnSkip;
  171. EditorUtility.SetDirty( evts[i] );
  172. }
  173. }
  174. // FrameRange validRange = _evt.GetTrack().GetValidRange( _evt );
  175. EditorGUI.BeginChangeCheck();
  176. // foreach( GUIStyle style in GUI.skin.customStyles )
  177. // {
  178. //// if( style.name.ToLower().Contains( "" ) )
  179. // Debug.Log( style.name );
  180. // }
  181. EditorGUILayout.BeginHorizontal();
  182. EditorGUILayout.PrefixLabel( "Range" );
  183. GUILayout.Label( "S:", EditorStyles.label );
  184. GUI.SetNextControlName( FRAMERANGE_START_FIELD_ID );
  185. startFrame = EditorGUILayout.IntField( startFrame, startFrameMatch ? EditorStyles.numberField : "PR TextField" );
  186. GUILayout.Label( "E:", EditorStyles.label );
  187. endFrame = EditorGUILayout.IntField( endFrame, endFrameMatch ? EditorStyles.numberField : "PR TextField" );
  188. EditorGUILayout.EndHorizontal();
  189. if( EditorGUI.EndChangeCheck() )
  190. {
  191. // bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID;
  192. // for( int i = 0; i != targets.Length; ++i )
  193. // {
  194. // FEvent evt = (FEvent)targets[i];
  195. //
  196. // FrameRange newFrameRange = evt.FrameRange;
  197. // if( changedStart )
  198. // {
  199. // if( startFrame <= newFrameRange.End )
  200. // newFrameRange.Start = (int)startFrame;
  201. // }
  202. // else if( endFrame >= newFrameRange.Start )
  203. // newFrameRange.End = (int)endFrame;
  204. //
  205. // if( newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength() )
  206. // {
  207. // FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent( evt, newFrameRange );
  208. // // FUtility.Resize( evt, newFrameRange );
  209. // }
  210. // }
  211. }
  212. }
  213. }
  214. }