private void AddRenderDataForTransform(JTimelineBase timeline) { if (timeline is JTimelineTransform) { JTimelineTransform tline = (JTimelineTransform)timeline; for (int k = 0; k < tline.Tracks.Count; k++) { List <JClipRenderData> list = new List <JClipRenderData>(); JTransformTrack track = tline.Tracks[k]; for (int l = 0; l < track.Keyframes.Count; l++) { JSplineKeyframe key = track.Keyframes[l]; var cachedData = ScriptableObject.CreateInstance <JClipRenderData>(); cachedData.ClipData = key; list.Add(cachedData); } if (!timelineClipRenderDataMap.ContainsKey(track)) { timelineClipRenderDataMap.Add(track, list); } else { timelineClipRenderDataMap[track] = list; } } } }
//侧边栏 private void SideBarAndLineForTranform(JTimelineBase timeline) { if (timeline is JTimelineTransform) { GUILayout.BeginVertical(); JTimelineTransform transformline = (JTimelineTransform)timeline; for (int j = 0; j < transformline.Tracks.Count; j++) { GUILayout.BeginHorizontal(); GUILayout.Box(new GUIContent("" + transformline.AffectedObject.name, ""), USEditorUtility.USeqSkin.GetStyle("TimelinePaneBackground"), GUILayout.Height(lineHeight), GUILayout.MaxWidth(FloatingWidth)); Rect FloatingRect = GUILayoutUtility.GetLastRect(); GUILayout.Box(new GUIContent("", "TransformTimeline for" + transformline.AffectedObject.name + "Track " + j), USEditorUtility.USeqSkin.GetStyle("TimelinePaneBackground"), GUILayout.Height(lineHeight), GUILayout.ExpandWidth(true)); Rect ContentRect = GUILayoutUtility.GetLastRect(); GUILayout.EndHorizontal(); Rect addRect = FloatingRect; Rect labelRect = addRect; labelRect.x += 40; labelRect.width -= (lineHeight + 41); GUI.Label(labelRect, "Track " + j); //轨道名字 Rect nameRect = addRect; nameRect.x += 40 + lineHeight + 40; nameRect.width -= (lineHeight + 120); transformline.Tracks[j].name = GUI.TextField(nameRect, transformline.Tracks[j].name); Rect enableRect = addRect; enableRect.x = addRect.x + addRect.width - 2 * lineHeight - 2.0f;; enableRect.width = lineHeight; //enable开关 transformline.Tracks[j].Enable = GUI.Toggle(enableRect, transformline.Tracks[j].Enable, new GUIContent("", USEditorUtility.EditButton, "Enable The Timeline")); addRect.x = addRect.x + addRect.width - lineHeight - 1.0f; addRect.width = lineHeight; GenericMenu contextMenu = new GenericMenu(); if (GUI.Button(addRect, new GUIContent("", USEditorUtility.EditButton, "Options for this Timeline"), USEditorUtility.ToolbarButtonSmall)) { contextMenu = MenuForTransformTimeLine(transformline, transformline.Tracks[j]); contextMenu.ShowAsContext(); } if (timelineClipRenderDataMap.ContainsKey(transformline.Tracks[j])) { ///时间线背景 区域 只接受右键 DisplayArea = ContentRect;// GUILayoutUtility.GetLastRect(); GUI.BeginGroup(DisplayArea); List <JClipRenderData> renderDataList = timelineClipRenderDataMap[transformline.Tracks[j]]; TransformGUI(transformline, transformline.Tracks[j], renderDataList.ToArray()); GUI.EndGroup(); } } GUILayout.EndVertical(); } }
private void AddNewTransFormTrack(JTimelineBase line) { if (line is JTimelineTransform) { JTimelineTransform tline = (JTimelineTransform)line; var track = ScriptableObject.CreateInstance <JTransformTrack>(); tline.AddTrack(track); tline.Build(); AddRenderDataForTransform(tline); } }
private void RemoveTransformLine(JTransformTrack track) { if (timelineClipRenderDataMap.ContainsKey(track)) { timelineClipRenderDataMap.Remove(track); } JTimelineTransform line = (JTimelineTransform)track.TimeLine; line.RemoveTrack(track); JTimelineContainer contain = line.TimelineContainer; if (line.Tracks.Count == 0) { DestroyImmediate(line.gameObject); } //删除的是最后一个 删除掉container if (contain.transform.childCount == 0) { DestroyImmediate(contain.gameObject); } }
public void OnTransformSceneGUI(JTimelineBase timeline) { if (timeline == null) { return; } if (timeline.LineType() == TimeLineType.Transform) { JTimelineTransform ObjectPathTimeline = (JTimelineTransform)timeline; if (ObjectPathTimeline.Tracks == null) { return; } for (int i = 0; i < ObjectPathTimeline.Tracks.Count; i++) { JTransformTrack tTrack = ObjectPathTimeline.Tracks[i]; if (SelectedNodeIndex >= 0) { if (UnityEngine.Event.current.isKey && (UnityEngine.Event.current.keyCode == KeyCode.Delete || UnityEngine.Event.current.keyCode == KeyCode.Backspace)) { UnityEngine.Event.current.Use(); RemoveKeyFrameWithKeyframe(SelectedNodeIndex); SelectedNodeIndex = -1; } } if (UnityEngine.Event.current.type == EventType.mouseDown) { var nearestIndex = GetNearestNodeForMousePosition(tTrack, UnityEngine.Event.current.mousePosition); if (nearestIndex != -1) { SelectedNodeIndex = nearestIndex; if (UnityEngine.Event.current.clickCount == 1 && UnityEngine.Event.current.button == 0) { ResetSelection(); Selection.activeObject = tTrack.Keyframes[SelectedNodeIndex]; OnSelectedObjects(new List <Object> { tTrack.Keyframes[SelectedNodeIndex] }); } if (UnityEngine.Event.current.clickCount > 1) { var cameraTransform = UnityEditor.SceneView.currentDrawingSceneView.camera.transform; var keyframe = tTrack.Keyframes[SelectedNodeIndex]; int next = SelectedNodeIndex == (tTrack.Keyframes.Count - 1) ? (SelectedNodeIndex - 1) : (SelectedNodeIndex + 1); var nextKeyframe = tTrack.Keyframes[next]; float newtime = (keyframe.StartTime + nextKeyframe.StartTime) * 0.5f; AddNewKeyFrame(tTrack, newtime, SelectedNodeIndex); GUI.changed = true; } } } if (tTrack.Keyframes.Count >= 2) { if (Vector3.Distance(tTrack.Keyframes[0].Position, tTrack.Keyframes[tTrack.Keyframes.Count - 1].Position) == 0) { Handles.Label(tTrack.Keyframes[0].Position, "Start and End"); } else { Handles.Label(tTrack.Keyframes[0].Position, "Start"); Handles.Label(tTrack.Keyframes[tTrack.Keyframes.Count - 1].Position, "End"); } } for (int nodeIndex = 0; nodeIndex < tTrack.Keyframes.Count; nodeIndex++) { var node = tTrack.Keyframes[nodeIndex]; if (node && nodeIndex > 0 && nodeIndex < tTrack.Keyframes.Count - 1) { float handleSize = HandlesUtility.GetHandleSize(node.Position); Handles.Label(node.Position + new Vector3(0.25f * handleSize, 0.0f * handleSize, 0.0f * handleSize), nodeIndex.ToString()); } var existingKeyframe = tTrack.Keyframes[nodeIndex]; Quaternion oldrotation = Quaternion.Euler(existingKeyframe.Rotation); Vector3 oldpos = existingKeyframe.Position; Vector3 oldtang = existingKeyframe.Tangent; Vector3 oldnormal = existingKeyframe.Normal; Vector3 newPosition = HandlesUtility.PositionHandle(existingKeyframe.Position, oldrotation); Vector3 newtangent = HandlesUtility.TangentHandle(existingKeyframe.Position + existingKeyframe.Tangent) - existingKeyframe.Position; if (oldpos != newPosition || oldtang != newtangent) { tTrack.AlterKeyframe(newPosition, oldrotation.eulerAngles, newtangent, oldnormal, nodeIndex); EditorUtility.SetDirty(tTrack); } } } } }