public void Initialize(USEventBase evt)
        {
            Event = evt;

            // Use Reflection to find the Function we require and call it.
            var baseType  = typeof(USEventBaseEditor);
            var foundType = baseType;
            var types     = USEditorUtility.GetAllSubTypes(baseType);

            foreach (var type in types)
            {
                if (type.IsSubclassOf(baseType))
                {
                    foreach (Attribute attr in type.GetCustomAttributes(true))
                    {
                        var eventAttr = attr as CustomUSEditorAttribute;

                        if (eventAttr == null)
                        {
                            continue;
                        }

                        if (eventAttr.InspectedType == Event.GetType())
                        {
                            foundType = type;
                        }
                    }
                }
            }

            eventEditor             = CreateInstance(foundType) as USEventBaseEditor;
            eventEditor.TargetEvent = Event;
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Sequence Settings", MessageType.None);

            EditorGUILayout.PropertyField(updateOnFixedUpdate, new GUIContent("Fixed Update?"));
            EditorGUILayout.PropertyField(autoPlay, new GUIContent("Auto Play?"));

            EditorGUILayout.Space();
            EditorGUILayout.Space();
            EditorGUILayout.HelpBox("Utility", MessageType.None);

            var sequences = new List <USSequencer>();

            foreach (var target in targets)
            {
                var sequence = target as USSequencer;
                if (sequence == null)
                {
                    continue;
                }

                sequences.Add(sequence);
            }

            if (sequences.Count == 1 && GUILayout.Button("Open and Edit Sequence"))
            {
                USWindow.OpenuSequencerWindow();
                Selection.activeObject = sequences[0];
            }

            if (sequences.Count <= 1)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button(sequences.Count > 1 ? "Duplicate Sequences" : "Duplicate Sequence"))
            {
                foreach (var sequence in sequences)
                {
                    USEditorUtility.DuplicateSequence(sequence);
                }
            }

            if (sequences.Count == 1 && GUILayout.Button(PrefabUtility.GetPrefabObject(sequences[0].gameObject) ? "Update Prefab" : "Create Prefab"))
            {
                USEditorUtility.CreatePrefabFrom(sequences[0], false);
            }

            serializedObject.ApplyModifiedProperties();
        }
Exemplo n.º 3
0
        public void ResetSelection()
        {
            if (SelectedObjects.Count > 0)
            {
                USUndoManager.PropertyChange(this, "Select None");

                USEditorUtility.RemoveFromUnitySelection(SelectedObjects);
                SelectedObjects.Clear();
                SourcePositions.Clear();
            }
        }
        public List <UnityEngine.Object> GetSelectableObjectsUnderRect(Rect selectionRect, float yScroll)
        {
            objectsUnderMouse.Clear();

            selectionRect.y += YScroll;

            foreach (var cachedData in cachedClipRenderData)
            {
                if (USEditorUtility.DoRectsOverlap(cachedData.renderRect, selectionRect))
                {
                    objectsUnderMouse.Add(cachedData.animationClipData);
                }
            }

            return(objectsUnderMouse);
        }
        public List <UnityEngine.Object> GetSelectableObjectsUnderRect(Rect selectionRect, float yScroll)
        {
            objectsUnderMouse.Clear();

            foreach (var cachedData in cachedObserverRenderData)
            {
                var renderRect = cachedData.RenderRect;
                renderRect.y -= yScroll;
                if (USEditorUtility.DoRectsOverlap(cachedData.RenderRect, selectionRect))
                {
                    objectsUnderMouse.Add(cachedData.Keyframe);
                }
            }

            return(objectsUnderMouse);
        }
Exemplo n.º 6
0
        private void HandleEvent()
        {
            var isContext = Event.current.type == EventType.MouseDown && Event.current.button == 1;

            if (!isContext)
            {
                return;
            }

            var contextMenu = new GenericMenu();

            foreach (var data in cachedEventRenderData)
            {
                if (data.RenderRect.Contains(Event.current.mousePosition))
                {
                    contextMenu.AddItem(new GUIContent("Remove Event"), false, () => { RemoveEvent(data.Event); });
                    contextMenu.AddSeparator("");
                    break;
                }
            }

            if (DisplayArea.Contains(Event.current.mousePosition))
            {
                var baseAdd = "Add Event/";
                var newTime = (((Event.current.mousePosition.x + XScroll - DisplayArea.x) / DisplayArea.width) * Duration) / XScale;

                var baseType = typeof(USEventBase);
                var types    = USEditorUtility.GetAllSubTypes(baseType).Where(type => type.IsSubclassOf(baseType));
                foreach (var type in types)
                {
                    var fullAdd          = baseAdd;
                    var customAttributes = type.GetCustomAttributes(true).Where(attr => attr is USequencerEventAttribute).Cast <USequencerEventAttribute>();
                    foreach (var customAttribute in customAttributes)
                    {
                        fullAdd += customAttribute.EventPath;
                    }

                    contextMenu.AddItem(new GUIContent(fullAdd), false, (obj) => AddEvent(newTime, (Type)obj), (object)type);
                }
            }

            if (DisplayArea.Contains(Event.current.mousePosition))
            {
                Event.current.Use();
                contextMenu.ShowAsContext();
            }
        }
Exemplo n.º 7
0
        public List <UnityEngine.Object> GetSelectableObjectsUnderRect(Rect selectionRect, float yScroll)
        {
            var selectableObjects = new List <UnityEngine.Object>();

            foreach (var kvp in cachedKeyframePositions)
            {
                var FinalRenderPosition = kvp.Value.RenderPosition;
                FinalRenderPosition.x  = (FinalRenderPosition.x * XScale) - XScroll;
                FinalRenderPosition.y -= yScroll;
                var keyframeRect = new Rect(FinalRenderPosition.x - 6, FinalRenderPosition.y - 6, 16, 16);
                keyframeRect.x += DisplayArea.x;
                keyframeRect.y += DisplayArea.y;

                if (USEditorUtility.DoRectsOverlap(keyframeRect, selectionRect))
                {
                    selectableObjects.Add(kvp.Key);
                }
            }

            return(selectableObjects);
        }
Exemplo n.º 8
0
        public List <UnityEngine.Object> GetSelectableObjectUnderPos(Vector2 mousePosition)
        {
            var selectableObjects    = new List <UnityEngine.Object>();
            var selectableRenderData = new Dictionary <UnityEngine.Object, AnimationKeyframeRenderData>();

            foreach (var kvp in cachedKeyframePositions)
            {
                if (kvp.Value.IsMouseOverKeyframe)
                {
                    selectableRenderData[kvp.Key] = kvp.Value;
                }
            }

            foreach (var kvp in selectableRenderData)
            {
                var canAdd = true;
                for (var selectedObjectIndex = selectableObjects.Count - 1; selectedObjectIndex >= 0; selectedObjectIndex--)
                {
                    var selectedObject = selectableObjects[selectedObjectIndex];
                    if (USEditorUtility.DoRectsOverlap(kvp.Value.RenderRect, selectableRenderData[selectedObject].RenderRect))
                    {
                        if (Vector2.Distance(kvp.Value.RenderPosition, mousePosition) < Vector2.Distance(selectableRenderData[selectedObject].RenderPosition, mousePosition))
                        {
                            selectableObjects.Remove(selectedObject);
                        }
                        else
                        {
                            canAdd = false;
                        }
                    }
                }

                if (canAdd)
                {
                    selectableObjects.Add(kvp.Key);
                }
            }

            return(selectableObjects);
        }
        private void FloatingOnGUI()
        {
            GUILayout.Box("", FloatingBackground, GUILayout.MaxWidth(FloatingWidth), GUILayout.Height(17.0f));

            if (Event.current.type == EventType.Repaint)
            {
                FloatingBackgroundRect = GUILayoutUtility.GetLastRect();
            }

            bool wasLabelPressed;
            var  newExpandedState = USEditor.FoldoutLabel(FloatingBackgroundRect, IsExpanded, USEditorUtility.GetReadableTimelineContainerName(TimelineContainer), out wasLabelPressed);

            if (newExpandedState != IsExpanded)
            {
                USUndoManager.PropertyChange(this, "Foldout");
                IsExpanded = newExpandedState;
            }

            base.FloatingOnGUI(0);

            if (!USRuntimeUtility.HasObserverTimeline(TimelineContainer.transform) && TimelineContainer.AffectedObject == null)
            {
                IsExpanded = false;
            }
        }
Exemplo n.º 10
0
        private void OnItemContextClicked(IUSHierarchyItem item)
        {
            var timelineContainerItem = item as USTimelineContainerHierarchyItem;
            var timelineHierarchyItem = item as IUSTimelineHierarchyItem;
            var contextMenu           = new GenericMenu();

            var canContextClickTimelineContainer = !timelineContainerItem || USEditorUtility.CanContextClickTimelineContainer(timelineContainerItem.TimelineContainer);

            if (!canContextClickTimelineContainer)
            {
                return;
            }

            var canContextClickTimeline = !timelineHierarchyItem || USEditorUtility.CanContextClickTimeline(timelineHierarchyItem.BaseTimeline);

            if (!canContextClickTimeline)
            {
                return;
            }

            if (timelineHierarchyItem || timelineContainerItem)
            {
                contextMenu.AddItem(new GUIContent("Remove"), false, () => ProcessDelete(item));
            }

            // if we context click on a hierarchy container, always allow the duplication
            var isDuplicateEnabled = timelineContainerItem != null ? true :false;

            // If we context click on a hierarchy item, we need to make sure we can duplicate that item.
            if (timelineHierarchyItem)
            {
                var customAttribute = timelineHierarchyItem.GetType().GetCustomAttributes(typeof(USCustomTimelineHierarchyItem), true).FirstOrDefault() as USCustomTimelineHierarchyItem;
                if (customAttribute != default(USCustomTimelineHierarchyItem))
                {
                    if (customAttribute.CanBeManuallyAddToSequence && customAttribute.MaxNumberPerSequence > 1)
                    {
                        isDuplicateEnabled = true;
                    }
                }
                else
                {
                    isDuplicateEnabled = true;
                }
            }

            if (isDuplicateEnabled)
            {
                contextMenu.AddSeparator("Copy To/This Sequence");
                contextMenu.AddItem(new GUIContent("Copy To/Duplicate"), false, () => ProcessDuplicate(item));
                contextMenu.AddSeparator("Copy To/Other Sequences");
            }
            else
            {
                contextMenu.AddDisabledItem(new GUIContent("Copy To/This Sequence"));
            }

            var sequences        = FindObjectsOfType(typeof(USSequencer)) as USSequencer[];
            var orderedSequences = sequences.OrderBy(sequence => sequence.name).Where(sequence => sequence != CurrentSequence);

            foreach (var sequence in orderedSequences)
            {
                contextMenu.AddItem(new GUIContent(string.Format("{0}/{1}", "Copy To", sequence.name)),
                                    false,
                                    (obj) => ProcessDuplicateToSequence(item, (USSequencer)obj),
                                    sequence);
            }

            if (timelineContainerItem)
            {
                var customKeyValuePairs = USEditorUtility.CustomTimelineAttributes;
                foreach (var customKeyValuePair in customKeyValuePairs)
                {
                    var customTimelineDescription = customKeyValuePair.Key;

                    if (!customTimelineDescription.CanBeManuallyAddToSequence)
                    {
                        continue;
                    }

                    if (USRuntimeUtility.GetNumberOfTimelinesOfType(customTimelineDescription.InspectedType, timelineContainerItem.TimelineContainer) >= customTimelineDescription.MaxNumberPerSequence)
                    {
                        continue;
                    }

                    contextMenu.AddItem(
                        new GUIContent(string.Format("Add Timeline/{0}", customTimelineDescription.FriendlyName)),
                        false,
                        (obj) => { AddNewTimeline((obj as object[])[0] as USTimelineContainerHierarchyItem, (obj as object[])[1] as USCustomTimelineHierarchyItem); },
                        new object[] { timelineContainerItem, customTimelineDescription }
                        );
                }
            }

            item.AddContextItems(contextMenu);

            if (timelineContainerItem != null &&
                (timelineContainerItem.TimelineContainer.AffectedObject == null ||
                 (Selection.activeGameObject != null &&
                  Selection.activeObject != timelineContainerItem.TimelineContainer.AffectedObject.gameObject)))
            {
                if (Selection.activeGameObject != null)
                {
                    contextMenu.AddItem(
                        new GUIContent(string.Format("Update Affected Object : {0}", Selection.activeGameObject.name)),
                        false,
                        () => UpdateAffectedObject(timelineContainerItem, Selection.activeGameObject));
                }
            }


            contextMenu.ShowAsContext();
        }
Exemplo n.º 11
0
 private void GoToPrevKeyframe()
 {
     SetRunningTime(USEditorUtility.FindPrevVisibleKeyframeTime(ContentRenderer.USHierarchy, CurrentSequence));
 }
Exemplo n.º 12
0
        private void DisplayTopBar()
        {
            var space = 16.0f;

            GUILayout.Box("", EditorStyles.toolbar, GUILayout.ExpandWidth(true), GUILayout.Height(18.0f));

            if (Event.current.type == EventType.Repaint)
            {
                TopBar = GUILayoutUtility.GetLastRect();
            }

            using (new Shared.GUIBeginArea(TopBar))
            {
                using (new Shared.GUIBeginHorizontal())
                {
                    if (GUILayout.Button("Create New Sequence", EditorStyles.toolbarButton))
                    {
                        var newSequence = new GameObject("Sequence");
                        USUndoManager.RegisterCreatedObjectUndo(newSequence, "Create new sequence");

                        var sequence = newSequence.AddComponent <USSequencer>();
                        sequence.Version = USUpgradePaths.CurrentVersionNumber;
                        USUndoManager.RegisterCreatedObjectUndo(sequence, "Create new sequence");

                        USUndoManager.RegisterCompleteObjectUndo(newSequence, "Create new sequence");
                        USRuntimeUtility.CreateAndAttachObserver(sequence);

                        if (CurrentSequence == null)
                        {
                            Selection.activeGameObject = newSequence;
                            Selection.activeTransform  = newSequence.transform;
                            SequenceSwitch(sequence);
                        }

                        Repaint();
                    }

                    var currentSequence = CurrentSequence != null ? CurrentSequence.name : "";
                    var label           = "Select a Sequence";
                    if (CurrentSequence != null)
                    {
                        label = String.Format("Editting : {0}", currentSequence);
                    }
                    if (GUILayout.Button(label, EditorStyles.toolbarButton, GUILayout.Width(150.0f)))
                    {
                        var menu             = new GenericMenu();
                        var sequences        = FindObjectsOfType(typeof(USSequencer)) as USSequencer[];
                        var orderedSequences = sequences.OrderBy(sequence => sequence.name);
                        foreach (var sequence in orderedSequences)
                        {
                            menu.AddItem(new GUIContent(sequence.name),
                                         currentSequence == sequence.name ? true : false,
                                         (obj) => Selection.activeGameObject = (GameObject)obj,
                                         sequence.gameObject);
                        }
                        menu.ShowAsContext();
                    }

                    GUILayout.Space(space);
                    GUILayout.Box("", USEditorUtility.SeperatorStyle, GUILayout.Height(18.0f));
                    GUILayout.Space(space);

                    if (CurrentSequence != null)
                    {
                        using (new Shared.GUIChangeColor((AnimationHelper.IsInAnimationMode || IsArmed) ? Color.red : GUI.color))
                        {
                            if (GUILayout.Button(new GUIContent(!CurrentSequence.IsPlaying ? USEditorUtility.PlayButton : USEditorUtility.PauseButton, "Toggle Play Mode (P)"), USEditorUtility.ToolbarButtonSmall))
                            {
                                PlayOrPause();
                            }

                            if (GUILayout.Button(USEditorUtility.StopButton, USEditorUtility.ToolbarButtonSmall))
                            {
                                Stop();
                            }
                        }
                        using (new Shared.GUIEnable(EditorApplication.isPlaying))
                        {
                            var buttonContent = new GUIContent(USEditorUtility.RecordButton, !EditorApplication.isPlaying ? "You must be in Play Mode to enable this button" : "Start g");
                            if (GUILayout.Button(buttonContent, USEditorUtility.ToolbarButtonSmall))
                            {
                                Record();
                            }
                        }

                        GUILayout.Space(space);

                        USUndoManager.BeginChangeCheck();
                        GUILayout.Button(new GUIContent(USEditorUtility.PrevKeyframeButton, "Prev Keyframe (Alt + ,)"), USEditorUtility.ToolbarButtonSmall);
                        if (USUndoManager.EndChangeCheck())
                        {
                            USUndoManager.PropertyChange(this, "Previous Keyframe");
                            GoToPrevKeyframe();
                        }

                        USUndoManager.BeginChangeCheck();
                        GUILayout.Button(new GUIContent(USEditorUtility.NextKeyframeButton, "Next Keyframe (Alt + .)"), USEditorUtility.ToolbarButtonSmall);
                        if (USUndoManager.EndChangeCheck())
                        {
                            USUndoManager.PropertyChange(this, "Next Keyframe");
                            GoToNextKeyframe();
                        }

                        GUILayout.Space(space);
                        GUILayout.Box("", USEditorUtility.SeperatorStyle, GUILayout.Height(18.0f));
                        GUILayout.Space(space);

                        EditorGUILayout.LabelField(new GUIContent("Keyframe Snap", "The amount keyframes will snap to when dragged in the uSequencer window. (Left Shift to activate)"), GUILayout.MaxWidth(100.0f));
                        USUndoManager.BeginChangeCheck();
                        var snapAmount = EditorGUILayout.FloatField(new GUIContent("", "The amount keyframes will snap to when dragged in the uSequencer window. (Left Shift to activate)"), ContentRenderer.SnapAmount, GUILayout.MaxWidth(40.0f));
                        if (USUndoManager.EndChangeCheck())
                        {
                            USUndoManager.PropertyChange(this, "Snap Amount");
                            ContentRenderer.SnapAmount = snapAmount;
                        }

                        GUILayout.Space(space);
                        GUILayout.Box("", USEditorUtility.SeperatorStyle, GUILayout.Height(18.0f));
                        GUILayout.Space(space);
                    }

                    GUILayout.FlexibleSpace();

                    if (CurrentSequence && GUILayout.Button("Duplicate Sequence", EditorStyles.toolbarButton))
                    {
                        USEditorUtility.DuplicateSequence(CurrentSequence);
                    }

                    if (CurrentSequence && GUILayout.Button(PrefabUtility.GetPrefabObject(CurrentSequence.gameObject) ? "Update Prefab" : "Create Prefab", EditorStyles.toolbarButton))
                    {
                        CurrentSequence.Stop();
                        StopProcessingAnimationMode();
                        USEditorUtility.CreatePrefabFrom(CurrentSequence, false);
                    }
                }
            }
        }