| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255 |
- using UnityEngine;
- using UnityEditor;
- using UnityEditorInternal;
- using System;
- using System.Collections.Generic;
- using Flux;
- namespace FluxEditor
- {
- [CustomEditor( typeof( Flux.FEvent ), true )]
- [CanEditMultipleObjects]
- public class FEventInspector : Editor
- {
- //目标挂载点
- 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" };
- private const string FRAMERANGE_START_FIELD_ID = "FrameRange.Start";
- private FEvent _evt;
- private bool _allEventsSameType = true;
- // protected SerializedProperty _script;
- protected SerializedProperty _triggerOnSkip;
- protected virtual void OnEnable()
- {
- if( target == null )
- {
- DestroyImmediate( this );
- return;
- }
- _evt = (Flux.FEvent)target;
- Type evtType = _evt.GetType();
- for( int i = 0; i != targets.Length; ++i )
- {
- FEvent evt = (FEvent)targets[i];
- if( evtType != evt.GetType() )
- {
- _allEventsSameType = false;
- break;
- }
- }
- // _script = serializedObject.FindProperty("m_Script");
- if( _allEventsSameType )
- {
- _triggerOnSkip = serializedObject.FindProperty( "_triggerOnSkip");
- }
- }
- public override void OnInspectorGUI()
- {
- // EditorGUILayout.PropertyField( _script );
- if( _allEventsSameType )
- {
- serializedObject.Update();
- EditorGUILayout.PropertyField( _triggerOnSkip );
- }
- else
- {
- bool triggerOnSkipMatch = true;
- for( int i = 0; i != targets.Length; ++i )
- {
- if( ((FEvent)targets[i]).TriggerOnSkip != _evt.TriggerOnSkip )
- {
- triggerOnSkipMatch = false;
- break;
- }
- }
-
- EditorGUI.BeginChangeCheck();
- bool triggerOnSkip = EditorGUILayout.Toggle( "Trigger On Skip", _evt.TriggerOnSkip, triggerOnSkipMatch ? EditorStyles.toggle : "ToggleMixed" );
- if( EditorGUI.EndChangeCheck() )
- {
- Undo.RecordObjects( targets, " Inspector" );
- for( int i = 0; i != targets.Length; ++i )
- {
- FEvent evt = (FEvent)targets[i];
- evt.TriggerOnSkip = triggerOnSkip;
- }
- }
- }
- // EditorGUILayout.IntField( "Instance ID", _evt.GetInstanceID() );
- float startFrame = _evt.Start;
- float endFrame = _evt.End;
- FrameRange validRange = _evt.Track != null ? _evt.Track.GetValidRange( _evt ) : new FrameRange(_evt.Start, _evt.End);
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Label( "开始帧:", EditorStyles.label );
- GUI.SetNextControlName( FRAMERANGE_START_FIELD_ID );
- startFrame = EditorGUILayout.IntField( _evt.Start );
- GUILayout.Label( "结束帧:", EditorStyles.label );
- endFrame = EditorGUILayout.IntField( _evt.End );
- EditorGUILayout.EndHorizontal();
-
- if( EditorGUI.EndChangeCheck() )
- {
- bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID;
-
- for( int i = 0; i != targets.Length; ++i )
- {
- FEvent evt = (FEvent)targets[i];
-
- FrameRange newFrameRange = evt.FrameRange;
- if( changedStart )
- {
- if( startFrame <= newFrameRange.End )
- newFrameRange.Start = (int)startFrame;
- }
- else if( endFrame >= newFrameRange.Start )
- newFrameRange.End = (int)endFrame;
-
- if( newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength() )
- {
- FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent( evt, newFrameRange );
- FEventEditor.FinishMovingEventEditors();
- // FUtility.Resize( evt, newFrameRange );
- }
- }
- }
- if( targets.Length == 1 )
- {
- EditorGUI.BeginChangeCheck();
- EditorGUILayout.BeginHorizontal();
- GUILayout.Space( EditorGUIUtility.labelWidth );
- float sliderStartFrame = startFrame;
- float sliderEndFrame = endFrame;
- EditorGUILayout.MinMaxSlider( ref sliderStartFrame, ref sliderEndFrame, validRange.Start, validRange.End );
- EditorGUILayout.EndHorizontal();
- if( EditorGUI.EndChangeCheck() )
- {
- FrameRange newFrameRange = new FrameRange( (int)sliderStartFrame, (int)sliderEndFrame );
- if( newFrameRange.Length < _evt.GetMinLength() )
- {
- if( sliderStartFrame != startFrame ) // changed start
- newFrameRange.Start = newFrameRange.End - _evt.GetMinLength();
- else
- newFrameRange.Length = _evt.GetMinLength();
- }
- // FUtility.Resize( _evt, newFrameRange );
- FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent( _evt, newFrameRange );
- FEventEditor.FinishMovingEventEditors();
- }
- }
-
- if( _allEventsSameType )
- {
- serializedObject.ApplyModifiedProperties();
- base.OnInspectorGUI();
- }
- }
- public static void OnInspectorGUIGeneric( List<FEvent> evts )
- {
- if( evts.Count == 0 )
- return;
- bool triggerOnSkipMatch = true;
- int startFrame = evts[0].Start;
- int endFrame = evts[0].End;
- bool startFrameMatch = true;
- bool endFrameMatch = true;
- for( int i = 1; i < evts.Count; ++i )
- {
- if( evts[i].TriggerOnSkip != evts[0].TriggerOnSkip )
- {
- triggerOnSkipMatch = false;
- }
- if( evts[i].Start != startFrame )
- {
- startFrameMatch = false;
- }
- if( evts[i].End != endFrame )
- {
- endFrameMatch = false;
- }
- }
- EditorGUI.BeginChangeCheck();
- bool triggerOnSkip = EditorGUILayout.Toggle( "Trigger On Skip", evts[0].TriggerOnSkip, triggerOnSkipMatch ? EditorStyles.toggle : "ToggleMixed" );
- if( EditorGUI.EndChangeCheck() )
- {
- Undo.RecordObjects( evts.ToArray(), "Inspector" );
- for( int i = 0; i < evts.Count; ++i )
- {
- evts[i].TriggerOnSkip = triggerOnSkip;
- EditorUtility.SetDirty( evts[i] );
- }
- }
-
- // FrameRange validRange = _evt.GetTrack().GetValidRange( _evt );
-
- EditorGUI.BeginChangeCheck();
- // foreach( GUIStyle style in GUI.skin.customStyles )
- // {
- //// if( style.name.ToLower().Contains( "" ) )
- // Debug.Log( style.name );
- // }
- EditorGUILayout.BeginHorizontal();
- EditorGUILayout.PrefixLabel( "Range" );
- GUILayout.Label( "S:", EditorStyles.label );
- GUI.SetNextControlName( FRAMERANGE_START_FIELD_ID );
- startFrame = EditorGUILayout.IntField( startFrame, startFrameMatch ? EditorStyles.numberField : "PR TextField" );
- GUILayout.Label( "E:", EditorStyles.label );
- endFrame = EditorGUILayout.IntField( endFrame, endFrameMatch ? EditorStyles.numberField : "PR TextField" );
- EditorGUILayout.EndHorizontal();
-
- if( EditorGUI.EndChangeCheck() )
- {
- // bool changedStart = GUI.GetNameOfFocusedControl() == FRAMERANGE_START_FIELD_ID;
-
- // for( int i = 0; i != targets.Length; ++i )
- // {
- // FEvent evt = (FEvent)targets[i];
- //
- // FrameRange newFrameRange = evt.FrameRange;
- // if( changedStart )
- // {
- // if( startFrame <= newFrameRange.End )
- // newFrameRange.Start = (int)startFrame;
- // }
- // else if( endFrame >= newFrameRange.Start )
- // newFrameRange.End = (int)endFrame;
- //
- // if( newFrameRange.Length >= evt.GetMinLength() && newFrameRange.Length <= evt.GetMaxLength() )
- // {
- // FSequenceEditorWindow.instance.GetSequenceEditor().MoveEvent( evt, newFrameRange );
- // // FUtility.Resize( evt, newFrameRange );
- // }
- // }
- }
- }
- }
- }
|