private void OnSingleCameraSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JCameraClipData) { Selection.activeObject = (JCameraClipData)selectobj.ClipData; } }
private void OnSingleAnimationSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JAnimationClipData) { Selection.activeObject = (JAnimationClipData)selectobj.ClipData; } }
private void OnSingleSoundSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JSoundClipData) { Selection.activeObject = (JSoundClipData)selectobj.ClipData; } }
//单独选中一个关键帧 private void OnSingleTransformSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JSplineKeyframe) { Selection.activeObject = (JSplineKeyframe)selectobj.ClipData; } }
//单独选中一个关键帧 private void OnSingleEffectSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JEffectClipData) { Selection.activeObject = (JEffectClipData)selectobj.ClipData; } }
//单独选中一个关键帧 private void OnSingleEventSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JEventBase) { Selection.activeObject = (JEventBase)selectobj.ClipData; } }
//拖动 private void ProcessDraggingTransformClip(JClipRenderData clip, Vector2 mouseDelta) { if (SourcePositions.ContainsKey(clip)) { ScriptableObject selected = clip.ClipData; if (selected is JSplineKeyframe) { JSplineKeyframe Keyframe = selected as JSplineKeyframe; float mousePosOnTimeline = ContentXToTime(mouseDelta.x + FloatingWidth); float newTime = SourcePositions[clip] + mousePosOnTimeline; newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration); int index = Keyframe.Track.Keyframes.IndexOf(Keyframe); if (index == 0) { Keyframe.StartTime = newTime; Keyframe.Track.StartTime = newTime; } else if (index == Keyframe.Track.Keyframes.Count - 1) { Keyframe.StartTime = newTime; Keyframe.Track.EndTime = newTime; } else { newTime = Mathf.Clamp(newTime, Keyframe.Track.Keyframes[index - 1].StartTime, Keyframe.Track.Keyframes[index + 1].StartTime); Keyframe.StartTime = newTime; } if (SelectedObjects.Count == 1) { Selection.activeObject = Keyframe; } } } }
private void OnSingleParticleSelected(JClipRenderData selectobj) { if (selectobj.ClipData is JParticleClipData) { Selection.activeObject = (JParticleClipData)selectobj.ClipData; } }
//单独选中一个关键帧 private void OnSingleTrajectorySelected(JClipRenderData selectobj) { if (selectobj.ClipData is JTrajectoryClipData) { Selection.activeObject = (JTrajectoryClipData)selectobj.ClipData; } }
//开始拖动记录原始位置 private void StartDraggingEventClip(JClipRenderData clipData) { var trackdata = clipData.ClipData; if (trackdata is JEventBase) { SourcePositions[clipData] = ((JEventBase)trackdata).StartTime; } }
public void DeleteSelection() { foreach (var selectedObject in SelectedObjects) { JClipRenderData clip = selectedObject as JClipRenderData; RemoveClip(clip); } SelectedObjects.Clear(); }
//开始拖动记录原始位置 private void StartDraggingTrajectoryClip(JClipRenderData clipData) { var trackdata = clipData.ClipData; if (trackdata is JTrajectoryClipData) { SourcePositions[clipData] = ((JTrajectoryClipData)trackdata).StartTime; } }
/// <summary> /// 移除可见渲染块 /// </summary> /// <param name="clip"></param> private void RemoveClip(JClipRenderData clip) { RemoveAnimationClip(clip); RemoveParticleClip(clip); RemoveSoundClip(clip); RemoveKeyFrame(clip); RemoveTrajectoryClip(clip); RemoveEffectClip(clip); }
//开始拖动记录原始位置 private void StartDraggingTransformClip(JClipRenderData clipData) { var trackdata = clipData.ClipData; if (trackdata is JSplineKeyframe) { SourcePositions[clipData] = ((JSplineKeyframe)trackdata).StartTime; } }
private void StartDraggingParticleClip(JClipRenderData clipData) { var trackdata = clipData.ClipData; if (trackdata is JParticleClipData) { SourcePositions[clipData] = ((JParticleClipData)trackdata).StartTime; } }
public void OnSingleClipSelected(JClipRenderData selectobj) { OnSingleAnimationSelected(selectobj); OnSingleParticleSelected(selectobj); OnSingleSoundSelected(selectobj); OnSingleTransformSelected(selectobj); OnSingleEventSelected(selectobj); OnSingleTrajectorySelected(selectobj); OnSingleCameraSelected(selectobj); OnSingleEffectSelected(selectobj); }
private void RemoveTrajectoryClip(JClipRenderData clip) { if (clip.ClipData is JTrajectoryClipData) { JTrajectoryClipData anidata = (JTrajectoryClipData)clip.ClipData; if (timelineClipRenderDataMap.ContainsKey(anidata.Track)) { if (timelineClipRenderDataMap[anidata.Track].Contains(clip)) { timelineClipRenderDataMap[anidata.Track].Remove(clip); } } anidata.Track.RemoveClip(anidata); } }
private void RemoveParticleClip(JClipRenderData clip) { var clipdata = clip.ClipData; if (clipdata is JParticleClipData) { JParticleClipData anidata = (JParticleClipData)clipdata; if (timelineClipRenderDataMap.ContainsKey(anidata.Track)) { if (timelineClipRenderDataMap[anidata.Track].Contains(clip)) { timelineClipRenderDataMap[anidata.Track].Remove(clip); } } anidata.Track.RemoveClip(anidata); } }
private void RemoveEvent(JClipRenderData renderdata) { var keyframe = renderdata.ClipData; if (keyframe is JEventBase) { JEventBase key = (JEventBase)keyframe; JEventTrack track = key.Track; if (timelineClipRenderDataMap.ContainsKey(track)) { if (timelineClipRenderDataMap[track].Contains(renderdata)) { timelineClipRenderDataMap[track].Remove(renderdata); } } track.RemoveClip(key); } }
private void RemoveKeyFrame(JClipRenderData renderdata) { var keyframe = renderdata.ClipData; if (keyframe is JSplineKeyframe) { JSplineKeyframe key = (JSplineKeyframe)keyframe; JTransformTrack track = key.Track; if (timelineClipRenderDataMap.ContainsKey(track)) { if (timelineClipRenderDataMap[track].Contains(renderdata)) { timelineClipRenderDataMap[track].Remove(renderdata); } } track.RemoveKeyframe(key); } }
private void ProcessDraggingParticleClip(JClipRenderData clip, Vector2 mouseDelta) { if (SourcePositions.ContainsKey(clip)) { UnityEngine.Object selected = clip.ClipData; if (selected is JParticleClipData) { JParticleClipData particleClipData = selected as JParticleClipData; float mousePosOnTimeline = ContentXToTime(mouseDelta.x + FloatingWidth); float newTime = SourcePositions[clip] + mousePosOnTimeline; newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration - particleClipData.PlaybackDuration); particleClipData.StartTime = newTime; if (SelectedObjects.Count == 1) { Selection.activeObject = particleClipData; } } } }
//拖动 private void ProcessDraggingEventClip(JClipRenderData clip, Vector2 mouseDelta) { if (SourcePositions.ContainsKey(clip)) { ScriptableObject selected = clip.ClipData; if (selected is JEventBase) { JEventBase aevent = selected as JEventBase; float mousePosOnTimeline = ContentXToTime(mouseDelta.x + FloatingWidth); float newTime = SourcePositions[clip] + mousePosOnTimeline; newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration); aevent.StartTime = newTime; if (SelectedObjects.Count == 1) { Selection.activeObject = aevent; } } } }
private void ProcessDraggingAnimationClip(JClipRenderData clip, Vector2 mouseDelta) { if (SourcePositions.ContainsKey(clip)) { ScriptableObject selected = (ScriptableObject)clip.ClipData; if (selected is JAnimationClipData) { JAnimationClipData animationClipData = selected as JAnimationClipData; //float newTime = ((newPosition.x / DisplayArea.width) * AnimationTimeline.Sequence.Duration) / XScale; // newTime = Mathf.Clamp(newTime, 0.0f, AnimationTimeline.Sequence.Duration); float mousePosOnTimeline = ContentXToTime(FloatingWidth + mouseDelta.x); float newTime = SourcePositions[clip] + mousePosOnTimeline; newTime = Mathf.Clamp(newTime, 0.0f, CurrentSequence.Duration - animationClipData.PlaybackDuration); animationClipData.StartTime = newTime; if (SelectedObjects.Count == 1) { Selection.activeObject = animationClipData; } } } }
private void ParticleGUI(JTimelineParticle Particleline, JParticleTrack linetrack, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JParticleClipData particleClipData = (JParticleClipData)renderdata.ClipData; JParticleTrack track = particleClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(particleClipData.StartTime); var endX = ConvertTimeToXPos(particleClipData.StartTime + particleClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(particleClipData.StartTime + particleClipData.TransitionDuration); var handleWidth = 2.0f; float posy = DisplayArea.y; float height = DisplayArea.height; Rect renderRect = new Rect(startX, posy, endX - startX, height); Rect transitionRect = new Rect(startX, posy, transitionX - startX, height); Rect leftHandle = new Rect(startX, posy, handleWidth * 2.0f, height); Rect rightHandle = new Rect(endX - (handleWidth * 2.0f), posy, handleWidth * 2.0f, height); Rect labelRect = new Rect(); Rect renderRecttemp = renderRect; renderRecttemp.x -= DisplayArea.x; renderRecttemp.y = 0; Rect transitionRecttemp = transitionRect; transitionRecttemp.y = 0; transitionRecttemp.x -= DisplayArea.x; Rect leftHandletemp = leftHandle; leftHandletemp.y = 0; leftHandletemp.x -= DisplayArea.x; Rect rightHandletemp = rightHandle; rightHandletemp.x -= DisplayArea.x; rightHandletemp.y = 0; GUI.color = new Color(163 / 255.0f, 237 / 255.0f, 116 / 255.0f, 1); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); if (particleClipData.CrossFade) { GUI.Box(transitionRecttemp, ""); } GUI.Box(leftHandletemp, ""); GUI.Box(rightHandletemp, ""); labelRect = renderRecttemp; labelRect.width = DisplayArea.width; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX, height); renderdata.transitionRect = transitionRect; renderdata.leftHandle = leftHandle; renderdata.rightHandle = rightHandle; renderdata.ClipData = particleClipData; if (particleClipData.CrossFade) { labelRect.x = labelRect.x + (transitionX - startX); } else { labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. } GUI.color = Color.black; GUI.Label(labelRect, particleClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveParticleClip(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(Animationline.gameObject.name); Selection.activeGameObject = Particleline.gameObject; EditorGUIUtility.PingObject(Particleline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForParticleTimeLine(Particleline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } }
private void TransformGUI(JTimelineBase timeline, JTransformTrack track, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1 && UnityEngine.Event.current.clickCount == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool isDouble = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 2; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; var linestartX = ConvertTimeToXPos(track.StartTime); var lineendX = ConvertTimeToXPos(track.EndTime); Rect linerenderRect = new Rect(linestartX, DisplayArea.y, lineendX - linestartX, DisplayArea.height); Rect linerenderRectTemp = linerenderRect; linerenderRectTemp.x -= DisplayArea.x; linerenderRectTemp.y = 0; GUI.color = new Color(85 / 255.0f, 47 / 255.0f, 176 / 255.0f, 1f); GUI.Box(linerenderRectTemp, "", USEditorUtility.NormalWhiteOutLineBG); GUI.color = Color.white; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JSplineKeyframe key = (JSplineKeyframe)renderdata.ClipData; var startX = ConvertTimeToXPos(key.StartTime); var handleWidth = 5.0f; Rect renderRect = new Rect(startX - handleWidth, DisplayArea.y, handleWidth * 2, DisplayArea.height); Rect renderRectTemp = renderRect; renderRectTemp.x -= DisplayArea.x; renderRectTemp.y = 0; Rect labelRect = new Rect(); GUI.color = new Color(255 / 255.0f, 122 / 255.0f, 105 / 255.0f, 1); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } GUI.Box(renderRectTemp, "", USEditorUtility.NormalWhiteOutLineBG); labelRect = renderRectTemp; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX - handleWidth, DisplayArea.y); renderdata.ClipData = key; GUI.color = Color.black; GUI.Label(labelRect, "" + track.Keyframes.IndexOf(key), USEditorUtility.USeqSkin.label); GUI.color = Color.white; if (isContext && renderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteKeyFrame"), false, (obj) => RemoveKeyFrame(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (hasBox && isContext && renderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(tline.gameObject.name); Selection.activeObject = track; EditorGUIUtility.PingObject(track); } if (!hasBox && isContext && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForTransformTimeLine(timeline, track); } if (!hasBox && isContext && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } if (!hasBox && isDouble && linerenderRectTemp.Contains(UnityEngine.Event.current.mousePosition)) { int index = 1; float newTime = (((UnityEngine.Event.current.mousePosition.x + XScroll) / DisplayArea.width) * timeline.Sequence.Duration) / XScale; for (int i = 1; i < track.Keyframes.Count; i++) { if (newTime <= track.Keyframes[i].StartTime) { index = i; break; } } AddNewKeyFrame(track, newTime, index); } }
private void SoundGUI(JTimelineSound Soundline, JSoundTrack linetrack, JClipRenderData[] renderDataList) { GenericMenu contextMenu = new GenericMenu(); ///event 右键点击 bool isContext = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 1; bool isChoose = UnityEngine.Event.current.type == EventType.MouseDown && UnityEngine.Event.current.button == 0 && UnityEngine.Event.current.clickCount == 1; bool hasBox = false; Rect DisplayAreaTemp = DisplayArea; DisplayAreaTemp.x = 0; DisplayAreaTemp.y = 0; for (int j = 0; j < renderDataList.Length; j++) { JClipRenderData renderdata = renderDataList[j]; JSoundClipData SoundClipData = (JSoundClipData)renderdata.ClipData; JSoundTrack track = SoundClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(SoundClipData.StartTime); var endX = ConvertTimeToXPos(SoundClipData.StartTime + SoundClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(SoundClipData.StartTime + SoundClipData.TransitionDuration); var handleWidth = 2.0f; Rect renderRect = new Rect(startX, DisplayArea.y, endX - startX, DisplayArea.height); Rect transitionRect = new Rect(startX, DisplayArea.y, transitionX - startX, DisplayArea.height); Rect leftHandle = new Rect(startX, DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect rightHandle = new Rect(endX - (handleWidth * 2.0f), DisplayArea.y, handleWidth * 2.0f, DisplayArea.height); Rect labelRect = new Rect(); Rect renderRecttemp = renderRect; renderRecttemp.x -= DisplayArea.x; renderRecttemp.y = 0; Rect transitionRecttemp = transitionRect; transitionRecttemp.y = 0; transitionRecttemp.x -= DisplayArea.x; Rect leftHandletemp = leftHandle; leftHandletemp.y = 0; leftHandletemp.x -= DisplayArea.x; Rect rightHandletemp = rightHandle; rightHandletemp.x -= DisplayArea.x; rightHandletemp.y = 0; //GUI.color = new Color(243 / 255.0f, 154 / 255.0f, 0 / 255.0f, 1f); GUI.color = ColorTools.GetGrandientColor((float)renderdata.index / (float)CountClip); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor; } Texture2D texture = AssetPreview.GetAssetPreview(SoundClipData.Clip); if (texture != null) { GUI.DrawTexture(renderRecttemp, texture, ScaleMode.StretchToFill); } else { GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); } if (SoundClipData.CrossFade) { GUI.Box(transitionRecttemp, ""); } GUI.Box(leftHandletemp, ""); GUI.Box(rightHandletemp, ""); labelRect = renderRecttemp; labelRect.width = DisplayArea.width; renderdata.renderRect = renderRect; renderdata.labelRect = renderRect; renderdata.renderPosition = new Vector2(startX, DisplayArea.y); renderdata.transitionRect = transitionRect; renderdata.leftHandle = leftHandle; renderdata.rightHandle = rightHandle; renderdata.ClipData = SoundClipData; if (SoundClipData.CrossFade) { labelRect.x = labelRect.x + (transitionX - startX); } else { labelRect.x += 4.0f; // Nudge this along a bit so it isn't flush with the side. } GUI.color = Color.black; GUI.Label(labelRect, SoundClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveSoundClip(((JClipRenderData)((object[])obj)[0])), new object[] { renderdata }); } if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } } if (!hasBox && isChoose && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition) && (UnityEngine.Event.current.control || UnityEngine.Event.current.command)) { //代码选中hierarchy中的对象 显示inspector 按住Ctrl or command //GameObject go = GameObject.Find(Animationline.gameObject.name); Selection.activeGameObject = Soundline.gameObject; EditorGUIUtility.PingObject(Soundline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForSoundTimeLine(Soundline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } // Handle the case where the object picker has a value selected. if (UnityEngine.Event.current.type == EventType.ExecuteCommand && UnityEngine.Event.current.commandName == "ObjectSelectorClosed") { if (EditorGUIUtility.GetObjectPickerControlID() == controlID) { UnityEngine.Object pickedObject = EditorGUIUtility.GetObjectPickerObject(); if (pickedObject != null) { AudioClip clip = (AudioClip)pickedObject; AddNewSoundState((JTimelineSound)savedData.Line, (JSoundTrack)savedData.Track, savedData.Firetime, clip.name, clip); } UnityEngine.Event.current.Use(); } } }