FSequenceEditor.cs 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022
  1. using UnityEngine;
  2. using UnityEngine.SceneManagement;
  3. using UnityEngine.Events;
  4. using UnityEditor;
  5. using UnityEditor.SceneManagement;
  6. using System.Collections.Generic;
  7. using Flux;
  8. namespace FluxEditor
  9. {
  10. [System.Serializable]
  11. public class FSequenceEditor : FEditorList<FContainerEditor>
  12. {
  13. private const double NOTIFY_DIRTY_TRACKS_DELTA = 1;
  14. private const int VERTICAL_SCROLLER_WIDTH = 16;
  15. public const int RIGHT_BORDER = 20;
  16. private const int FRAME_RANGE_SCROLLER_HEIGHT = 16;
  17. private const int MINIMUM_HEADER_WIDTH = 150;
  18. private const int SCROLL_WHEEL_SPEED = 5;
  19. // keep track if we came out of play mode
  20. private bool _wasUnityInPlaymode = false;
  21. [SerializeField]
  22. private Editor _renderingOnEditor;
  23. [SerializeField]
  24. private EditorWindow _renderingOnEditorWindow;
  25. private int _headerResizerGuiId = 0;
  26. // current view range of the sequence
  27. [SerializeField]
  28. private FrameRange _viewRange;
  29. public FrameRange ViewRange { get { return _viewRange; } }
  30. // cached sequence.Length, to know when it got chanced
  31. // and adjust the _viewRange accordingly
  32. private int _sequenceLength = int.MaxValue;
  33. // how many pixels do we have to render per frame
  34. private float _pixelsPerFrame;
  35. public float PixelsPerFrame { get { return _pixelsPerFrame; } }
  36. // editor cache
  37. [SerializeField]
  38. private FEditorCache _editorCache = null;
  39. // sequence being edited
  40. public FSequence Sequence { get { return (FSequence)Obj; } }
  41. [SerializeField]
  42. private FTrackEditorInspector _trackSelection = new FTrackEditorInspector();
  43. public FTrackEditorInspector TrackSelection { get { return _trackSelection; } }
  44. [SerializeField]
  45. private FEventEditorInspector _eventSelection = new FEventEditorInspector();
  46. public FEventEditorInspector EventSelection { get { return _eventSelection; } }
  47. [SerializeField]
  48. private FTimelineEditorInspector _timelineSelection = new FTimelineEditorInspector();
  49. public FTimelineEditorInspector TimelineSelection { get { return _timelineSelection; } }
  50. [SerializeField]
  51. private FContainerEditorInspector _containerSelection = new FContainerEditorInspector();
  52. public FContainerEditorInspector ContainerSelection { get { return _containerSelection; } }
  53. public override void Init( FObject obj, FEditor owner )
  54. {
  55. base.Init( obj, owner );
  56. Editors.Clear();
  57. if( Sequence != null )
  58. {
  59. for( int i = 0; i != Sequence.Containers.Count; ++i )
  60. {
  61. FContainerEditor editor = _editorCache.GetEditor<FContainerEditor>( Sequence.Containers[i] );
  62. editor.Init( Sequence.Containers[i], this );
  63. Editors.Add( editor );
  64. }
  65. }
  66. _contentOffset.x = 0; // no left margin, and Y offset needs to be calculated based on scroll
  67. }
  68. public override FSequenceEditor SequenceEditor { get { return this; } }
  69. #region Cached rects to speed up render and not use GUILayout
  70. // rect for the scroll bar on the left
  71. [SerializeField]
  72. private Rect _verticalScrollerRect;
  73. // rect where the timelines will be displayed
  74. [SerializeField]
  75. private Rect _viewRect;
  76. // rect for the view range bar
  77. [SerializeField]
  78. private Rect _viewRangeRect;
  79. // rect for the time scrubber
  80. [SerializeField]
  81. private Rect _timeScrubberRect;
  82. // origin-starting rect for the sequence timelines, to be used
  83. // inside the GUI.BeginGroup
  84. [SerializeField]
  85. private Rect _sequenceRect;
  86. [SerializeField]
  87. private Rect _timelineRect;
  88. // rect of the area where the timeline headers are
  89. [SerializeField]
  90. private Rect _timelineHeaderResizerRect;
  91. // width of the timeline header
  92. [SerializeField]
  93. private float _headerWidth;
  94. public float HeaderWidth { get { return _headerWidth; } }
  95. // timeline scroll bar pos, only handles Y
  96. [SerializeField]
  97. private Vector2 _scrollPos;
  98. public FEditor EditorDragged { get; set; }
  99. public Rect EditorDraggedRect { get; set; }
  100. #endregion
  101. [SerializeField]
  102. private UnityEvent _onUpdateEvent = new UnityEvent();
  103. public UnityEvent OnUpdateEvent { get { return _onUpdateEvent; } }
  104. private bool _isEditorCompiling = false;
  105. protected override void OnEnable()
  106. {
  107. base.OnEnable();
  108. EditorApplication.hierarchyWindowChanged += Refresh;
  109. AnimationUtility.onCurveWasModified += OnAnimationCurveChanged;
  110. Undo.undoRedoPerformed += OnUndo;
  111. Undo.postprocessModifications += PostProcessModifications;
  112. EditorApplication.playmodeStateChanged += OnPlaymodeChanged;
  113. EditorSceneManager.sceneUnloaded += OnSceneUnloaded;
  114. }
  115. private double _timeNotifyDirtyTracks = 0;
  116. void OnAnimationCurveChanged( AnimationClip clip, EditorCurveBinding binding, AnimationUtility.CurveModifiedType curveModifiedType )
  117. {
  118. // Debug.LogWarning( "OnAnimationCurveChanged" );
  119. SetAllDirty();
  120. }
  121. protected override void OnDestroy()
  122. {
  123. base.OnDestroy();
  124. EventSelection.Clear();
  125. TrackSelection.Clear();
  126. TimelineSelection.Clear();
  127. ContainerSelection.Clear();
  128. if( _editorCache != null )
  129. {
  130. _editorCache.Clear();
  131. DestroyImmediate( _editorCache );
  132. }
  133. EditorApplication.hierarchyWindowChanged -= Refresh;
  134. AnimationUtility.onCurveWasModified -= OnAnimationCurveChanged;
  135. Undo.undoRedoPerformed -= OnUndo;
  136. Undo.postprocessModifications -= PostProcessModifications;
  137. EditorApplication.playmodeStateChanged -= OnPlaymodeChanged;
  138. EditorSceneManager.sceneUnloaded -= OnSceneUnloaded;
  139. }
  140. private void OnSceneUnloaded(Scene scene)
  141. {
  142. if( Sequence != null && Sequence.gameObject.scene == scene )
  143. {
  144. OpenSequence(null);
  145. }
  146. }
  147. protected override bool CanPaste(FObject obj)
  148. {
  149. return obj is FContainer;
  150. }
  151. protected override void Paste(object obj)
  152. {
  153. Undo.RecordObject( Sequence, string.Empty );
  154. FContainer container = Instantiate<FContainer>((FContainer)obj);
  155. container.hideFlags = Sequence.Content.hideFlags;
  156. Sequence.Add( container );
  157. Undo.RegisterCreatedObjectUndo( container.gameObject, "Paste Container " + ((FContainer)obj).name );
  158. }
  159. public void Init( Editor editor )
  160. {
  161. Init( editor, null );
  162. }
  163. public void Init( EditorWindow editorWindow )
  164. {
  165. Init( null, editorWindow );
  166. }
  167. private void Init( Editor editor, EditorWindow editorWindow )
  168. {
  169. _renderingOnEditor = editor;
  170. _renderingOnEditorWindow = editorWindow;
  171. _editorCache = CreateInstance<FEditorCache>();
  172. }
  173. public void Repaint()
  174. {
  175. if( _renderingOnEditor )
  176. _renderingOnEditor.Repaint();
  177. else if( _renderingOnEditorWindow )
  178. _renderingOnEditorWindow.Repaint();
  179. }
  180. public void Refresh()
  181. {
  182. OpenSequence( Sequence );
  183. }
  184. public T GetEditor<T>( FObject obj ) where T : FEditor
  185. {
  186. return _editorCache.GetEditor<T>( obj );
  187. }
  188. public void OnUndo()
  189. {
  190. _editorCache.Refresh();
  191. if( FInspectorWindow._instance )
  192. {
  193. EventSelection.Refresh();
  194. TrackSelection.Refresh();
  195. TimelineSelection.Refresh();
  196. ContainerSelection.Refresh();
  197. FInspectorWindow._instance.Repaint();
  198. }
  199. OpenSequence( Sequence );
  200. SetAllDirty();
  201. if( Sequence && !Sequence.IsStopped )
  202. {
  203. int currentFrame = Sequence.CurrentFrame;
  204. Stop();
  205. SetCurrentFrame( currentFrame );
  206. }
  207. }
  208. UndoPropertyModification[] PostProcessModifications( UndoPropertyModification[] modifications )
  209. {
  210. foreach( UndoPropertyModification modification in modifications )
  211. {
  212. FTrack track = null;
  213. PropertyModification propertyModification = modification.currentValue;
  214. if( propertyModification.target is FEvent )
  215. if( propertyModification.target is FEvent )
  216. {
  217. track = ((FEvent)propertyModification.target).Track;
  218. }
  219. else if( propertyModification.target is FTrack )
  220. {
  221. track = (FTrack)propertyModification.target;
  222. }
  223. if( track != null && track.Sequence == Sequence )
  224. {
  225. FTrackEditor trackEditor = GetEditor<FTrackEditor>( track );
  226. SetDirty( trackEditor );
  227. }
  228. }
  229. return modifications;
  230. }
  231. public void OnPlaymodeChanged()
  232. {
  233. if( _wasUnityInPlaymode )
  234. {
  235. // make sure it is like it is opening it for the first time
  236. _wasUnityInPlaymode = false;
  237. FSequence sequence = Sequence;
  238. OpenSequence( null );
  239. OpenSequence( sequence );
  240. }
  241. }
  242. public void OnPlaymodeWillChange()
  243. {
  244. Stop();
  245. foreach( FContainerEditor container in Editors )
  246. {
  247. List<FTimelineEditor> timelineEditors = container.Editors;
  248. for( int i = 0; i != timelineEditors.Count; ++i )
  249. {
  250. for( int j = 0; j != timelineEditors[i].Editors.Count; ++j )
  251. {
  252. if( timelineEditors[i].Editors[j].Track.HasCache )
  253. {
  254. timelineEditors[i].Editors[j].Track.ClearCache();
  255. }
  256. }
  257. }
  258. }
  259. FAnimationTrack.DeleteAnimationPreviews( Sequence );
  260. _editorCache.Refresh();
  261. EventSelection.Refresh();
  262. TrackSelection.Refresh();
  263. TimelineSelection.Refresh();
  264. ContainerSelection.Refresh();
  265. Repaint();
  266. }
  267. public void SetViewRange( FrameRange viewRange )
  268. {
  269. FrameRange sequenceRange = new FrameRange(0, Sequence.Length);
  270. viewRange.Start = sequenceRange.Cull( viewRange.Start );
  271. viewRange.End = sequenceRange.Cull( viewRange.End );
  272. if( viewRange.End <= viewRange.Start )
  273. {
  274. if( viewRange.Start == Sequence.Length )
  275. {
  276. viewRange.End = Sequence.Length;
  277. viewRange.Start = viewRange.End-1;
  278. }
  279. else
  280. {
  281. viewRange.End = viewRange.Start+1;
  282. }
  283. }
  284. _viewRange = viewRange;
  285. }
  286. /**
  287. * @brief Returns the mouse x normalized to the start of the timeline, so 0 = viewRange.Start
  288. * @param frame Frame.
  289. */
  290. public float GetXForFrame( int frame )
  291. {
  292. return ((frame - _viewRange.Start) * _pixelsPerFrame);
  293. }
  294. /**
  295. * @brief Get frame for x, normalized to the start of timeline, so 0 = viewRange.Start
  296. * @param x Position.
  297. */
  298. public int GetFrameForX( float x )
  299. {
  300. return _viewRange.Start + Mathf.RoundToInt( x / _pixelsPerFrame );
  301. }
  302. protected override string HeaderText { get { return null; } }
  303. protected override Transform ContentTransform { get { return Sequence.Content; } }
  304. public override void Render( Rect rect, float headerWidth )
  305. {
  306. RenderList( rect, headerWidth );
  307. }
  308. public void RebuildLayout( Rect rect )
  309. {
  310. Rect = rect;
  311. _viewRect = rect;
  312. _viewRect.xMin += VERTICAL_SCROLLER_WIDTH;
  313. _viewRect.yMax -= (FRAME_RANGE_SCROLLER_HEIGHT + FGUI.TIMELINE_SCRUBBER_HEIGHT);
  314. _sequenceRect = _viewRect;
  315. _sequenceRect.xMin -= VERTICAL_SCROLLER_WIDTH;
  316. _sequenceRect.xMax -= VERTICAL_SCROLLER_WIDTH + RIGHT_BORDER;
  317. _timelineRect = _sequenceRect;
  318. _timelineRect.xMin += _headerWidth;
  319. _headerWidth = Mathf.Max(MINIMUM_HEADER_WIDTH, _headerWidth);
  320. _timeScrubberRect = _viewRect;
  321. _timeScrubberRect.xMin += _headerWidth;
  322. _timeScrubberRect.xMax -= RIGHT_BORDER;
  323. _timeScrubberRect.yMax += FGUI.TIMELINE_SCRUBBER_HEIGHT;
  324. _timelineHeaderResizerRect = _timeScrubberRect;
  325. _timelineHeaderResizerRect.xMin = 0;
  326. _timelineHeaderResizerRect.xMax = _timeScrubberRect.xMin;
  327. _timelineHeaderResizerRect.yMin = _timelineHeaderResizerRect.yMax-FGUI.TIMELINE_SCRUBBER_HEIGHT;
  328. _viewRangeRect = rect;
  329. _viewRangeRect.yMin = _viewRangeRect.yMax - FRAME_RANGE_SCROLLER_HEIGHT;
  330. _verticalScrollerRect = rect;
  331. _verticalScrollerRect.width = VERTICAL_SCROLLER_WIDTH;
  332. _verticalScrollerRect.yMax -= (FRAME_RANGE_SCROLLER_HEIGHT + FGUI.TIMELINE_SCRUBBER_HEIGHT);
  333. }
  334. public void OpenSequence( FSequence sequence )
  335. {
  336. #if FLUX_DEBUG
  337. Debug.Log( "Opening sequence: " + sequence + " isPlaying " + EditorApplication.isPlaying + " isPlayingOrEtc " + EditorApplication.isPlayingOrWillChangePlaymode );
  338. #endif
  339. if( sequence == null )
  340. {
  341. if( !object.Equals( sequence, null ) )
  342. sequence = (FSequence)EditorUtility.InstanceIDToObject( sequence.GetInstanceID() );
  343. }
  344. bool sequenceChanged = Sequence != sequence && (object.Equals(Sequence, null) || object.Equals(sequence, null) || Sequence.GetInstanceID() != sequence.GetInstanceID());
  345. if( sequenceChanged || sequence == null )
  346. {
  347. if( Sequence != null )
  348. {
  349. Stop();
  350. Sequence.DestroyTrackCaches();
  351. }
  352. OnUpdateEvent.RemoveAllListeners();
  353. _editorCache.Clear();
  354. EventSelection.Clear();
  355. TrackSelection.Clear();
  356. TimelineSelection.Clear();
  357. ContainerSelection.Clear();
  358. Editors.Clear();
  359. if( sequence != null )
  360. sequence.Speed = sequence.DefaultSpeed;
  361. }
  362. else if( !EditorApplication.isPlaying )
  363. {
  364. _editorCache.Refresh();
  365. EventSelection.Refresh();
  366. TrackSelection.Refresh();
  367. TimelineSelection.Refresh();
  368. ContainerSelection.Refresh();
  369. }
  370. if( sequence != null )
  371. {
  372. if( !EditorApplication.isPlaying && sequence.Version != Flux.FUtility.FLUX_VERSION )
  373. {
  374. FluxEditor.FUtility.Upgrade( sequence );
  375. }
  376. if( _viewRange.Length == 0 )
  377. _viewRange = new FrameRange(0, sequence.Length);
  378. if( !EditorApplication.isPlaying )
  379. sequence.Rebuild();
  380. if( _viewRange.Length == 0 )
  381. {
  382. _viewRange = new FrameRange(0, sequence.Length);
  383. }
  384. }
  385. else
  386. {
  387. _dirtyTracks.Clear();
  388. }
  389. Init( sequence, null );
  390. if( !Application.isPlaying && sequenceChanged )
  391. {
  392. sequence.Init();
  393. sequence.ResetDefaultVal();
  394. }
  395. Repaint();
  396. if( FInspectorWindow._instance != null )
  397. FInspectorWindow._instance.Repaint();
  398. }
  399. public void CreateContainer( FColorSetting containerInfo )
  400. {
  401. Undo.RecordObject( Sequence, null );
  402. FContainer container = FContainer.Create( containerInfo._color );
  403. container.gameObject.name = GetUniqueContainerName( containerInfo._str );
  404. Sequence.Add( container );
  405. Undo.RegisterCreatedObjectUndo( container.gameObject, "create Container" );
  406. }
  407. private bool HasContainerWithName( string name )
  408. {
  409. foreach( FContainer container in Sequence.Containers )
  410. {
  411. if( container.gameObject.name == name )
  412. return true;
  413. }
  414. return false;
  415. }
  416. public string GetUniqueContainerName( string defaultName )
  417. {
  418. if( !HasContainerWithName( defaultName ) )
  419. return defaultName;
  420. string nameFormat = defaultName + " {0}";
  421. int id = 1;
  422. while( HasContainerWithName( string.Format( nameFormat, id ) ) )
  423. {
  424. ++id;
  425. }
  426. return string.Format( nameFormat, id );
  427. }
  428. public void DestroyEditor( FEditor editor )
  429. {
  430. if( editor is FEventEditor )
  431. {
  432. List<FEventEditor> eventEditors = new List<FEventEditor>();
  433. eventEditors.Add( (FEventEditor)editor );
  434. DestroyEvents( eventEditors );
  435. }
  436. else if( editor is FTrackEditor )
  437. {
  438. DestroyEditor( (FTrackEditor)editor );
  439. }
  440. else if( editor is FTimelineEditor )
  441. {
  442. DestroyEditor( (FTimelineEditor)editor );
  443. }
  444. else if( editor is FContainerEditor )
  445. {
  446. DestroyEditor( (FContainerEditor)editor );
  447. }
  448. }
  449. public void DestroyEditor( FContainerEditor editor )
  450. {
  451. FContainer container = editor.Container;
  452. int undoGroup = Undo.GetCurrentGroup();
  453. Undo.SetCurrentGroupName( "delete Container" );
  454. Undo.RecordObjects( new Object[]{Sequence, container, editor, _editorCache, this}, "delete Container" );
  455. editor.OnDelete();
  456. editor.SequenceEditor.Editors.Remove( editor );
  457. _editorCache.Remove( editor );
  458. ContainerSelection.Remove( editor );
  459. Undo.SetTransformParent( container.transform, null, null );
  460. Sequence.Remove( container );
  461. while( editor.Editors.Count > 0 )
  462. {
  463. DestroyEditor( editor.Editors[editor.Editors.Count-1] );
  464. }
  465. Undo.DestroyObjectImmediate( editor );
  466. Undo.DestroyObjectImmediate( container.gameObject );
  467. Undo.CollapseUndoOperations( undoGroup );
  468. }
  469. public void DestroyEditor( FTrackEditor editor )
  470. {
  471. FTrack track = editor.Track;
  472. int undoGroup = Undo.GetCurrentGroup();
  473. Undo.SetCurrentGroupName( "delete Track" );
  474. Undo.RecordObjects( new UnityEngine.Object[]{track.Timeline, editor.TimelineEditor, track, editor, _editorCache, this}, "delete Track" );
  475. editor.OnDelete();
  476. editor.TimelineEditor.Editors.Remove( editor );
  477. _editorCache.Remove( editor );
  478. TrackSelection.Remove( editor );
  479. Undo.SetTransformParent( track.transform, null, null );
  480. track.Timeline.Remove( track );
  481. DestroyEvents( editor._eventEditors );
  482. Undo.DestroyObjectImmediate( editor );
  483. Undo.DestroyObjectImmediate( track.gameObject );
  484. Undo.CollapseUndoOperations( undoGroup );
  485. }
  486. public void DestroyEditor( FTimelineEditor editor )
  487. {
  488. FTimeline timeline = editor.Timeline;
  489. int undoGroup = Undo.GetCurrentGroup();
  490. Undo.SetCurrentGroupName( "delete Timeline" );
  491. Undo.RecordObjects( new UnityEngine.Object[]{timeline.Container, editor.ContainerEditor, timeline, editor, _editorCache, this}, "delete Timeline" );
  492. editor.OnDelete();
  493. while( editor.Editors.Count > 0 )
  494. {
  495. DestroyEditor( editor.Editors[editor.Editors.Count-1] );
  496. }
  497. editor.ContainerEditor.Editors.Remove( editor );
  498. _editorCache.Remove( editor );
  499. TimelineSelection.Remove( editor );
  500. Undo.SetTransformParent( timeline.transform, null, null );
  501. timeline.Container.Remove( timeline );
  502. Undo.DestroyObjectImmediate( editor );
  503. Undo.DestroyObjectImmediate( timeline.gameObject );
  504. Undo.CollapseUndoOperations( undoGroup );
  505. }
  506. protected override void Delete()
  507. {
  508. // cannot be deleted this way since it has no header to right click on
  509. }
  510. public void AddEvent( int t )
  511. {
  512. List<ISelectableElement> newEvents = new List<ISelectableElement>();
  513. int undoGroup = Undo.GetCurrentGroup();
  514. foreach( FTrackEditor trackEditor in TrackSelection.Editors )
  515. {
  516. FEvent evt = trackEditor.TryAddEvent( t );
  517. if( evt )
  518. {
  519. FEventEditor evtEditor = GetEditor<FEventEditor>( evt );
  520. evtEditor.Init( evt, trackEditor );
  521. newEvents.Add( evtEditor );
  522. }
  523. }
  524. if( newEvents.Count > 0 )
  525. {
  526. int currentFrame = Sequence.CurrentFrame;
  527. DeselectAll();
  528. Select( newEvents );
  529. if( currentFrame >= 0 )
  530. {
  531. foreach( FTrackEditor trackEditor in TrackSelection.Editors )
  532. {
  533. trackEditor.Track.Init();
  534. }
  535. }
  536. }
  537. else
  538. EditorApplication.Beep();
  539. Undo.CollapseUndoOperations( undoGroup );
  540. }
  541. public void DestroyEvents( List<FEventEditor> events )
  542. {
  543. if( events.Count == 0 )
  544. return;
  545. List<FTrackEditor> trackEditors = new List<FTrackEditor>();
  546. List<Object> objs = new List<Object>();
  547. for( int i = 0; i != events.Count; ++i )
  548. {
  549. objs.Add( events[i] );
  550. objs.Add( events[i].Evt );
  551. if( !trackEditors.Contains( events[i].TrackEditor ) )
  552. trackEditors.Add( events[i].TrackEditor );
  553. }
  554. for( int i = 0; i != trackEditors.Count; ++i )
  555. {
  556. objs.Add( trackEditors[i] );
  557. objs.Add( trackEditors[i].Track );
  558. }
  559. // objs.Add( _editorCache );
  560. objs.Add( this ); // add itself, to save selection lists
  561. Undo.SetCurrentGroupName( "delete Events" );
  562. Undo.RecordObjects( objs.ToArray(), "delete Events");
  563. for( int j = events.Count-1; j > -1; --j )
  564. {
  565. FEventEditor evtEditor = events[j];
  566. evtEditor.OnDelete();
  567. _editorCache.Remove( evtEditor );
  568. EventSelection.Remove( evtEditor );
  569. evtEditor.TrackEditor._eventEditors.Remove( evtEditor );
  570. Undo.SetTransformParent( evtEditor.Evt.transform, null, string.Empty );
  571. evtEditor.Evt.Track.Remove( evtEditor.Evt );
  572. GameObject evtGO = evtEditor.Evt.gameObject;
  573. Undo.DestroyObjectImmediate( evtEditor );
  574. Undo.DestroyObjectImmediate( evtGO );
  575. }
  576. }
  577. private class MouseHoverData
  578. {
  579. public int Frame = -1;
  580. public FEditor Editor = null;
  581. public void Copy( MouseHoverData data )
  582. {
  583. Frame = data.Frame;
  584. Editor = data.Editor;
  585. }
  586. public void Clear(){ Frame = -1; Editor = null; }
  587. }
  588. public void SetMouseHover( float mouseX, FEditor editor )
  589. {
  590. if( editor == null )
  591. _mouseHoverData.Clear();
  592. else
  593. {
  594. _mouseHoverData.Frame = GetFrameForX( mouseX );
  595. _mouseHoverData.Editor = editor;
  596. }
  597. }
  598. public override void ReserveGuiIds ()
  599. {
  600. _headerResizerGuiId = EditorGUIUtility.GetControlID( FocusType.Passive );
  601. base.ReserveGuiIds();
  602. }
  603. public void OnGUI()
  604. {
  605. if( Application.isPlaying )
  606. {
  607. GUI.color = new Color(0.5f, 0.5f, 0.5f, 0.5f);
  608. GUI.enabled = false;
  609. }
  610. if( !Sequence.HasTimelines() )
  611. {
  612. if( _renderingOnEditorWindow )
  613. _renderingOnEditorWindow.ShowNotification( new GUIContent("Drag GameObjects Here") );
  614. }
  615. if( Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.F && EditorGUIUtility.keyboardControl == 0 )
  616. {
  617. FocusOnSelection();
  618. Event.current.Use();
  619. }
  620. _pixelsPerFrame = (_sequenceRect.width - _headerWidth) / _viewRange.Length;
  621. ReserveGuiIds();
  622. _scrollPos.y = GUI.VerticalScrollbar( _verticalScrollerRect, _scrollPos.y, Mathf.Min( _sequenceRect.height, Height ), 0, Height );
  623. // content is offset based on the scrool position, since we just care about vertical forget the rest
  624. _contentOffset.y = -_scrollPos.y;
  625. Rect scrolledViewRect = _viewRect;
  626. GUI.BeginGroup( scrolledViewRect );
  627. Rect timelineRect = _sequenceRect;
  628. timelineRect.y = -_scrollPos.y;
  629. timelineRect.height = 0;
  630. Handles.color = FGUI.GetLineColor();
  631. Rect normalizedScrollViewRect = _sequenceRect;
  632. normalizedScrollViewRect.x = 0;
  633. normalizedScrollViewRect.yMin = -_scrollPos.y;
  634. SetMouseHover( -1, null );
  635. Render( normalizedScrollViewRect, _headerWidth );
  636. if( Event.current.type == EventType.MouseDown && Event.current.button != 1 && EditorGUIUtility.hotControl == 0 )
  637. StartDragSelect();
  638. if( _isDragSelecting )
  639. {
  640. OnDragSelect();
  641. }
  642. if( Event.current.type == EventType.MouseUp || Event.current.type == EventType.Ignore )
  643. {
  644. if( EditorDragged != null )
  645. {
  646. StopDraggingEditor();
  647. }
  648. if( _isDragSelecting )
  649. {
  650. StopDragSelect();
  651. }
  652. }
  653. if( EditorDragged != null )
  654. {
  655. float indent = 0;
  656. FEditor owner = EditorDragged.Owner;
  657. while( owner != null )
  658. {
  659. indent += owner.ContentOffset.x;
  660. owner = owner.Owner;
  661. }
  662. Rect editorDraggedRect = EditorDraggedRect;
  663. editorDraggedRect.x += indent;
  664. editorDraggedRect.y += Event.current.mousePosition.y;
  665. // EditorGUI.DrawRect( editorDraggedRect, FGUI.GetWindowColor() );
  666. EditorDragged.Render( editorDraggedRect, _headerWidth-indent );
  667. Repaint();
  668. // EditorGUI.DrawTextureAlpha( new Rect(0, 0, 100, 100), EditorGUIUtility.whiteTexture);
  669. if( !(EditorDragged is FContainerEditor) && !(EditorDragged is FEventEditor) )
  670. {
  671. System.Type typeOfOwner = null;
  672. if( EditorDragged is FTrackEditor )
  673. typeOfOwner = typeof(FTimelineEditor);
  674. else if( EditorDragged is FTimelineEditor )
  675. typeOfOwner = typeof(FContainerEditor);
  676. FEditor editorBelowMouse = null;
  677. foreach( FContainerEditor containerEditor in Editors )
  678. {
  679. if( typeOfOwner == typeof(FContainerEditor) )
  680. {
  681. if( containerEditor.GetGlobalRect().Contains( Event.current.mousePosition ) )
  682. {
  683. editorBelowMouse = containerEditor;
  684. break;
  685. }
  686. }
  687. else
  688. {
  689. foreach( FTimelineEditor timelineEditor in containerEditor.Editors )
  690. {
  691. if( typeOfOwner == typeof(FTimelineEditor) )
  692. {
  693. if( timelineEditor.GetGlobalRect().Contains( Event.current.mousePosition ) )
  694. {
  695. editorBelowMouse = timelineEditor;
  696. break;
  697. }
  698. }
  699. else
  700. {
  701. // handle events
  702. }
  703. }
  704. }
  705. }
  706. if( editorBelowMouse != null )
  707. {
  708. Rect r = editorBelowMouse.GetGlobalRect();
  709. float lineWidth = 3;
  710. float halfLineWidth = lineWidth * 0.33f;
  711. Color c = Handles.selectedColor;
  712. c.a = 1f;
  713. Handles.color = c;
  714. Vector3 pt0 = new Vector3( r.xMin+halfLineWidth, r.yMin+halfLineWidth );
  715. Vector3 pt1 = new Vector3( r.xMin+halfLineWidth, r.yMax-halfLineWidth );
  716. Vector3 pt2 = new Vector3( r.xMax-halfLineWidth, r.yMax-halfLineWidth );
  717. Vector3 pt3 = new Vector3( r.xMax-halfLineWidth, r.yMin+halfLineWidth );
  718. Handles.DrawSolidRectangleWithOutline( new Vector3[]{ pt0, pt1, pt2, pt3 }, new Color( 0, 0, 0, 0 ), c );
  719. }
  720. }
  721. }
  722. switch( Event.current.type )
  723. {
  724. case EventType.DragUpdated:
  725. if( normalizedScrollViewRect.Contains( Event.current.mousePosition ) )
  726. {
  727. DragAndDrop.visualMode = DragAndDropVisualMode.Link;
  728. Event.current.Use();
  729. }
  730. break;
  731. case EventType.DragPerform:
  732. if( !normalizedScrollViewRect.Contains( Event.current.mousePosition ) )
  733. break;
  734. FContainerEditor containerEditor = null;
  735. foreach( FContainerEditor editor in Editors )
  736. {
  737. if( editor.GetGlobalRect().Contains( Event.current.mousePosition ) )
  738. {
  739. containerEditor = editor;
  740. break;
  741. }
  742. }
  743. if( containerEditor == null )
  744. {
  745. if( Editors.Count > 0 )
  746. containerEditor = Editors[Editors.Count-1];
  747. else
  748. {
  749. CreateContainer( new FColorSetting("Default", FGUI.DefaultContainerColor()) );
  750. containerEditor = GetEditor<FContainerEditor>( Sequence.Containers[0] );
  751. }
  752. }
  753. foreach( UnityEngine.Object obj in DragAndDrop.objectReferences )
  754. {
  755. if( !(obj is GameObject) )
  756. {
  757. continue;
  758. }
  759. PrefabType prefabType = PrefabUtility.GetPrefabType(obj);
  760. if( prefabType == PrefabType.ModelPrefab || prefabType == PrefabType.Prefab )
  761. continue;
  762. Undo.IncrementCurrentGroup();
  763. UnityEngine.Object[] objsToSave = new UnityEngine.Object[]{ Sequence, this };
  764. Undo.RecordObjects( objsToSave, string.Empty );
  765. FTimeline timeline = FTimeline.Create( ((GameObject)obj).transform );
  766. containerEditor.Container.Add( timeline );
  767. Undo.RegisterCreatedObjectUndo( timeline.gameObject, "create Timeline" );
  768. Undo.CollapseUndoOperations( Undo.GetCurrentGroup() );
  769. }
  770. if( _renderingOnEditorWindow != null )
  771. _renderingOnEditorWindow.RemoveNotification();
  772. Event.current.Use();
  773. DragAndDrop.AcceptDrag();
  774. Refresh();
  775. EditorGUIUtility.ExitGUI();
  776. break;
  777. }
  778. GUI.EndGroup();
  779. if( Sequence.Length != _sequenceLength )
  780. {
  781. if( Sequence.Length < _sequenceLength )
  782. {
  783. _viewRange.Start = 0;
  784. _viewRange.End = Sequence.Length;
  785. }
  786. else
  787. {
  788. _viewRange.End = _viewRange.Start + Mathf.RoundToInt( ((_viewRange.End - _viewRange.Start) / (float)_sequenceLength) * Sequence.Length );
  789. }
  790. _sequenceLength = Sequence.Length;
  791. }
  792. GUI.enabled = true;
  793. GUI.backgroundColor = Color.white;
  794. int newT = FGUI.TimeScrubber( _timeScrubberRect, Sequence.CurrentFrame, Sequence.FrameRate, _viewRange );
  795. if( newT != Sequence.CurrentFrame )
  796. {
  797. if( _renderingOnEditorWindow )
  798. _renderingOnEditorWindow.Focus();
  799. SetCurrentFrame( newT );
  800. if( _isPlaying || Sequence.IsPlaying )
  801. Pause();
  802. }
  803. _viewRange = FGUI.ViewRangeBar( _viewRangeRect, _viewRange, Sequence.Length );
  804. if( _timelineHeaderResizerRect.Contains(Event.current.mousePosition) )
  805. EditorGUIUtility.AddCursorRect( _timelineHeaderResizerRect, MouseCursor.ResizeHorizontal );
  806. switch( Event.current.type )
  807. {
  808. case EventType.MouseDown:
  809. bool leftClick = Event.current.button == 0 && !Event.current.alt;
  810. if( leftClick ) // left button
  811. {
  812. if( EditorGUIUtility.hotControl == 0 && _timelineHeaderResizerRect.Contains(Event.current.mousePosition) )
  813. {
  814. EditorGUIUtility.hotControl = _headerResizerGuiId;
  815. Event.current.Use();
  816. }
  817. else if( Rect.Contains( Event.current.mousePosition ) )
  818. {
  819. DeselectAll();
  820. Event.current.Use();
  821. }
  822. }
  823. break;
  824. case EventType.MouseDrag:
  825. if( EditorGUIUtility.hotControl == _headerResizerGuiId )
  826. {
  827. _headerWidth = (int)Mathf.Max( MINIMUM_HEADER_WIDTH, _headerWidth+Event.current.delta.x );
  828. RebuildLayout( Rect );
  829. EditorWindow.GetWindow<FSequenceEditorWindow>().Repaint();
  830. Event.current.Use();
  831. }
  832. break;
  833. case EventType.MouseUp:
  834. if( EditorGUIUtility.hotControl == _headerResizerGuiId )
  835. {
  836. EditorGUIUtility.hotControl = 0;
  837. Event.current.Use();
  838. }
  839. break;
  840. case EventType.Repaint:
  841. Rect dragArea = _timelineHeaderResizerRect;
  842. dragArea.xMax -= 10;
  843. dragArea.xMin = dragArea.xMax - 16;
  844. GUIStyle dragStyle = FUtility.GetFluxSkin().GetStyle( "HorizontalPanelSeparatorHandle" );
  845. dragStyle.Draw( dragArea, GUIContent.none, 0 );
  846. // GUI.DrawTexture( dragArea, EditorGUIUtility.whiteTexture );
  847. Handles.color = FGUI.GetLineColor();// new Color(0.8f, 0.8f, 0.8f, 0.2f);
  848. // Handles.DrawLine( new Vector3( _viewRect.xMin-16, _sequenceRect.yMax, 0), new Vector3(_viewRect.xMax-RIGHT_BORDER, _sequenceRect.yMax, 0) );
  849. // Handles.DrawLine( new Vector3( _sequenceRect.xMin, _sequenceRect.yMin, 0), new Vector3( _sequenceRect.xMax, _sequenceRect.yMin, 0) );
  850. // Handles.color = Color.black;
  851. break;
  852. case EventType.ScrollWheel:
  853. if( _viewRect.Contains(Event.current.mousePosition) )
  854. {
  855. _scrollPos.y += Event.current.delta.y * SCROLL_WHEEL_SPEED;
  856. Event.current.Use();
  857. }
  858. break;
  859. case EventType.ValidateCommand:
  860. if( EventSelection.Editors.Count == 1 )
  861. Event.current.Use();
  862. else if( EventSelection.Editors.Count == 0 )
  863. {
  864. if( TrackSelection.Editors.Count == 1 )
  865. Event.current.Use();
  866. else if( TrackSelection.Editors.Count == 0 )
  867. {
  868. if( TimelineSelection.Editors.Count == 1 )
  869. Event.current.Use();
  870. else if( TimelineSelection.Editors.Count == 0 )
  871. {
  872. if( ContainerSelection.Editors.Count == 1 )
  873. Event.current.Use();
  874. }
  875. }
  876. }
  877. break;
  878. case EventType.ExecuteCommand:
  879. if( Event.current.commandName == "Copy" )
  880. {
  881. if( EventSelection.Editors.Count == 1 )
  882. CopyEditor(EventSelection.Editors[0]);
  883. else if( EventSelection.Editors.Count == 0 )
  884. {
  885. if( TrackSelection.Editors.Count == 1 )
  886. CopyEditor(TrackSelection.Editors[0]);
  887. else if( TrackSelection.Editors.Count == 0 )
  888. {
  889. if( TimelineSelection.Editors.Count == 1 )
  890. CopyEditor(TimelineSelection.Editors[0]);
  891. else if( TimelineSelection.Editors.Count == 0 )
  892. {
  893. if( ContainerSelection.Editors.Count == 1 )
  894. CopyEditor(ContainerSelection.Editors[0]);
  895. }
  896. }
  897. }
  898. }
  899. break;
  900. }
  901. #if FLUX_TRIAL
  902. GUIStyle watermarkLabel = new GUIStyle( GUI.skin.label );
  903. watermarkLabel.fontSize = 24;
  904. GUIContent watermark = new GUIContent("..::FLUX TRIAL::..");
  905. Vector2 watermarkSize = watermarkLabel.CalcSize( watermark );
  906. Rect watermarkRect = new Rect( Rect.width*0.5f-watermarkSize.x*0.5f, Rect.height*0.5f - watermarkSize.y*0.5f, watermarkSize.x, watermarkSize.y );
  907. GUI.color = new Color( 1f, 1f, 1f, 0.4f );
  908. GUI.Label( watermarkRect, watermark, watermarkLabel );
  909. #endif
  910. }
  911. #region Drag Editor
  912. public void StartDraggingEditor( FEditor editorDragged )
  913. {
  914. if( _isDragSelecting )
  915. return; // if we're drag selecting, move on
  916. EditorDragged = editorDragged;
  917. EditorGUIUtility.hotControl = EditorDragged.GuiId;
  918. Event.current.Use();
  919. }
  920. public void StopDraggingEditor()
  921. {
  922. if( EditorDragged == null ) return;
  923. FEditor editorBelowMouse = null;
  924. if( EditorDragged is FContainerEditor )
  925. {
  926. editorBelowMouse = this;
  927. }
  928. else
  929. {
  930. foreach( FContainerEditor containerEditor in Editors )
  931. {
  932. if( EditorDragged is FTimelineEditor )
  933. {
  934. if( containerEditor.GetGlobalRect().Contains( Event.current.mousePosition ) )
  935. {
  936. editorBelowMouse = containerEditor;
  937. break;
  938. }
  939. }
  940. else
  941. {
  942. foreach( FTimelineEditor timelineEditor in containerEditor.Editors )
  943. {
  944. if( EditorDragged is FTrackEditor )
  945. {
  946. if( timelineEditor.GetGlobalRect().Contains( Event.current.mousePosition ) )
  947. {
  948. editorBelowMouse = timelineEditor;
  949. break;
  950. }
  951. }
  952. else // handle events?
  953. {
  954. }
  955. }
  956. }
  957. }
  958. }
  959. if( editorBelowMouse != null )
  960. {
  961. if( editorBelowMouse == EditorDragged.Owner )
  962. {
  963. if( EditorDragged.Owner is FSequenceEditor )
  964. ((FSequenceEditor)EditorDragged.Owner).UpdateListFromOffsets();
  965. if( EditorDragged.Owner is FContainerEditor )
  966. ((FContainerEditor)EditorDragged.Owner).UpdateListFromOffsets();
  967. if( EditorDragged.Owner is FTimelineEditor )
  968. ((FTimelineEditor)EditorDragged.Owner).UpdateListFromOffsets();
  969. }
  970. else
  971. {
  972. Undo.SetTransformParent( EditorDragged.Obj.transform, editorBelowMouse.Obj.transform, "move Editor" );
  973. }
  974. }
  975. CancelDragEditor();
  976. }
  977. public void CancelDragEditor()
  978. {
  979. if( EditorDragged == null ) return;
  980. EditorDragged.Owner.ClearOffset();
  981. EditorDragged = null;
  982. EditorGUIUtility.hotControl = 0;
  983. Event.current.Use();
  984. Repaint();
  985. }
  986. #endregion
  987. private MouseHoverData _mouseDownData = new MouseHoverData();
  988. private MouseHoverData _mouseHoverData = new MouseHoverData();
  989. private bool _isDragSelecting = false;
  990. public void StartDragSelect()
  991. {
  992. if( _isDragSelecting )
  993. return;
  994. _mouseDownData.Copy( _mouseHoverData );
  995. if( _mouseDownData.Editor != null && EditorGUIUtility.hotControl == 0 )
  996. {
  997. _isDragSelecting = true;
  998. Event.current.Use();
  999. }
  1000. }
  1001. public void StopDragSelect()
  1002. {
  1003. if( !_isDragSelecting )
  1004. return;
  1005. if( !Event.current.shift && !Event.current.alt )
  1006. DeselectAll();
  1007. bool select = !Event.current.alt;
  1008. Rect selectionRect = GetSelectionRect();
  1009. FrameRange selectRange = new FrameRange( GetFrameForX( selectionRect.xMin - _headerWidth ),
  1010. GetFrameForX( selectionRect.xMax - _headerWidth ) );
  1011. for( int i = 0; i != Editors.Count; ++i )
  1012. {
  1013. Rect containerRect = Editors[i].GetGlobalRect();
  1014. if( selectionRect.yMin > containerRect.yMax )
  1015. continue;
  1016. if( selectionRect.yMax < containerRect.yMin )
  1017. break;
  1018. for( int j = 0; j != Editors[i].Editors.Count; ++j )
  1019. {
  1020. List<FTrackEditor> tracks = Editors[i].Editors[j].Editors;
  1021. for( int k = 0; k != tracks.Count; ++k )
  1022. {
  1023. Rect trackRect = tracks[k].GetGlobalRect();
  1024. if( selectionRect.yMin >= trackRect.yMax )
  1025. continue;
  1026. if( selectionRect.yMax <= trackRect.yMin )
  1027. break;
  1028. if( select )
  1029. tracks[k].SelectEvents( selectRange );
  1030. else
  1031. tracks[k].DeselectEvents( selectRange );
  1032. }
  1033. }
  1034. }
  1035. _isDragSelecting = false;
  1036. _mouseDownData.Clear();
  1037. Event.current.Use();
  1038. }
  1039. public void OnDragSelect()
  1040. {
  1041. if( !_isDragSelecting )
  1042. return;
  1043. if( Event.current.shift )
  1044. EditorGUIUtility.AddCursorRect( Rect, MouseCursor.ArrowPlus );
  1045. if( Event.current.alt )
  1046. EditorGUIUtility.AddCursorRect( Rect, MouseCursor.ArrowMinus );
  1047. Rect selectionRect = GetSelectionRect();
  1048. GUI.color = FGUI.GetSelectionColor();
  1049. GUI.DrawTexture( selectionRect, EditorGUIUtility.whiteTexture );
  1050. Repaint();
  1051. }
  1052. private Rect GetSelectionRect()
  1053. {
  1054. MouseHoverData hoverData = _mouseHoverData;
  1055. int hoverFrame = hoverData.Frame;
  1056. if( hoverData.Editor == null )
  1057. {
  1058. hoverData = _mouseDownData;
  1059. hoverFrame = Event.current.mousePosition.x < _headerWidth ? _viewRange.Start : _viewRange.End;
  1060. }
  1061. float x1 = GetXForFrame( _mouseDownData.Frame ) + _headerWidth;
  1062. float x2 = GetXForFrame( hoverFrame ) + _headerWidth;
  1063. Rect downRect = _mouseDownData.Editor.GetGlobalRect();
  1064. Rect hoverRect = hoverData.Editor.GetGlobalRect();
  1065. Rect r = new Rect();
  1066. r.xMin = Mathf.Min( x1, x2 );
  1067. r.xMax = Mathf.Max( x1, x2 );
  1068. r.yMin = Mathf.Min( downRect.yMin, hoverRect.yMin );
  1069. r.yMax = Mathf.Max( downRect.yMax, hoverRect.yMax );
  1070. if( r.width == 0 )
  1071. {
  1072. r.xMin -= 0.5f;
  1073. r.xMax += 0.5f;
  1074. }
  1075. return r;
  1076. }
  1077. public void FocusOnSelection()
  1078. {
  1079. int start = 0;
  1080. int end = Sequence.Length;
  1081. if( _eventSelection.Editors.Count > 0 )
  1082. {
  1083. start = end;
  1084. end = 0;
  1085. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1086. {
  1087. FEvent evt = (FEvent)_eventSelection.Editors[i].Obj;
  1088. if( evt.Start < start )
  1089. start = evt.Start;
  1090. if( evt.End > end )
  1091. end = evt.End;
  1092. }
  1093. }
  1094. _viewRange = new FrameRange( start, end );
  1095. }
  1096. public void MoveEvents( int deltaFrames )
  1097. {
  1098. bool movingLeft = deltaFrames < 0;
  1099. int howMuchCanMove = int.MaxValue;
  1100. for( int i = 0; i != _trackSelection.Editors.Count; ++i )
  1101. {
  1102. if( movingLeft )
  1103. {
  1104. for( int j = 0; j != _trackSelection.Editors[i]._eventEditors.Count; ++j )
  1105. {
  1106. FEventEditor evtEditor = _trackSelection.Editors[i]._eventEditors[j];
  1107. if( evtEditor.IsSelected )
  1108. {
  1109. if( j == 0 )
  1110. howMuchCanMove = Mathf.Min( howMuchCanMove, evtEditor.Evt.Start );
  1111. else if( !_trackSelection.Editors[i]._eventEditors[j-1].IsSelected )
  1112. howMuchCanMove = Mathf.Min( howMuchCanMove , evtEditor.Evt.Start - _trackSelection.Editors[i]._eventEditors[j-1].Evt.End );
  1113. }
  1114. }
  1115. }
  1116. else
  1117. {
  1118. int lastElementIndex = _trackSelection.Editors[i]._eventEditors.Count-1;
  1119. for( int j = lastElementIndex; j != -1; --j )
  1120. {
  1121. FEventEditor evtEditor = _trackSelection.Editors[i]._eventEditors[j];
  1122. if( evtEditor.IsSelected )
  1123. {
  1124. if( j == lastElementIndex )
  1125. howMuchCanMove = Mathf.Min( howMuchCanMove, Sequence.Length - evtEditor.Evt.End );
  1126. else if( !_trackSelection.Editors[i]._eventEditors[j+1].IsSelected )
  1127. howMuchCanMove = Mathf.Min( howMuchCanMove, _trackSelection.Editors[i]._eventEditors[j+1].Evt.Start - evtEditor.Evt.End );
  1128. }
  1129. }
  1130. }
  1131. }
  1132. if( movingLeft )
  1133. {
  1134. howMuchCanMove = -howMuchCanMove;
  1135. deltaFrames = Mathf.Clamp( deltaFrames, howMuchCanMove, 0 );
  1136. }
  1137. else
  1138. {
  1139. deltaFrames = Mathf.Clamp( deltaFrames, 0, howMuchCanMove );
  1140. }
  1141. if( deltaFrames != 0 )
  1142. {
  1143. int start = 0;
  1144. int limit = EventSelection.Editors.Count;
  1145. int increment = 1;
  1146. if( !movingLeft )
  1147. {
  1148. start = limit -1;
  1149. limit = -1;
  1150. increment = -increment;
  1151. }
  1152. int undoGroup = Undo.GetCurrentGroup();
  1153. Undo.SetCurrentGroupName( "move Events" );
  1154. for( int i = start; i != limit; i += increment )
  1155. {
  1156. FrameRange newFrameRange = EventSelection.Editors[i].Evt.FrameRange;
  1157. newFrameRange.Start += deltaFrames;
  1158. newFrameRange.End += deltaFrames;
  1159. MoveEvent( EventSelection.Editors[i].Evt, newFrameRange );
  1160. }
  1161. Undo.CollapseUndoOperations( undoGroup );
  1162. }
  1163. Repaint();
  1164. }
  1165. public void ResizeEventsLeft( int delta )
  1166. {
  1167. int howMuchCanResize = int.MaxValue;
  1168. // making them bigger?
  1169. if( delta < 0 )
  1170. {
  1171. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1172. {
  1173. int evtId = _eventSelection.Editors[i].Obj.GetId ();
  1174. int howMuchCanEvtResize = _eventSelection.Editors[i].Evt.Start;
  1175. if( evtId > 0 )
  1176. howMuchCanEvtResize -= _eventSelection.Editors[i].Evt.Track.GetEvent( evtId - 1 ).End;
  1177. if( howMuchCanResize > howMuchCanEvtResize )
  1178. howMuchCanResize = howMuchCanEvtResize;
  1179. }
  1180. delta = Mathf.Clamp( delta, -howMuchCanResize, 0 );
  1181. }
  1182. else // making them smaller
  1183. {
  1184. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1185. {
  1186. int howMuchCanEvtResize = _eventSelection.Editors[i].Evt.Length-_eventSelection.Editors[i].Evt.GetMinLength();
  1187. if( howMuchCanResize > howMuchCanEvtResize )
  1188. howMuchCanResize = howMuchCanEvtResize;
  1189. }
  1190. delta = Mathf.Clamp( delta, 0, howMuchCanResize );
  1191. }
  1192. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1193. {
  1194. FrameRange evtRange = _eventSelection.Editors[i].Evt.FrameRange;
  1195. evtRange.Start += delta;
  1196. MoveEvent( _eventSelection.Editors[i].Evt, evtRange );
  1197. }
  1198. }
  1199. public void ResizeEventsRight( int delta )
  1200. {
  1201. int howMuchCanResize = int.MaxValue;
  1202. // making them bigger?
  1203. if( delta > 0 )
  1204. {
  1205. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1206. {
  1207. int evtId = _eventSelection.Editors[i].Obj.GetId ();
  1208. int howMuchCanEvtResize = _eventSelection.Editors[i].Evt.IsLastEvent ? Sequence.Length : _eventSelection.Editors[i].Evt.Track.GetEvent( evtId + 1 ).Start;
  1209. howMuchCanEvtResize -= _eventSelection.Editors[i].Evt.End;
  1210. if( howMuchCanResize > howMuchCanEvtResize )
  1211. howMuchCanResize = howMuchCanEvtResize;
  1212. }
  1213. delta = Mathf.Clamp( delta, 0, howMuchCanResize );
  1214. }
  1215. else // making them smaller
  1216. {
  1217. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1218. {
  1219. int howMuchCanEvtResize = _eventSelection.Editors[i].Evt.Length-_eventSelection.Editors[i].Evt.GetMinLength();
  1220. if( howMuchCanResize > howMuchCanEvtResize )
  1221. howMuchCanResize = howMuchCanEvtResize;
  1222. }
  1223. delta = Mathf.Clamp( delta, -howMuchCanResize, 0 );
  1224. }
  1225. for( int i = 0; i != _eventSelection.Editors.Count; ++i )
  1226. {
  1227. FrameRange evtRange = _eventSelection.Editors[i].Evt.FrameRange;
  1228. evtRange.End += delta;
  1229. MoveEvent( _eventSelection.Editors[i].Evt, evtRange );
  1230. }
  1231. }
  1232. public void MoveEvent( FEvent evt, FrameRange newFrameRange )
  1233. {
  1234. FrameRange oldFrameRange = evt.FrameRange;
  1235. if( oldFrameRange == newFrameRange || newFrameRange.Start > newFrameRange.End )
  1236. return;
  1237. if( newFrameRange.Length < evt.GetMinLength() || newFrameRange.Length > evt.GetMaxLength() )
  1238. {
  1239. Debug.LogError( string.Format("Trying to resize an Event to [{0},{1}] (length: {2}) which isn't a valid length, should be between [{3},{4}]", newFrameRange.Start, newFrameRange.End, newFrameRange.Length, evt.GetMinLength(), evt.GetMaxLength() ), evt );
  1240. return;
  1241. }
  1242. bool changedLength = oldFrameRange.Length != newFrameRange.Length;
  1243. if( !evt.Track.CanAdd( evt, newFrameRange ) )
  1244. return;
  1245. Undo.RecordObject( evt, changedLength ? "resize Event" : "move Event" );
  1246. evt.FrameRange = newFrameRange;
  1247. GetEditor<FEventEditor>( evt ).OnEventMoved( oldFrameRange );
  1248. EditorUtility.SetDirty( evt );
  1249. if( FSequenceEditorWindow.instance != null )
  1250. FSequenceEditorWindow.instance.Repaint();
  1251. }
  1252. public void SelectExclusive( ISelectableElement e )
  1253. {
  1254. int undoGroup = Undo.GetCurrentGroup();
  1255. DeselectAll();
  1256. Select( e );
  1257. Undo.CollapseUndoOperations( undoGroup );
  1258. Repaint();
  1259. }
  1260. public void Select( List<ISelectableElement> elements )
  1261. {
  1262. Undo.IncrementCurrentGroup();
  1263. foreach( ISelectableElement e in elements )
  1264. {
  1265. if( !e.IsSelected )
  1266. Select( e );
  1267. }
  1268. Undo.CollapseUndoOperations( Undo.GetCurrentGroup() );
  1269. Repaint();
  1270. }
  1271. public void Deselect( IEnumerable<ISelectableElement> elements )
  1272. {
  1273. foreach( ISelectableElement e in elements )
  1274. {
  1275. if( e.IsSelected )
  1276. Deselect( e );
  1277. }
  1278. Repaint();
  1279. }
  1280. public void Select( ISelectableElement e )
  1281. {
  1282. if( e.IsSelected )
  1283. return;
  1284. int undoGroup = Undo.GetCurrentGroup();
  1285. string undoStr = "select ";
  1286. if( e is FEventEditor )
  1287. {
  1288. Select( ((FEventEditor)e).TrackEditor );
  1289. undoStr += "Event";
  1290. }
  1291. else if( e is FTrackEditor )
  1292. {
  1293. undoStr += "Track";
  1294. }
  1295. else if( e is FTimelineEditor )
  1296. {
  1297. Deselect( EventSelection.Editors.ToArray() );
  1298. Deselect( TrackSelection.Editors.ToArray() );
  1299. Deselect( ContainerSelection.Editors.ToArray() );
  1300. undoStr += "Timeline";
  1301. }
  1302. else if( e is FContainerEditor )
  1303. {
  1304. Deselect( EventSelection.Editors.ToArray() );
  1305. Deselect( TrackSelection.Editors.ToArray() );
  1306. Deselect( TimelineSelection.Editors.ToArray() );
  1307. undoStr += "Container";
  1308. }
  1309. Undo.RecordObjects( new Object[]{ (UnityEngine.Object)e, this }, undoStr );
  1310. if( e is FEventEditor )
  1311. EventSelection.Add( (FEventEditor)e );
  1312. else if( e is FTrackEditor )
  1313. TrackSelection.Add( (FTrackEditor)e );
  1314. else if( e is FTimelineEditor )
  1315. TimelineSelection.Add( (FTimelineEditor)e );
  1316. else if( e is FContainerEditor )
  1317. ContainerSelection.Add( (FContainerEditor)e );
  1318. e.OnSelect();
  1319. Repaint();
  1320. Undo.CollapseUndoOperations( undoGroup );
  1321. }
  1322. public void Deselect( ISelectableElement e )
  1323. {
  1324. if( !e.IsSelected )
  1325. return;
  1326. string undoStr = "deselect ";
  1327. if( e is FEventEditor )
  1328. undoStr += "Event";
  1329. else if( e is FTrackEditor )
  1330. undoStr += "Track";
  1331. else if( e is FTimelineEditor )
  1332. undoStr += "Timeline";
  1333. else if( e is FContainerEditor )
  1334. undoStr += "Container";
  1335. Undo.RecordObjects( new Object[]{ (UnityEngine.Object)e, this }, undoStr );
  1336. if( e is FEventEditor )
  1337. EventSelection.Remove( (FEventEditor)e );
  1338. else if( e is FTrackEditor )
  1339. TrackSelection.Remove( (FTrackEditor)e );
  1340. else if( e is FTimelineEditor )
  1341. TimelineSelection.Remove( (FTimelineEditor)e );
  1342. else if( e is FContainerEditor )
  1343. ContainerSelection.Remove( (FContainerEditor)e );
  1344. e.OnDeselect();
  1345. Repaint();
  1346. }
  1347. public void DeselectAll()
  1348. {
  1349. int numEvents = EventSelection.Editors.Count;
  1350. int numTracks = TrackSelection.Editors.Count;
  1351. int numTimelines = TimelineSelection.Editors.Count;
  1352. int numContainers = ContainerSelection.Editors.Count;
  1353. int totalSelected = numEvents + numTracks + numTimelines + numContainers;
  1354. if( totalSelected == 0 )
  1355. return;
  1356. // tracks + events + window
  1357. Object[] objsToSave = new Object[totalSelected+1];
  1358. int i = 0;
  1359. for( int j = 0; j != numEvents; ++i, ++j )
  1360. objsToSave[i] = EventSelection.Editors[j];
  1361. for( int j = 0; j != numTracks; ++i, ++j )
  1362. objsToSave[i] = TrackSelection.Editors[j];
  1363. for( int j = 0; j != numTimelines; ++i, ++j )
  1364. objsToSave[i] = TimelineSelection.Editors[j];
  1365. for( int j = 0; j != numContainers; ++i, ++j )
  1366. objsToSave[i] = ContainerSelection.Editors[j];
  1367. objsToSave[totalSelected] = this;
  1368. Undo.RegisterCompleteObjectUndo( objsToSave, "deselect all" );
  1369. for( int j = 0; j != numEvents; ++j )
  1370. EventSelection.Editors[j].OnDeselect();
  1371. for( int j = 0; j != numTracks; ++j )
  1372. TrackSelection.Editors[j].OnDeselect();
  1373. for( int j = 0; j != numTimelines; ++j )
  1374. TimelineSelection.Editors[j].OnDeselect();
  1375. for( int j = 0; j != numContainers; ++j )
  1376. ContainerSelection.Editors[j].OnDeselect();
  1377. EventSelection.Clear();
  1378. TrackSelection.Clear();
  1379. TimelineSelection.Clear();
  1380. ContainerSelection.Clear();
  1381. Repaint();
  1382. if( FInspectorWindow._instance )
  1383. {
  1384. FInspectorWindow._instance.Repaint();
  1385. }
  1386. }
  1387. public void EnableAllTracks( bool enable )
  1388. {
  1389. foreach( FContainerEditor containerEditor in Editors )
  1390. {
  1391. foreach( FTimelineEditor timelineEditor in containerEditor.Editors )
  1392. {
  1393. foreach( FTrackEditor trackEditor in timelineEditor.Editors )
  1394. {
  1395. if( trackEditor.Track.enabled != enable )
  1396. {
  1397. trackEditor.OnToggle( enable );
  1398. }
  1399. }
  1400. }
  1401. }
  1402. }
  1403. private Dictionary<int, FTrackEditor> _dirtyTracks = new Dictionary<int, FTrackEditor>();
  1404. public void SetDirty( FTrackEditor trackEditor )
  1405. {
  1406. if( !_dirtyTracks.ContainsKey( trackEditor.GetInstanceID() ) )
  1407. _dirtyTracks.Add( trackEditor.GetInstanceID(), trackEditor );
  1408. _timeNotifyDirtyTracks = EditorApplication.timeSinceStartup + NOTIFY_DIRTY_TRACKS_DELTA;
  1409. }
  1410. public void SetAllDirty()
  1411. {
  1412. foreach( FContainerEditor containerEditor in Editors )
  1413. {
  1414. foreach( FTimelineEditor timelineEditor in containerEditor.Editors )
  1415. {
  1416. foreach( FTrackEditor trackEditor in timelineEditor.Editors )
  1417. {
  1418. SetDirty( trackEditor );
  1419. }
  1420. }
  1421. }
  1422. }
  1423. public void NotifyDirtyTracks()
  1424. {
  1425. int currentFrame = Sequence.CurrentFrame;
  1426. Dictionary<int, FTrackEditor>.Enumerator e = _dirtyTracks.GetEnumerator();
  1427. while( e.MoveNext() )
  1428. {
  1429. e.Current.Value.OnTrackChanged();
  1430. }
  1431. _dirtyTracks.Clear();
  1432. if( currentFrame >= 0 && Sequence.CurrentFrame != currentFrame )
  1433. SetCurrentFrame( currentFrame );
  1434. }
  1435. #region Playback functions
  1436. private bool _isPlaying = false;
  1437. public bool IsPlaying { get { return _isPlaying; } }
  1438. private bool _isPlayingForward = true;
  1439. public bool IsPlayingForward {
  1440. get { return _isPlayingForward; }
  1441. set {
  1442. _isPlayingForward = value;
  1443. if( Sequence )
  1444. {
  1445. Sequence.Speed = (_isPlayingForward ? 1 : -1) * Mathf.Abs(Sequence.Speed);
  1446. }
  1447. }
  1448. }
  1449. private double _timeLastUpdate = -1;
  1450. private float _currentTime = 0;
  1451. public void Play()
  1452. {
  1453. Play( true );
  1454. }
  1455. public void Play( bool restart )
  1456. {
  1457. if( !Sequence.IsStopped && restart )
  1458. Sequence.Stop();
  1459. int frame = _viewRange.Cull( Sequence.CurrentFrame );
  1460. if( !Sequence.IsPlayingForward && frame == 0 )
  1461. {
  1462. Sequence.Stop();
  1463. frame = _viewRange.End;
  1464. }
  1465. _timeLastUpdate = EditorApplication.timeSinceStartup;
  1466. _currentTime = frame * Sequence.InverseFrameRate;
  1467. if( Sequence.Speed == 0 )
  1468. Sequence.Speed = Sequence.DefaultSpeed;
  1469. if( Application.isPlaying )
  1470. {
  1471. Sequence.Play( _currentTime );
  1472. }
  1473. else
  1474. {
  1475. SetCurrentFrame( frame );
  1476. _isPlaying = true;
  1477. }
  1478. FUtility.RepaintGameView();
  1479. }
  1480. public void Stop()
  1481. {
  1482. if( !object.Equals(Sequence, null) )
  1483. {
  1484. if( !Sequence.IsStopped )
  1485. {
  1486. Sequence.Stop( true );
  1487. for( int i = 0; i != Editors.Count; ++i )
  1488. Editors[i].OnStop();
  1489. }
  1490. }
  1491. _isPlaying = false;
  1492. FUtility.RepaintGameView();
  1493. }
  1494. public void Pause()
  1495. {
  1496. // Debug.Log ("Pause");
  1497. Sequence.Pause();
  1498. _isPlaying = false;
  1499. FUtility.RepaintGameView();
  1500. }
  1501. public void SetCurrentFrame( int frame )
  1502. {
  1503. SetCurrentTime( frame * Sequence.InverseFrameRate );
  1504. }
  1505. public void SetCurrentTime( float time )
  1506. {
  1507. if( _dirtyTracks.Count > 0 )
  1508. NotifyDirtyTracks();
  1509. _currentTime = time;
  1510. if( !Sequence.IsInit )
  1511. Sequence.Init();
  1512. int frame = (int)(time * Sequence.FrameRate);
  1513. Sequence.SetCurrentTimeEditor( frame * Sequence.InverseFrameRate );
  1514. for( int i = 0; i != Editors.Count; ++i )
  1515. Editors[i].UpdateTimelines( frame, time );
  1516. FUtility.RepaintGameView();
  1517. }
  1518. public void Update()
  1519. {
  1520. if( EditorApplication.isCompiling )
  1521. {
  1522. _isEditorCompiling = true;
  1523. Stop();
  1524. }
  1525. else if( _isEditorCompiling )
  1526. {
  1527. _isEditorCompiling = false;
  1528. if( Sequence != null )
  1529. {
  1530. foreach( FContainer container in Sequence.Containers )
  1531. {
  1532. foreach( FTimeline timeline in container.Timelines )
  1533. {
  1534. foreach( FTrack track in timeline.Tracks )
  1535. {
  1536. if( track.HasCache )
  1537. {
  1538. track.ClearCache();
  1539. }
  1540. }
  1541. }
  1542. }
  1543. }
  1544. Refresh();
  1545. }
  1546. // going into playmode
  1547. if( EditorApplication.isPlayingOrWillChangePlaymode && !EditorApplication.isPlaying )
  1548. {
  1549. OnPlaymodeWillChange();
  1550. }
  1551. // coming out of playmode
  1552. if( !EditorApplication.isPlayingOrWillChangePlaymode && EditorApplication.isPlaying )
  1553. {
  1554. _wasUnityInPlaymode = true;
  1555. OnPlaymodeWillChange();
  1556. }
  1557. _onUpdateEvent.Invoke();
  1558. if( _dirtyTracks.Count > 0 && _timeNotifyDirtyTracks < EditorApplication.timeSinceStartup /* && !_sequence.IsStopped */)
  1559. NotifyDirtyTracks();
  1560. // if( EditorApplication.isPlayingOrWillChangePlaymode )
  1561. // {
  1562. // Debug.Log("Application.isPlaying: " + Application.isPlaying +
  1563. // "\nEditorApplication.isPlaying: " + EditorApplication.isPlaying +
  1564. // "\nisPlayingOrWillChangePlaymode: " + EditorApplication.isPlayingOrWillChangePlaymode +
  1565. // "\nisPaused: " + EditorApplication.isPaused +
  1566. // "\nisUpdating: " + EditorApplication.isUpdating );
  1567. // }
  1568. if( !_isPlaying )
  1569. return;
  1570. float delta = (float)((EditorApplication.timeSinceStartup - _timeLastUpdate)*Sequence.Speed);
  1571. _timeLastUpdate = EditorApplication.timeSinceStartup;
  1572. if( Sequence.UpdateMode != AnimatorUpdateMode.UnscaledTime )
  1573. {
  1574. delta *= Time.timeScale;
  1575. }
  1576. float newTime = _currentTime + delta;
  1577. if( newTime > _viewRange.End * Sequence.InverseFrameRate )
  1578. {
  1579. Sequence.OnFinishedCallback.Invoke( Sequence );
  1580. Play();
  1581. }
  1582. else if( newTime < 0 && !Sequence.IsPlayingForward )
  1583. {
  1584. Sequence.OnFinishedCallback.Invoke( Sequence );
  1585. Play();
  1586. }
  1587. else
  1588. SetCurrentTime( newTime );
  1589. Repaint();
  1590. }
  1591. #endregion
  1592. #region FEditor Copy / Paste
  1593. public static FObject CopyObject { get { return _copyObject; } }
  1594. private static FObject _copyObject = null;
  1595. public void CopyEditor(FEditor editor)
  1596. {
  1597. Undo.RecordObject( this, string.Empty );
  1598. if( _copyObject != null )
  1599. {
  1600. Undo.DestroyObjectImmediate( _copyObject.gameObject );
  1601. }
  1602. _copyObject = Instantiate<FObject>( editor.Obj );
  1603. string objName = _copyObject.name;
  1604. objName = objName.Substring(0, objName.Length - "(Clone)".Length);
  1605. _copyObject.gameObject.name = objName;
  1606. _copyObject.gameObject.hideFlags = HideFlags.HideAndDontSave;
  1607. Undo.RegisterCreatedObjectUndo(CopyObject.gameObject, "Copy " + editor.Obj.name);
  1608. }
  1609. public void CutEditor(FEditor editor)
  1610. {
  1611. if( editor.IsSelected )
  1612. Deselect( editor );
  1613. CopyEditor( editor );
  1614. DestroyEditor( editor );
  1615. }
  1616. #endregion FEditor Copy / Paste
  1617. public void SaveToXml()
  1618. {
  1619. Sequence.SaveToXml();
  1620. AssetDatabase.Refresh();
  1621. }
  1622. public void ReadFromXml()
  1623. {
  1624. }
  1625. }
  1626. }