// public static EditorWindow GetAnimationWindow( bool showWindow ) // { // System.Type t = typeof(EditorWindow).Assembly.GetType("UnityEditor.AnimationWindow"); // if( showWindow ) // { // return EditorWindow.GetWindow( t ); // } // // System.Reflection.MethodInfo getWindow = typeof(EditorWindow).GetMethod( "GetWindowDontShow", System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Static ); // System.Reflection.MethodInfo getWindowGeneric = getWindow.MakeGenericMethod( t ); // return (EditorWindow)getWindowGeneric.Invoke(null, null); // } #endregion #region Upgrade Sequences public static void Upgrade(FSequence sequence) { const int fluxVersion = Flux.FUtility.FLUX_VERSION; if (sequence.Version == fluxVersion) { return; } Debug.LogFormat("Upgrading sequence '{0}' from version '{1}' to '{2}'", sequence.name, sequence.Version, fluxVersion); // is it before 2.0.0 release? if (sequence.Version < 200) { // set TimelineContainer as Content Transform timelineContainer = null; foreach (Transform t in sequence.transform) { if (t.name == "Timeline Container") { timelineContainer = t; break; } } if (timelineContainer == null) { timelineContainer = new GameObject("SequenceContent").transform; timelineContainer.hideFlags |= HideFlags.HideInHierarchy; } sequence.Content = timelineContainer; // create a container, and add it to the sequence FContainer container = FContainer.Create(FContainer.DEFAULT_COLOR); sequence.Add(container); FTimeline[] timelines = timelineContainer.GetComponentsInChildren <FTimeline>(); foreach (FTimeline timeline in timelines) { container.Add(timeline); List <FTrack> tracks = timeline.Tracks; foreach (FTrack track in tracks) { if (track is FAnimationTrack) { FAnimationTrack animTrack = (FAnimationTrack)track; if (animTrack.AnimatorController != null) { FAnimationTrackInspector inspector = (FAnimationTrackInspector)FAnimationTrackInspector.CreateEditor(animTrack); AnimatorController controller = (AnimatorController)animTrack.AnimatorController; inspector.UpdateLayer(controller == null || controller.layers.Length == 0 ? null : controller.layers[0]); inspector.serializedObject.ApplyModifiedProperties(); if (controller.layers.Length > 0) { while (controller.layers[0].stateMachine.stateMachines.Length > 0) { controller.layers[0].stateMachine.RemoveStateMachine(controller.layers[0].stateMachine.stateMachines[controller.layers[0].stateMachine.stateMachines.Length - 1].stateMachine); } while (controller.layers[0].stateMachine.states.Length > 0) { controller.layers[0].stateMachine.RemoveState(controller.layers[0].stateMachine.states[controller.layers[0].stateMachine.states.Length - 1].state); } } Editor.DestroyImmediate(inspector); FAnimationTrackInspector.RebuildStateMachine(animTrack); } } track.CacheMode = track.RequiredCacheMode; } // foreach( FTrack track in tracks ) // { // track.CacheType = track.DefaultCacheType(); // } } } sequence.Version = fluxVersion; }
void OnGUI() { #if FLUX_PROFILE Profiler.BeginSample("Flux OnGUI"); #endif if (_sequenceEditor == null) { return; } Rect currentWindowRect = position; currentWindowRect.x = 0; currentWindowRect.y = 0; if (currentWindowRect != _windowRect) { RebuildLayout(); } if (Event.current.type == EventType.Ignore) { EditorGUIUtility.hotControl = 0; } FSequence sequence = _sequenceEditor.GetSequence(); if (sequence == null) { ShowNotification(new GUIContent("Select Or Create Sequence")); } else if (Event.current.isKey) { if (Event.current.keyCode == KeyCode.Space) { if (Event.current.type == EventType.KeyUp) { if (_sequenceEditor.IsPlaying) { if (Event.current.shift) { Stop(); } else { Pause(); } } else { Play(Event.current.shift); } Repaint(); } Event.current.Use(); } if (Event.current.type == EventType.KeyDown && Event.current.keyCode == KeyCode.Return) { EditorGUIUtility.keyboardControl = 0; Event.current.Use(); Repaint(); } } // header _windowHeader.OnGUI(); if (sequence == null) { return; } // toolbar _toolbar.OnGUI(); switch (Event.current.type) { case EventType.KeyDown: if (Event.current.keyCode == KeyCode.Backspace || Event.current.keyCode == KeyCode.Delete) { _sequenceEditor.DestroyEvents(_sequenceEditor._selectedEvents); Event.current.Use(); } else if (Event.current.keyCode == KeyCode.K && _sequenceEditor.GetSequence().GetCurrentFrame() >= 0) { _sequenceEditor.AddEvent(_sequenceEditor.GetSequence().GetCurrentFrame()); Event.current.Use(); } break; case EventType.MouseDown: break; case EventType.MouseUp: break; } if (Event.current.type == EventType.ValidateCommand) { Repaint(); } _sequenceEditor.OnGUI(); // because of a bug with windows editor, we have to not catch right button // otherwise ContextClick doesn't get called if (Event.current.type == EventType.MouseUp && Event.current.button != 1) { Event.current.Use(); } // handle drag & drop if (Event.current.type == EventType.DragUpdated) { if (_windowRect.Contains(Event.current.mousePosition)) { DragAndDrop.visualMode = DragAndDropVisualMode.Link; Event.current.Use(); } } else if (Event.current.type == EventType.DragPerform) { if (_windowRect.Contains(Event.current.mousePosition)) { foreach (UnityEngine.Object obj in DragAndDrop.objectReferences) { if (!(obj is GameObject)) { continue; } PrefabType prefabType = PrefabUtility.GetPrefabType(obj); if (prefabType == PrefabType.ModelPrefab || prefabType == PrefabType.Prefab) { continue; } Undo.IncrementCurrentGroup(); UnityEngine.Object[] objsToSave = new UnityEngine.Object[] { sequence, this }; Undo.RegisterCompleteObjectUndo(objsToSave, string.Empty); GameObject timelineGO = new GameObject(obj.name); FTimeline timeline = timelineGO.AddComponent <Flux.FTimeline>(); timeline.SetOwner(((GameObject)obj).transform); sequence.Add(timeline); Undo.RegisterCompleteObjectUndo(objsToSave, string.Empty); Undo.RegisterCreatedObjectUndo(timeline.gameObject, "create Timeline"); Undo.CollapseUndoOperations(Undo.GetCurrentGroup()); } RemoveNotification(); Event.current.Use(); DragAndDrop.AcceptDrag(); Refresh(); EditorGUIUtility.ExitGUI(); } } if (Event.current.type == EventType.Repaint) { Handles.DrawLine(new Vector3(_windowHeaderRect.xMin, _windowHeaderRect.yMax, 0), new Vector3(_windowHeaderRect.xMax - FSequenceEditor.RIGHT_BORDER, _windowHeaderRect.yMax, 0)); } #if FLUX_PROFILE Profiler.EndSample(); #endif }