void OnSceneGUI()
        {
            USApplyForceEvent forceEvent = target as USApplyForceEvent;

            if (!forceEvent)
            {
                Debug.LogWarning("Trying to render an event as a USApplyForceEvent, but it is a : " + forceEvent.GetType().ToString());
            }

            if (forceEvent.AffectedObject)
            {
                forceEvent.transform.position = forceEvent.AffectedObject.transform.position;
            }

            USUndoManager.BeginChangeCheck();

            Vector3 vPosition = forceEvent.transform.position;

            float   width = HandleUtility.GetHandleSize(vPosition) * HandleLength;
            Vector3 vEnd  = vPosition + (forceEvent.direction * width);

            width = HandleUtility.GetHandleSize(vEnd) * HandleSize;
            vEnd  = Handles.FreeMoveHandle(vEnd, Quaternion.identity, width, Vector3.zero, Handles.CubeCap);

            Vector3 vDifference = vEnd - vPosition;

            vDifference.Normalize();

            // Undo this
            if (USUndoManager.EndChangeCheck())
            {
                USUndoManager.PropertyChange(forceEvent, "Change Force Event Direction");
                forceEvent.direction = vDifference;
            }

            Handles.color = Color.red;
            Handles.DrawLine(vPosition, vEnd);

            if (GUI.changed)
            {
                EditorUtility.SetDirty(forceEvent);
            }
        }
        public override void OnInspectorGUI()
        {
            serializedObject.Update();

            var objectTimelinePaths = new List <USTimelineObjectPath>();

            foreach (var objectTarget in targets)
            {
                var objectTimelinePath = objectTarget as USTimelineObjectPath;
                if (objectTimelinePath != null)
                {
                    objectTimelinePaths.Add(objectTimelinePath);
                }
            }

            EditorGUILayout.HelpBox(string.Format("Object Path for {0}", objectTimelinePaths.Count == 1 ? objectTimelinePaths[0].AffectedObject.name : (string.Format("{0} Objects", objectTimelinePaths.Count))), MessageType.Info);

            if (objectTimelinePaths.Count == 1)
            {
                EditorGUILayout.HelpBox(string.Format("{0} Transform Settings", objectTimelinePaths[0].AffectedObject.name), MessageType.None);

                var objectPath = target as USTimelineObjectPath;

                USUndoManager.BeginChangeCheck();

                var newPosition    = EditorGUILayout.Vector3Field(new GUIContent("Position"), objectPath.AffectedObject.localPosition);
                var newOrientation = EditorGUILayout.Vector3Field(new GUIContent("Rotation"), objectPath.AffectedObject.localRotation.eulerAngles);

                if (USUndoManager.EndChangeCheck())
                {
                    USUndoManager.PropertyChange(objectPath.AffectedObject, string.Format("Alter {0} Orientation", objectTimelinePaths[0].AffectedObject.name));
                    objectPath.AffectedObject.localPosition = newPosition;
                    objectPath.AffectedObject.localRotation = Quaternion.Euler(newOrientation);
                }

                if (GUILayout.Button(string.Format("Select {0}", objectTimelinePaths[0].AffectedObject.name)))
                {
                    Selection.activeGameObject = objectTimelinePaths[0].AffectedObject.gameObject;
                }
            }
            else
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
            }

            if (GUILayout.Button("Orient " + (objectTimelinePaths.Count > 1 ? "Objects" :  objectTimelinePaths[0].AffectedObject.name) + " To First Node"))
            {
                foreach (var objectTimelinePath in objectTimelinePaths)
                {
                    USUndoManager.PropertyChange(objectTimelinePath.AffectedObject, "Orient Object");
                    objectTimelinePath.SetStartingOrientation();
                }
            }

            EditorGUILayout.Space();
            EditorGUILayout.Space();

            EditorGUILayout.HelpBox("Path Settings", MessageType.None);

            EditorGUILayout.PropertyField(easingType, new GUIContent("Easing Mode"));
            EditorGUILayout.PropertyField(splineOrientationMode, new GUIContent("Orientation Mode"));

            if ((SplineOrientationMode)splineOrientationMode.enumValueIndex == SplineOrientationMode.LookAtTransform)
            {
                EditorGUILayout.PropertyField(lookAtTarget, new GUIContent("Look At Target"));
            }

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

            EditorGUILayout.PropertyField(shakeType, new GUIContent("Mode"));

            var shakeTypeEnum = (Shared.ShakeType)shakeType.enumValueIndex;

            if (shakeTypeEnum == Shared.ShakeType.Position || shakeTypeEnum == Shared.ShakeType.Both)
            {
                EditorGUILayout.PropertyField(shakeSpeedPosition, new GUIContent("Speed (Position)"));
                EditorGUILayout.PropertyField(shakeRangePosition, new GUIContent("Delta (Position)"));
            }
            if (shakeTypeEnum == Shared.ShakeType.Rotation || shakeTypeEnum == Shared.ShakeType.Both)
            {
                EditorGUILayout.PropertyField(shakeSpeedRotation, new GUIContent("Speed (Rotation)"));
                EditorGUILayout.PropertyField(shakeRangeRotation, new GUIContent("Delta (Rotation)"));
            }

            if (objectTimelinePaths.Count == 1)
            {
                EditorGUILayout.Space();
                EditorGUILayout.Space();
                EditorGUILayout.HelpBox("Keyframe Settings", MessageType.None);
                keyControls = EditorGUILayout.Foldout(keyControls, "Edit Keyframes directly (beta)");

                if (keyControls)
                {
                    foreach (var keyframe in objectTimelinePaths[0].Keyframes)
                    {
                        using (new Shared.GUIBeginHorizontal())
                        {
                            GUILayout.Label("Keyframe");
                            if (GUILayout.Button("Align to scene camera"))
                            {
                                USUndoManager.PropertyChange(objectTimelinePaths[0], "Align Keyframe");
                                var cameraTransform = SceneView.currentDrawingSceneView.camera.transform;
                                keyframe.Position = cameraTransform.position;
                            }
                        }
                    }
                }
            }

            if (serializedObject.ApplyModifiedProperties())
            {
                var windows = Resources.FindObjectsOfTypeAll <USWindow>();
                foreach (var window in windows)
                {
                    window.ExternalModification();
                }
            }
        }
예제 #3
0
        private void DisplayBottomBar()
        {
            var space = 16.0f;

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

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

            if (CurrentSequence == null)
            {
                return;
            }

            using (new Shared.GUIBeginArea(BottomBar))
            {
                using (new Shared.GUIBeginHorizontal())
                {
                    USUndoManager.BeginChangeCheck();
                    string[] showAllOptions  = { "Show All", "Show Only Animated" };
                    var      selectedShowAll = 0;
                    if (ShowOnlyAnimated)
                    {
                        selectedShowAll = 1;
                    }
                    selectedShowAll = EditorGUILayout.Popup(selectedShowAll, showAllOptions, EditorStyles.toolbarPopup, GUILayout.MaxWidth(120.0f));
                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(this, "Show Animated");
                        if (selectedShowAll == 1)
                        {
                            ShowOnlyAnimated = true;
                        }
                        else
                        {
                            ShowOnlyAnimated = false;
                        }
                    }

                    USUndoManager.BeginChangeCheck();
                    string[] playBackOptions       = { "Playback : Normal", "Playback : Looping", "Playback : PingPong" };
                    var      selectedAnimationType = 0;
                    if (CurrentSequence.IsLopping)
                    {
                        selectedAnimationType = 1;
                    }
                    else if (CurrentSequence.IsPingPonging)
                    {
                        selectedAnimationType = 2;
                    }
                    selectedAnimationType = EditorGUILayout.Popup(selectedAnimationType, playBackOptions, EditorStyles.toolbarPopup, GUILayout.MaxWidth(120.0f));
                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(CurrentSequence, "Playback State");
                        CurrentSequence.IsLopping     = false;
                        CurrentSequence.IsPingPonging = false;
                        if (selectedAnimationType == 1)
                        {
                            CurrentSequence.IsLopping     = true;
                            CurrentSequence.IsPingPonging = false;
                        }
                        else if (selectedAnimationType == 2)
                        {
                            CurrentSequence.IsLopping     = false;
                            CurrentSequence.IsPingPonging = true;
                        }
                    }

                    USUndoManager.BeginChangeCheck();
                    string[] curveAutoTangentModesNames = { "Tangent Mode : None", "Tangent Mode : Smooth", "Tangent Mode : Flatten", "Tangent Mode : RightLinear", "Tangent Mode : RightConstant", "Tangent Mode : LeftLinear", "Tangent Mode : LeftConstant", "Tangent Mode : BothLinear", "Tangent Mode : BothConstant", };
                    var      newAutoTangentMode         = EditorGUILayout.Popup((int)AutoTangentMode, curveAutoTangentModesNames, EditorStyles.toolbarPopup, GUILayout.MaxWidth(150.0f));
                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(this, "AutoTangentMode");
                        AutoTangentMode = (CurveAutoTangentModes)newAutoTangentMode;
                        AnimationCurveEditor.AutoTangentMode = AutoTangentMode;
                    }

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

                    EditorGUILayout.LabelField("", "Running Time", GUILayout.MaxWidth(100.0f));
                    USUndoManager.BeginChangeCheck();
                    var runningTime = EditorGUILayout.FloatField("", CurrentSequence.RunningTime, GUILayout.MaxWidth(50.0f));
                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(CurrentSequence, "Running Time");
                        SetRunningTime(runningTime);
                    }

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

                    EditorGUILayout.LabelField("", "Duration", GUILayout.MaxWidth(50.0f));
                    USUndoManager.BeginChangeCheck();
                    var duration = EditorGUILayout.FloatField("", CurrentSequence.Duration, GUILayout.MaxWidth(50.0f));
                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(CurrentSequence, "Duration");
                        CurrentSequence.Duration = duration;
                        ContentRenderer.UpdateCachedMarkerInformation();
                        ContentRenderer.USHierarchy.ExternalModification();
                    }

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

                    EditorGUILayout.LabelField("", "PlaybackRate", GUILayout.MaxWidth(80.0f));
                    USUndoManager.BeginChangeCheck();
                    var playbackRate = EditorGUILayout.FloatField("", CurrentSequence.PlaybackRate, GUILayout.MaxWidth(50.0f));
                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(CurrentSequence, "PlaybackRate");
                        CurrentSequence.PlaybackRate = playbackRate;
                        ContentRenderer.UpdateCachedMarkerInformation();
                    }

                    GUILayout.FlexibleSpace();
                }
            }
        }
예제 #4
0
        public void OnSceneGUI()
        {
            if (ObjectPathTimeline == null || ObjectPathTimeline.Keyframes == null)
            {
                return;
            }

            if (SelectedNodeIndex >= 0)
            {
                if (Event.current.isKey && (Event.current.keyCode == KeyCode.Delete || Event.current.keyCode == KeyCode.Backspace))
                {
                    USUndoManager.RegisterCompleteObjectUndo(this, "Remove Keyframe");
                    USUndoManager.RegisterCompleteObjectUndo(ObjectPathTimeline, "Remove Keyframe");

                    Event.current.Use();
                    RemoveKeyframeAtIndex(SelectedNodeIndex);
                    SelectedNodeIndex = -1;
                }
            }

            if (Event.current.type == EventType.MouseDown)
            {
                var nearestIndex = GetNearestNodeForMousePosition(Event.current.mousePosition);

                if (nearestIndex != -1)
                {
                    SelectedNodeIndex = nearestIndex;

                    if (Event.current.clickCount > 1)
                    {
                        USUndoManager.PropertyChange(ObjectPathTimeline, "Add Keyframe");

                        var cameraTransform = SceneView.currentDrawingSceneView.camera.transform;

                        var keyframe     = GetKeyframeAtIndex(SelectedNodeIndex);
                        var nextKeyframe = GetKeyframeAtIndex(SelectedNodeIndex + 1);

                        var newKeyframePosition = Vector3.zero;
                        if (keyframe == null)
                        {
                            newKeyframePosition = cameraTransform.position + (cameraTransform.forward * 1.0f);
                        }
                        else
                        {
                            if (SelectedNodeIndex == ObjectPathTimeline.Keyframes.Count - 1)
                            {
                                newKeyframePosition = keyframe.Position + (cameraTransform.up * Vector3.Magnitude(keyframe.Position - cameraTransform.position) * 0.1f);
                            }
                            else
                            {
                                var directionVector = nextKeyframe.Position - keyframe.Position;
                                var halfDistance    = Vector3.Magnitude(directionVector) * 0.5f;
                                directionVector.Normalize();
                                newKeyframePosition = keyframe.Position + (directionVector * halfDistance);
                            }
                        }

                        var translatedKeyframe = CreateInstance <SplineKeyframe>();
                        USUndoManager.RegisterCreatedObjectUndo(translatedKeyframe, "Add Keyframe");
                        translatedKeyframe.Position = newKeyframePosition;

                        ObjectPathTimeline.AddAfterKeyframe(translatedKeyframe, SelectedNodeIndex);
                        GUI.changed = true;
                    }
                }
            }

            if (Vector3.Distance(ObjectPathTimeline.Keyframes[0].Position, ObjectPathTimeline.Keyframes[ObjectPathTimeline.Keyframes.Count - 1].Position) == 0)
            {
                Handles.Label(ObjectPathTimeline.Keyframes[0].Position, "Start and End");
            }
            else
            {
                Handles.Label(ObjectPathTimeline.Keyframes[0].Position, "Start");
                Handles.Label(ObjectPathTimeline.Keyframes[ObjectPathTimeline.Keyframes.Count - 1].Position, "End");
            }

            for (var nodeIndex = 0; nodeIndex < ObjectPathTimeline.Keyframes.Count; nodeIndex++)
            {
                var node = ObjectPathTimeline.Keyframes[nodeIndex];

                if (node && nodeIndex > 0 && nodeIndex < ObjectPathTimeline.Keyframes.Count - 1)
                {
                    var handleSize = HandlesUtility.GetHandleSize(node.Position);
                    Handles.Label(node.Position + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), nodeIndex.ToString());
                }

                using (new HandlesChangeColor(ObjectPathTimeline.PathColor))
                {
                    USUndoManager.BeginChangeCheck();

                    var existingKeyframe = ObjectPathTimeline.Keyframes[nodeIndex];
                    var newPosition      = HandlesUtility.PositionHandle(existingKeyframe.Position, Quaternion.identity);

                    if (USUndoManager.EndChangeCheck())
                    {
                        USUndoManager.PropertyChange(ObjectPathTimeline, "Modify Keyframe");

                        foreach (var keyframe in ObjectPathTimeline.Keyframes)
                        {
                            USUndoManager.PropertyChange(keyframe, "Modify Keyframe");
                        }

                        ObjectPathTimeline.AlterKeyframe(newPosition, nodeIndex);
                        EditorUtility.SetDirty(ObjectPathTimeline);
                    }
                }
            }
        }
예제 #5
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);
                    }
                }
            }
        }