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; } }
public void ProcessDraggingObjects(Vector2 mouseDelta, bool snap, float snapValue) { if (!ObjectPathTimeline) { return; } USUndoManager.PropertyChange(ObjectPathTimeline, "Drag Selection"); USUndoManager.PropertyChange(this, "Drag Selection"); foreach (var selectedObject in SelectedObjects) { var keyframe = selectedObject as SplineKeyframe; Vector3 newPosition = SourcePositions[keyframe] + mouseDelta; newPosition.x = newPosition.x + XScroll - DisplayArea.x; if (snap) { newPosition.x = Mathf.Round(newPosition.x / snapValue) * snapValue; } var newTime = ((newPosition.x / DisplayArea.width) * Duration) / XScale; newTime = Mathf.Clamp(newTime, 0.0f, Duration); if (ObjectPathTimeline.ObjectSpline.Nodes[0] == keyframe) { ObjectPathTimeline.StartTime = newTime; } if (ObjectPathTimeline.ObjectSpline.Nodes[ObjectPathTimeline.ObjectSpline.Nodes.Count - 1] == keyframe) { ObjectPathTimeline.EndTime = newTime; } } ObjectPathTimeline.Process(ObjectPathTimeline.Sequence.RunningTime, ObjectPathTimeline.Sequence.PlaybackRate); }
public override void DoGUI(int depth) { using (new Shared.GUIBeginHorizontal()) { FloatingOnGUI(depth); EventEditor.Duration = EventTimeline.Sequence.Duration; EventEditor.XScale = XScale; EventEditor.XScroll = XScroll; EventEditor.YScroll = YScroll; if (IsExpanded) { EventEditor.OnGUI(); } else { EventEditor.OnCollapsedGUI(); } GUI.Box(FloatingBackgroundRect, "", FloatingBackground); var wasLabelPressed = false; var newExpandedState = USEditor.FoldoutLabel(FloatingBackgroundRect, IsExpanded, EventTimeline.name, out wasLabelPressed); if (newExpandedState != IsExpanded) { USUndoManager.PropertyChange(this, "Foldout"); IsExpanded = newExpandedState; EditorWindow.Repaint(); } base.FloatingOnGUI(depth, MoreRect); } }
protected override void FloatingOnGUI(int depth) { GUILayout.Box("", FloatingBackground, GUILayout.MaxWidth(FloatingWidth), GUILayout.Height(17.0f)); if (Event.current.type == EventType.Repaint) { var lastRect = GUILayoutUtility.GetLastRect(); lastRect.x += GetXOffsetForDepth(depth); lastRect.width -= GetXOffsetForDepth(depth); if (FloatingBackgroundRect != lastRect) { EditorWindow.Repaint(); FloatingBackgroundRect = lastRect; } } var wasLabelPressed = false; var newExpandedState = USEditor.FoldoutLabel(FloatingBackgroundRect, IsExpanded, AnimationTimeline.name, out wasLabelPressed); if (newExpandedState != IsExpanded) { USUndoManager.PropertyChange(this, "Foldout"); IsExpanded = newExpandedState; EditorWindow.Repaint(); } base.FloatingOnGUI(depth); }
protected override void FloatingOnGUI(int depth) { GUILayout.Box("", FloatingBackground, GUILayout.Width(FloatingWidth), GUILayout.Height(17.0f)); if (Event.current.type == EventType.Repaint) { var lastRect = GUILayoutUtility.GetLastRect(); lastRect.x += GetXOffsetForDepth(depth); lastRect.width -= GetXOffsetForDepth(depth); FloatingBackgroundRect = lastRect; } if (Component == null) { var missingRect = FloatingBackgroundRect; missingRect.x += GetXOffsetForDepth(2); GUI.Label(missingRect, "*Missing*"); IsExpanded = false; return; } var wasLabelPressed = false; var displayableContent = new GUIContent(Component.GetType().Name, EditorGUIUtility.ObjectContent(Component, Component.GetType()).image); var newExpandedState = USEditor.FoldoutLabel(FloatingBackgroundRect, IsExpanded, displayableContent, out wasLabelPressed); if (newExpandedState != IsExpanded) { USUndoManager.PropertyChange(this, "Foldout"); IsExpanded = newExpandedState; } }
public void ProcessDraggingObjects(Vector2 mouseDelta, bool snap, float snapValue) { if (!ObserverTimeline) { return; } USUndoManager.PropertyChange(this, "Drag Selection"); foreach (var selectedObject in SelectedObjects) { var keyframe = selectedObject as USObserverKeyframe; USUndoManager.PropertyChange(keyframe, "Drag Selection"); Vector3 newPosition = SourcePositions[keyframe] + mouseDelta; newPosition.x = newPosition.x + XScroll - DisplayArea.x; if (snap) { newPosition.x = Mathf.Round(newPosition.x / snapValue) * snapValue; } var newTime = ((newPosition.x / DisplayArea.width) * Duration) / XScale; newTime = Mathf.Clamp(newTime, 0.0f, Duration); keyframe.FireTime = newTime; } if (AnimationHelper.IsInAnimationMode) { ObserverTimeline.Process(ObserverTimeline.Sequence.RunningTime, ObserverTimeline.Sequence.PlaybackRate); } }
private void SetCamera(USObserverKeyframe keyframe, float time, Shared.TypeOfTransition transitionType, float transitionDuration, Camera camera) { if (AnimationHelper.IsInAnimationMode) { ObserverTimeline.StopTimeline(); ObserverTimeline.StartTimeline(); } if (keyframe != null) { USUndoManager.PropertyChange(keyframe, "Set Camera"); keyframe.KeyframeCamera = camera; } else { USUndoManager.RegisterCompleteObjectUndo(this, "Set Camera"); var newKeyframe = CreateInstance <USObserverKeyframe>(); newKeyframe.FireTime = time; newKeyframe.KeyframeCamera = camera; newKeyframe.TransitionType = transitionType; newKeyframe.TransitionDuration = transitionDuration; USUndoManager.RegisterCreatedObjectUndo(newKeyframe, "Set Camera"); USUndoManager.RegisterCompleteObjectUndo(ObserverTimeline, "Set Camera"); ObserverTimeline.AddKeyframe(newKeyframe); var cachedData = CreateInstance <ObserverRenderData>(); cachedData.Keyframe = newKeyframe; cachedObserverRenderData.Add(cachedData); } ObserverTimeline.Process(ObserverTimeline.Sequence.RunningTime, ObserverTimeline.Sequence.PlaybackRate); }
public void ResetSelection() { if (SelectedObjects.Count > 0) { USUndoManager.PropertyChange(this, "Select None"); USEditorUtility.RemoveFromUnitySelection(SelectedObjects); SelectedObjects.Clear(); SourcePositions.Clear(); } }
public override void DoGUI(int depth) { GUILayout.Box("", FloatingBackground, GUILayout.Width(FloatingWidth), GUILayout.Height(17.0f)); if (Event.current.type == EventType.Repaint) { IsSelected = Children.Any(element => ((USPropertyMemberHierarchyItem)element).IsSelected); var lastRect = GUILayoutUtility.GetLastRect(); lastRect.x += GetXOffsetForDepth(depth); lastRect.width -= GetXOffsetForDepth(depth); FloatingBackgroundRect = lastRect; } if (IsSelected) { GUI.Box(new Rect(0, FloatingBackgroundRect.y, FloatingBackgroundRect.width + FloatingBackgroundRect.x, FloatingBackgroundRect.height), ""); } var newExpandedState = IsExpanded; bool wasLabelPressed; newExpandedState = USEditor.FoldoutLabel(FloatingBackgroundRect, IsExpanded, PropertyFieldInfo.ReadableName, out wasLabelPressed); if (newExpandedState != IsExpanded) { USUndoManager.PropertyChange(this, "Foldout"); IsExpanded = newExpandedState; } var addRect = FloatingBackgroundRect; var padding = 1.0f; var addWidth = 22.0f; addRect.x = addRect.x + addRect.width - addWidth - padding; addRect.width = addWidth; if (!HasChildCurves) { if (GUI.Button(addRect, "+")) { AddProperty(); } } else { using (new Shared.GUIChangeColor(Color.red)) { if (GUI.Button(addRect, "-")) { RemoveProperty(); } } } }
public void OnDeSelectedObjects(List <UnityEngine.Object> selectedObjects) { USUndoManager.PropertyChange(this, "DeSelect"); foreach (var selectedObject in selectedObjects) { SelectedObjects.Remove(selectedObject); var selection = Selection.objects != null?Selection.objects.ToList() : new List <UnityEngine.Object>(); selection.Remove(selectedObject); Selection.objects = selection.ToArray(); } }
public void SetRunningTime(float newRunningTime) { StartProcessingAnimationMode(); if (!CurrentSequence.IsPlaying) { CurrentSequence.Play(); } CurrentSequence.Pause(); USUndoManager.PropertyChange(CurrentSequence, "Set Running Time"); CurrentSequence.RunningTime = newRunningTime; }
public void OnSelectedObjects(List <UnityEngine.Object> selectedObjects) { USUndoManager.PropertyChange(this, "Select"); foreach (var selectedObject in selectedObjects) { if (!SelectedObjects.Contains(selectedObject)) { SelectedObjects.Add(selectedObject); var selection = Selection.objects != null?Selection.objects.ToList() : new List <UnityEngine.Object>(); selection.Add(selectedObject); Selection.objects = selection.ToArray(); } } }
private void RemoveKeyframe(USObserverKeyframe keyframe) { USUndoManager.RegisterCompleteObjectUndo(this, "Remove Keyframe"); var data = cachedObserverRenderData.Where(element => element.Keyframe == keyframe).First(); cachedObserverRenderData.Remove(data); USUndoManager.PropertyChange(ObserverTimeline, "Remove Keyframe"); ObserverTimeline.RemoveKeyframe(keyframe); ObserverTimeline.Process(ObserverTimeline.Sequence.RunningTime, ObserverTimeline.Sequence.PlaybackRate); USUndoManager.DestroyImmediate(data); USUndoManager.DestroyImmediate(keyframe); }
public void AddKeyframe(USInternalKeyframe internalKeyframe, USInternalCurve curve) { USUndoManager.PropertyChange(curve, "Add Keyframe"); curve.Keys.Add(internalKeyframe); if (Duration < internalKeyframe.Time) { Duration = internalKeyframe.Time; } curve.Keys.Sort(USInternalCurve.KeyframeComparer); curve.BuildAnimationCurveFromInternalCurve(); RebuildCachedCurveInformation(); AreCurvesDirty = true; }
private void AddProperty() { var usPropertyInfo = CreateInstance <USPropertyInfo>(); USUndoManager.RegisterCreatedObjectUndo(usPropertyInfo, "Add Curve"); USUndoManager.PropertyChange(PropertyTimeline, "Add Curve"); USUndoManager.PropertyChange(this, "Add Curve"); foreach (var child in Children) { USUndoManager.PropertyChange(child, "Add Curve"); } object propertyValue = null; usPropertyInfo.Component = PropertyFieldInfo.Component; if (PropertyFieldInfo.Property != null) { usPropertyInfo.propertyInfo = PropertyFieldInfo.Property; propertyValue = PropertyFieldInfo.Property.GetValue(PropertyFieldInfo.Component, null); } else if (PropertyFieldInfo.Field != null) { usPropertyInfo.fieldInfo = PropertyFieldInfo.Field; propertyValue = PropertyFieldInfo.Field.GetValue(PropertyFieldInfo.Component); } usPropertyInfo.InternalName = MappedType; usPropertyInfo.CreatePropertyInfo(USPropertyInfo.GetMappedType(propertyValue.GetType())); usPropertyInfo.AddKeyframe(propertyValue, 0.0f, CurveAutoTangentModes.None); usPropertyInfo.AddKeyframe(propertyValue, PropertyTimeline.Sequence.Duration, CurveAutoTangentModes.None); PropertyTimeline.AddProperty(usPropertyInfo); for (var curveIndex = 0; curveIndex < usPropertyInfo.curves.Count; curveIndex++) { ((USPropertyMemberHierarchyItem)Children[curveIndex]).Curve = usPropertyInfo.curves[curveIndex]; } usPropertyInfo.StoreBaseState(); IsSelected = true; foreach (var child in Children) { ((USPropertyMemberHierarchyItem)child).IsSelected = true; } }
public void ProcessDraggingObjects(Vector2 mouseDelta, bool snap, float snapValue) { USUndoManager.PropertyChange(this, "Drag Selection"); foreach (var selectedObject in SelectedObjects) { var eventBase = selectedObject as USEventBase; USUndoManager.PropertyChange(eventBase, "Drag Selection"); Vector3 newPosition = SourcePositions[eventBase] + mouseDelta; newPosition.x = newPosition.x + XScroll - DisplayArea.x; if (snap) { newPosition.x = Mathf.Round(newPosition.x / snapValue) * snapValue; } var newTime = ((newPosition.x / DisplayArea.width) * Duration) / XScale; eventBase.FireTime = newTime; } }
private void RemoveProperty(PropertyBox propertyBox) { Debug.Log("Removing Property " + propertyBox); USUndoManager.RegisterCompleteObjectUndo(PropertyTimeline, "Remove Curve"); USUndoManager.RegisterCompleteObjectUndo(this, "Remove Curve"); USUndoManager.PropertyChange(CurveEditor, "Add Curve"); propertyBoxes.Remove(propertyBox); var preFix = propertyBox.PropertyName; var propertyInfo = PropertyTimeline.GetProperty(preFix, propertyBox.Component); propertyInfo.curves.ForEach(curve => CurveEditor.Curves.Remove(curve)); propertyInfo.RestoreBaseState(); PropertyTimeline.RemoveProperty(propertyInfo); USUndoManager.DestroyImmediate(propertyInfo); }
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 void ProcessDraggingObjects(Vector2 mouseDelta, bool snap, float snapValue) { USUndoManager.PropertyChange(this, "Drag Selection"); foreach (var selectedObject in SelectedObjects) { var animationClipData = selectedObject as AnimationClipData; USUndoManager.PropertyChange(animationClipData, "Drag Selection"); Vector3 newPosition = SourcePositions[animationClipData] + mouseDelta; newPosition.x = newPosition.x + XScroll - DisplayArea.x; if (snap) { newPosition.x = Mathf.Round(newPosition.x / snapValue) * snapValue; } var newTime = ((newPosition.x / DisplayArea.width) * AnimationTimeline.Sequence.Duration) / XScale; newTime = Mathf.Clamp(newTime, 0.0f, AnimationTimeline.Sequence.Duration); animationClipData.StartTime = newTime; } }
public void AddNewTimeline(USTimelineContainerHierarchyItem hierarchyItem, USCustomTimelineHierarchyItem timelineAttribute) { var timelineObject = new GameObject(timelineAttribute.FriendlyName); USUndoManager.RegisterCreatedObjectUndo(timelineObject, "Add New Timeline"); timelineObject.transform.parent = hierarchyItem.TimelineContainer.transform; timelineObject.transform.position = Vector3.zero; timelineObject.transform.rotation = Quaternion.identity; var timeline = timelineObject.AddComponent(timelineAttribute.InspectedType) as USTimelineBase; USUndoManager.RegisterCreatedObjectUndo(timeline, "Add New Timeline"); USUndoManager.PropertyChange(hierarchyItem.TimelineContainer.Sequence, "Add New Timeline"); hierarchyItem.TimelineContainer.Sequence.ResetCachedData(); USUndoManager.RegisterCompleteObjectUndo(hierarchyItem, "Add New Timeline"); hierarchyItem.AddTimeline(timeline); }
private void PlayOrPause() { if (!CurrentSequence) { return; } if (CurrentSequence.IsPlaying) { CurrentSequence.Pause(); if (isArmed && GetOrSpawnRecorder()) { GetOrSpawnRecorder().PauseRecording(); } } else { USUndoManager.PropertyChange(CurrentSequence, "Play"); if (isArmed && !System.IO.Directory.Exists(USRecordRuntimePreferences.CapturePath)) { EditorUtility.DisplayDialog("Error", String.Format("Recording Directory : {0} doesn't exist, make sure you set one up in the uSequencer preferences (Edit/uSeqeucer/Recording Preferences)", USRecordRuntimePreferences.CapturePath), "OK"); return; } StartProcessingAnimationMode(); CurrentSequence.Play(); if (isArmed && GetOrSpawnRecorder()) { var recordingSequence = GetOrSpawnRecorder(); recordingSequence.StartRecording(); recordingSequence.CapturePath = USRecordRuntimePreferences.CapturePath; recordingSequence.CaptureFrameRate = USRecord.GetFramerate(); recordingSequence.UpscaleAmount = USRecord.GetUpscaleAmount(); } } }
private void Stop() { if (!CurrentSequence) { return; } USUndoManager.PropertyChange(CurrentSequence, "Stop"); CurrentSequence.Stop(); StopProcessingAnimationMode(); if (isArmed) { if (GetOrSpawnRecorder()) { GetOrSpawnRecorder().StopRecording(); } DestroyImmediate(GetOrSpawnRecorder().gameObject); } isArmed = false; }
public void ProcessDraggingObjects(Vector2 mouseDelta, bool snap, float snapValue) { USUndoManager.PropertyChange(this, "Drag Selection"); AreCurvesDirty = true; mouseDelta.x /= XScale; foreach (var selectedObject in SelectedObjects) { var keyframe = selectedObject as USInternalKeyframe; USUndoManager.PropertyChange(keyframe, "Drag Selection"); USUndoManager.PropertyChange(keyframe.curve, "Drag Selection"); Vector3 newPosition; if (snap) { var sourcePosition = SourcePositions[keyframe]; sourcePosition.x = Mathf.Round(sourcePosition.x / snapValue) * snapValue; mouseDelta.x = Mathf.Round(mouseDelta.x / snapValue) * snapValue; newPosition = sourcePosition + mouseDelta; } else { newPosition = SourcePositions[keyframe] + mouseDelta; } var newTime = (newPosition.x / DisplayArea.width) * Duration; newTime = Mathf.Clamp(newTime, 0.0f, Duration); keyframe.Time = newTime; var mouseDeltaY = -1.0f * (newPosition.y - DisplayArea.height); var keyframeRatio = mouseDeltaY / DisplayArea.height; var modifyingOnlyXAxis = false; if (Event.current.alt) { modifyingOnlyXAxis = true; } if (!modifyingOnlyXAxis) { keyframe.Value = (keyframeRatio * (MaxDisplayY - MinDisplayY)) + MinDisplayY; } var curve = keyframe.curve; var keyframeIndex = curve.Keys.ToList().FindIndex(element => element == keyframe); if (keyframeIndex > 0) { RebuildCachedKeyframeInformation(curve.Keys[keyframeIndex - 1]); } if (keyframeIndex > 1) { RebuildCachedKeyframeInformation(curve.Keys[keyframeIndex - 2]); } if (keyframeIndex < curve.Keys.Count() - 1) { RebuildCachedKeyframeInformation(curve.Keys[keyframeIndex + 1]); } if (keyframeIndex < curve.Keys.Count() - 2) { RebuildCachedKeyframeInformation(curve.Keys[keyframeIndex + 2]); } RebuildCachedKeyframeInformation(keyframe); } }
public void FlattenKeyframe(USInternalKeyframe keyframe) { USUndoManager.PropertyChange(keyframe, "Flatten Keyframe"); keyframe.Flatten(); }
public void RemoveKeyframe(USInternalKeyframe keyframe) { USUndoManager.PropertyChange(keyframe.curve, "Remove Keyframe"); keyframe.curve.RemoveKeyframe(keyframe); }
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); } } } }
private void SelectTangent(AnimationKeyframeRenderData keyframeRenderData, int tangentIndex) { USUndoManager.PropertyChange(this, "Select Tangent"); SelectedTangent = tangentIndex; Event.current.Use(); }
private void DragTangent(AnimationKeyframeRenderData keyframeRenderData, int tangentIndex) { AreCurvesDirty = true; var keyframe = SelectedObjects[0] as USInternalKeyframe; USUndoManager.PropertyChange(keyframe, "Alter keyframe"); Vector3 direction = (Event.current.mousePosition - keyframeRenderData.RenderPosition).normalized; var ratio = DisplayArea.height / DisplayArea.width; direction.y = direction.y / ratio; direction.Normalize(); var needsFlip = direction.y > 0.0f; var angle = Vector2.Angle(Vector2.right, direction); if (SelectedTangent == 1 && angle >= 90.0f) { angle = 90.0f; } if (SelectedTangent == 0 && angle <= 90.0f) { angle = 90.0f; } angle = Mathf.Deg2Rad * angle; angle = Mathf.Tan(angle); if (needsFlip) { angle = -1.0f * angle; } if (angle > 10000.0f || angle < -10000.0f) { angle = Mathf.Infinity; } if (!keyframe.BrokenTangents) { if (SelectedTangent == 0) { keyframe.InTangent = angle; keyframe.OutTangent = angle; } if (SelectedTangent == 1) { keyframe.OutTangent = angle; keyframe.InTangent = angle; } } else { if (SelectedTangent == 0) { keyframe.InTangent = angle; } if (SelectedTangent == 1) { keyframe.OutTangent = angle; } } var keyframeIndex = keyframe.curve.Keys.ToList().FindIndex(element => element == keyframe); RebuildCachedKeyframeInformation(keyframe); if (keyframeIndex != 0) { RebuildCachedKeyframeInformation(keyframe.curve.Keys[keyframeIndex - 1]); } if (keyframeIndex < keyframe.curve.Keys.Count - 1) { RebuildCachedKeyframeInformation(keyframe.curve.Keys[keyframeIndex + 1]); } keyframe.curve.BuildAnimationCurveFromInternalCurve(); Event.current.Use(); }
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(); } } }
public override void OnInspectorGUI() { keyframes.Update(); var newTime = EditorGUILayout.FloatField(new GUIContent("Fire Time"), time.floatValue); EditorGUILayout.PropertyField(value, new GUIContent("Value")); EditorGUILayout.PropertyField(inTangent, new GUIContent("In Tangent")); EditorGUILayout.PropertyField(outTangent, new GUIContent("Out Tangent")); EditorGUILayout.PropertyField(brokenTangents, new GUIContent("Broken Tangent")); var internalKeyframe = target as USInternalKeyframe; if (internalKeyframe && !Mathf.Approximately(internalKeyframe.Time, newTime)) { foreach (var internalObject in targets) { if (!(internalObject is USInternalKeyframe)) { continue; } var keyframe = internalObject as USInternalKeyframe; if (!keyframe.curve || keyframe.curve.CanSetKeyframeToTime(newTime)) { time.floatValue = newTime; } } } var hasDoneSomething = false; var isUndo = Event.current != null && (Event.current.type == EventType.ValidateCommand && Event.current.commandName == "UndoRedoPerformed"); if (keyframes.ApplyModifiedProperties() || isUndo) { foreach (var internalObject in targets) { if (!(internalObject is USInternalKeyframe)) { continue; } var keyframe = internalObject as USInternalKeyframe; if (!isUndo) { USUndoManager.PropertyChange(keyframe.curve, "Inspector"); } keyframe.curve.ValidateKeyframeTimes(); keyframe.curve.BuildAnimationCurveFromInternalCurve(); hasDoneSomething = true; } } if (hasDoneSomething) { var windows = Resources.FindObjectsOfTypeAll <USWindow>(); foreach (var window in windows) { window.ExternalModification(); } } }