コード例 #1
0
        public static float FindPrevVisibleKeyframeTime(USHierarchy hierarchy, USSequencer sequence)
        {
            var previousKeyframeTime = 0.0f;

            foreach (var rootItems in hierarchy.RootItems)
            {
                if (!rootItems.IsExpanded)
                {
                    continue;
                }

                foreach (var rootChild in rootItems.Children)
                {
                    var propertyTimelineContainer = rootChild as USPropertyTimelineHierarchyItem;

                    if (propertyTimelineContainer == null || !propertyTimelineContainer.IsExpanded)
                    {
                        continue;
                    }

                    var componentPreviousKeyframeTime = propertyTimelineContainer.GetPreviousShownKeyframeTime(sequence.RunningTime);
                    if (componentPreviousKeyframeTime > previousKeyframeTime)
                    {
                        previousKeyframeTime = componentPreviousKeyframeTime;
                    }
                }
            }

            return(previousKeyframeTime);
        }
コード例 #2
0
        public static float FindNextVisibleKeyframeTime(USHierarchy hierarchy, USSequencer sequence)
        {
            var nextKeyframeTime = sequence.Duration;

            foreach (var rootItems in hierarchy.RootItems)
            {
                if (!rootItems.IsExpanded)
                {
                    continue;
                }

                foreach (var rootChild in rootItems.Children)
                {
                    var propertyTimelineContainer = rootChild as USPropertyTimelineHierarchyItem;

                    if (propertyTimelineContainer == null || !propertyTimelineContainer.IsExpanded)
                    {
                        continue;
                    }

                    var componentNextKeyframeTime = propertyTimelineContainer.GetNextShownKeyframeTime(sequence.RunningTime);
                    if (componentNextKeyframeTime < nextKeyframeTime)
                    {
                        nextKeyframeTime = componentNextKeyframeTime;
                    }
                }
            }

            return(nextKeyframeTime);
        }
コード例 #3
0
        private void ProcessDuplicate(IUSHierarchyItem item)
        {
            var timelineContainer = item as USTimelineContainerHierarchyItem;

            if (timelineContainer != null)
            {
                var newTimelineContainer = USEditor.DuplicateTimelineContainer(timelineContainer.TimelineContainer, CurrentSequence);

                USUndoManager.RegisterCreatedObjectUndo(newTimelineContainer.gameObject, "Duplicate Timeline");

                AddNewTimelineContainer(newTimelineContainer);
            }

            var timeline = item as IUSTimelineHierarchyItem;

            if (timeline != null)
            {
                USUndoManager.RegisterCompleteObjectUndo(this, "Duplicate Timeline");
                USUndoManager.RegisterCompleteObjectUndo(USHierarchy, "Duplicate Timeline");

                var newTimeline = USEditor.DuplicateTimeline(timeline.BaseTimeline, timeline.BaseTimeline.TimelineContainer);
                USUndoManager.RegisterCreatedObjectUndo(newTimeline.gameObject, "Duplicate Timeline");

                var parent = USHierarchy.GetParentOf(item) as USTimelineContainerHierarchyItem;
                USUndoManager.RegisterCompleteObjectUndo(parent, "Duplicate Timeline");
                parent.AddTimeline(newTimeline);
            }
        }
コード例 #4
0
 public void OnSceneGUI()
 {
     if (USHierarchy)
     {
         USHierarchy.OnSceneGUI();
     }
 }
コード例 #5
0
        public void ProcessDelete(IUSHierarchyItem item)
        {
            var timelineContainerItem = item as USTimelineContainerHierarchyItem;
            var timelineHierarchyItem = item as IUSTimelineHierarchyItem;

            if (timelineContainerItem)
            {
                foreach (var child in timelineContainerItem.Children.ToList())
                {
                    ProcessDelete(child);
                }

                USUndoManager.RegisterCompleteObjectUndo(this, "Remove Timeline Container");
                USUndoManager.RegisterCompleteObjectUndo(USHierarchy, "Remove Timeline Container");
                USHierarchy.RootItems.Remove(timelineContainerItem);

                var gameObjectToDestroy = timelineContainerItem.TimelineContainer.gameObject;
                USUndoManager.DestroyImmediate(timelineContainerItem);
                USUndoManager.DestroyImmediate(gameObjectToDestroy);
            }
            else if (timelineHierarchyItem)
            {
                var parent = USHierarchy.GetParentOf(timelineHierarchyItem);

                timelineHierarchyItem.RestoreBaseState();

                USUndoManager.RegisterCompleteObjectUndo(parent, "Remove Timeline");
                parent.RemoveChild(timelineHierarchyItem);

                var gameObjectToDestroy = timelineHierarchyItem.TimelineToDestroy().gameObject;
                USUndoManager.DestroyImmediate(timelineHierarchyItem);
                USUndoManager.DestroyImmediate(gameObjectToDestroy);
            }
        }
コード例 #6
0
 public void ExternalModification()
 {
     if (USHierarchy)
     {
         USHierarchy.ExternalModification();
     }
 }
コード例 #7
0
 public void RestoreBaseState()
 {
     if (USHierarchy)
     {
         USHierarchy.RestoreBaseState();
     }
 }
コード例 #8
0
        public override void OnEnable()
        {
            base.OnEnable();

            if (USHierarchy == null)
            {
                USHierarchy = CreateInstance <USHierarchy>();
            }
        }
コード例 #9
0
        public void AddNewTimelineContainer(USTimelineContainer timelineContainer)
        {
            var newHierarchyItem = CreateInstance(typeof(USTimelineContainerHierarchyItem)) as USTimelineContainerHierarchyItem;

            USUndoManager.RegisterCreatedObjectUndo(newHierarchyItem, "Add New Timeline Container");

            USUndoManager.RegisterCompleteObjectUndo(newHierarchyItem, "Add New Timeline Container");
            newHierarchyItem.SetupWithTimelineContainer(timelineContainer);

            USUndoManager.RegisterCompleteObjectUndo(USHierarchy, "Add New Timeline Container");
            USHierarchy.AddHierarchyItemToRoot(newHierarchyItem as IUSHierarchyItem);
        }
コード例 #10
0
        private void MaintainHierarchyFor(USSequencer sequence)
        {
            USHierarchy.OnItemClicked        -= OnItemClicked;
            USHierarchy.OnItemClicked        += OnItemClicked;
            USHierarchy.OnItemContextClicked -= OnItemContextClicked;
            USHierarchy.OnItemContextClicked += OnItemContextClicked;

            USHierarchy.EditorWindow       = SequenceWindow;
            USHierarchy.CurrentXMarkerDist = zoomInfo.currentXMarkerDist;
            USHierarchy.FloatingWidth      = FloatingWidth;
            USHierarchy.Scrollable         = true;
            USHierarchy.ScrollPos          = ScrollInfo.currentScroll;
            USHierarchy.XScale             = (totalPixelWidthOfTimeline / ScrubArea.width);

            USHierarchy.CheckConsistency();
        }
コード例 #11
0
        public void OnSequenceChange(USSequencer newSequence)
        {
            CurrentSequence = newSequence;
            ZoomInfo.Reset();
            ScrollInfo.Reset();
            totalPixelWidthOfTimeline = 1.0f;
            UpdateCachedMarkerInformation();

            if (USHierarchy == null)
            {
                USHierarchy = CreateInstance(typeof(USHierarchy)) as USHierarchy;
            }

            foreach (var newTimelineContainer in CurrentSequence.TimelineContainers)
            {
                var newHierarchyItem = CreateInstance(typeof(USTimelineContainerHierarchyItem)) as USTimelineContainerHierarchyItem;
                newHierarchyItem.SetupWithTimelineContainer(newTimelineContainer);
                USHierarchy.AddHierarchyItemToRoot(newHierarchyItem as IUSHierarchyItem);
            }

            SequenceWindow.Repaint();
        }
コード例 #12
0
        public void HandleEvent(EventType eventType, int button, Vector2 mousePosition)
        {
            var selectableContainers = USHierarchy.ISelectableContainers();
            var allObjectsUnderMouse = new List <UnityEngine.Object>();
            var hasObjectsUnderMouse = false;

            objectContainerMap.Clear();

            foreach (var selectableContainer in selectableContainers)
            {
                var objectsUnderMouse = new List <UnityEngine.Object>();
                if (IsBoxSelecting && HasStartedDrag)
                {
                    objectsUnderMouse = selectableContainer.GetSelectableObjectsUnderRect(SelectionArea, ScrollInfo.currentScroll.y);
                }
                else
                {
                    objectsUnderMouse = selectableContainer.GetSelectableObjectUnderPos(mousePosition);
                }

                allObjectsUnderMouse.AddRange(objectsUnderMouse);
                if (objectsUnderMouse.Count > 0)
                {
                    hasObjectsUnderMouse = true;
                }

                objectContainerMap[selectableContainer] = objectsUnderMouse;
            }

            switch (eventType)
            {
            case EventType.MouseDown:
            {
                HasProcessedInitialDrag = false;
                IsDragging        = false;
                IsBoxSelecting    = false;
                DragStartPosition = mousePosition;

                if (!hasObjectsUnderMouse && Event.current.button == 0)
                {
                    IsBoxSelecting = true;
                }
                if (hasObjectsUnderMouse && Event.current.button == 0)
                {
                    IsDragging = true;
                }
                if (IsDragging && Event.current.alt && Event.current.control)
                {
                    IsDuplicating = true;
                }

                // if we have no objects under our mouse, then we are likely trying to clear our selection
                if (!hasObjectsUnderMouse && (!Event.current.control && !Event.current.command))
                {
                    foreach (var selectableContainer in selectableContainers)
                    {
                        selectableContainer.ResetSelection();
                    }
                }

                if (!Event.current.control && !Event.current.command)
                {
                    Selection.activeGameObject = null;
                    Selection.activeObject     = null;
                    Selection.activeTransform  = null;
                    Selection.objects          = new UnityEngine.Object[] { };
                }

                HasStartedDrag = false;
                SequenceWindow.Repaint();
            }
            break;

            case EventType.MouseDrag:
            {
                if (!HasStartedDrag)
                {
                    HasStartedDrag = true;
                }

                SequenceWindow.Repaint();
            }
            break;

            case EventType.MouseUp:
            {
                HasProcessedInitialDrag = false;
                IsBoxSelecting          = false;
                IsDragging    = false;
                IsDuplicating = false;
                HasDuplicated = false;
                SequenceWindow.Repaint();
            }
            break;
            }

            if (IsBoxSelecting && HasStartedDrag && eventType == EventType.MouseDrag)
            {
                foreach (var selectableContainer in selectableContainers)
                {
                    var objectsUnderSelection = objectContainerMap[selectableContainer];
                    var difference            = objectsUnderSelection.Where(selectedObject => !selectableContainer.SelectedObjects.Contains(selectedObject)).ToList();
                    if (difference.Count > 0 || (selectableContainer.SelectedObjects.Count != objectsUnderSelection.Count))
                    {
                        EditorGUI.FocusTextInControl("");
                        selectableContainer.ResetSelection();
                        selectableContainer.OnSelectedObjects(objectsUnderSelection);
                    }
                }
            }
            if ((!Event.current.control && !Event.current.command) && hasObjectsUnderMouse && !HasStartedDrag && (eventType == EventType.MouseUp || (eventType == EventType.MouseDown && button == 1)))
            {
                foreach (var selectableContainer in selectableContainers)
                {
                    EditorGUI.FocusTextInControl("");
                    var objectsUnderSelection = objectContainerMap[selectableContainer];
                    selectableContainer.ResetSelection();
                    selectableContainer.OnSelectedObjects(objectsUnderSelection);
                }

                if (allObjectsUnderMouse.Count == 1)
                {
                    var internalKeyframe = allObjectsUnderMouse[0] as USInternalKeyframe;
                    if (internalKeyframe)
                    {
                        SequenceWindow.SetRunningTime(internalKeyframe.Time);
                    }

                    var observerKeyframe = allObjectsUnderMouse[0] as USObserverKeyframe;
                    if (observerKeyframe)
                    {
                        Selection.activeObject = observerKeyframe;
                    }

                    var eventBase = allObjectsUnderMouse[0] as USEventBase;
                    if (eventBase)
                    {
                        Selection.activeGameObject = eventBase.gameObject;
                        Selection.activeTransform  = eventBase.transform;
                    }
                }
            }
            else if ((Event.current.control || Event.current.command) && hasObjectsUnderMouse && !HasStartedDrag && eventType == EventType.MouseUp)
            {
                foreach (var selectableContainer in selectableContainers)
                {
                    var objectsUnderSelection = objectContainerMap[selectableContainer];
                    foreach (var selectedObject in objectsUnderSelection)
                    {
                        if (!selectableContainer.SelectedObjects.Contains(selectedObject))
                        {
                            selectableContainer.OnSelectedObjects(new List <UnityEngine.Object> {
                                selectedObject
                            });
                        }
                        else
                        {
                            selectableContainer.OnDeSelectedObjects(new List <UnityEngine.Object> {
                                selectedObject
                            });
                        }
                    }
                }
            }
            else if (IsDragging && HasStartedDrag)
            {
                DragStartPosition = new Vector2(DragStartPosition.x, DragStartPosition.y);
                var mouseDelta = Event.current.mousePosition - DragStartPosition;

                if (!HasProcessedInitialDrag)
                {
                    foreach (var selectableContainer in selectableContainers)
                    {
                        // if our under mouse isn't currently selected, clear our selection
                        var objectsUnderSelection = objectContainerMap[selectableContainer];
                        if (objectsUnderSelection.Count == 1 && !selectableContainer.SelectedObjects.Contains(objectsUnderSelection[0]) && !Event.current.control && !Event.current.command)
                        {
                            selectableContainer.ResetSelection();
                            EditorGUI.FocusTextInControl("");
                        }
                        selectableContainer.OnSelectedObjects(objectsUnderSelection);
                        selectableContainer.StartDraggingObjects();
                    }

                    HasProcessedInitialDrag = true;
                }

                if (IsDuplicating && !HasDuplicated)
                {
                    foreach (var selectableContainer in selectableContainers)
                    {
                        selectableContainer.DuplicateSelection();
                    }

                    HasDuplicated = true;
                }
                else
                {
                    foreach (var selectableContainer in selectableContainers)
                    {
                        selectableContainer.ProcessDraggingObjects(mouseDelta, Snap, TimeToContentX(SnapAmount));
                    }
                }
            }
            else if (!HasStartedDrag && !hasObjectsUnderMouse && eventType == EventType.MouseUp)
            {
                foreach (var selectableContainer in selectableContainers)
                {
                    selectableContainer.ResetSelection();
                }

                var selectableArea = USHierarchy.VisibleArea;
                if (selectableArea.Contains(Event.current.mousePosition))
                {
                    EditorGUI.FocusTextInControl("");
                }
            }
        }
コード例 #13
0
        private void ContentGUI()
        {
            MaintainHierarchyFor(CurrentSequence);
            using (new Shared.GUIBeginArea(HierarchyArea))
            {
                if (Event.current.type == EventType.ScrollWheel)
                {
                    ScrollInfo.currentScroll.x += Event.current.delta.x;
                    ScrollInfo.currentScroll.y += Event.current.delta.y;

                    var widthOfContent = ScrubArea.x + (CurrentSequence.Duration / ZoomInfo.meaningOfEveryMarker * ZoomInfo.currentXMarkerDist);
                    ScrollInfo.currentScroll.x = Mathf.Clamp(ScrollInfo.currentScroll.x, 0, widthOfContent);

                    UpdateCachedMarkerInformation();

                    Event.current.Use();
                }

                USHierarchy.DoGUI(0);

                var selectableArea = USHierarchy.VisibleArea;
                if (!SequenceWindow.HasOpenPopup)
                {
                    if (selectableArea.Contains(Event.current.mousePosition) || Event.current.rawType == EventType.MouseUp || Event.current.rawType == EventType.MouseDrag)
                    {
                        HandleEvent(Event.current.rawType == EventType.MouseUp ? Event.current.rawType : Event.current.type, Event.current.button, Event.current.mousePosition);
                    }
                }

                // Render our mouse drag box.
                if (IsBoxSelecting && HasStartedDrag)
                {
                    var mousePosition = Event.current.mousePosition;
                    var origin        = DragStartPosition;
                    var destination   = mousePosition;

                    if (mousePosition.x < DragStartPosition.x)
                    {
                        origin.x      = mousePosition.x;
                        destination.x = DragStartPosition.x;
                    }

                    if (mousePosition.y < DragStartPosition.y)
                    {
                        origin.y      = mousePosition.y;
                        destination.y = DragStartPosition.y;
                    }

                    var mouseDelta = destination - origin;
                    SelectionArea = new Rect(origin.x, origin.y, mouseDelta.x, mouseDelta.y);
                    if (!EditorGUIUtility.isProSkin)
                    {
                        GUI.Box(SelectionArea, "", USEditorUtility.USeqSkin.box);
                    }
                    else
                    {
                        GUI.Box(SelectionArea, "");
                    }

                    SequenceWindow.Repaint();
                }
            }
        }
コード例 #14
0
 public void StoreBaseState()
 {
     USHierarchy.StoreBaseState();
 }