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(); } } }
//绘制动作片段UI private void AnimationGUI(JTimelineAnimation Animationline, JAnimationTrack 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]; JAnimationClipData animationClipData = (JAnimationClipData)renderdata.ClipData; JAnimationTrack track = animationClipData.Track; if (linetrack != track) { continue; } var startX = ConvertTimeToXPos(animationClipData.StartTime); var endX = ConvertTimeToXPos(animationClipData.StartTime + animationClipData.PlaybackDuration); var transitionX = ConvertTimeToXPos(animationClipData.StartTime + animationClipData.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(70 / 255.0f, 147 / 255.0f, 236 / 255.0f, 1); GUI.color = ColorTools.GetGrandientColor((float)renderdata.index / (float)CountClip); if (SelectedObjects.Contains(renderdata)) { GUI.color = ColorTools.SelectColor;// Color.yellow; } GUI.Box(renderRecttemp, "", USEditorUtility.NormalWhiteOutLineBG); if (animationClipData.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 = animationClipData; if (animationClipData.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, animationClipData.FriendlyName); GUI.color = Color.white; if (isContext && renderRecttemp.Contains(UnityEngine.Event.current.mousePosition)) { hasBox = true; contextMenu.AddItem(new GUIContent("DeleteClip"), false, (obj) => RemoveAnimationClip(((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 = Animationline.gameObject; EditorGUIUtility.PingObject(Animationline.gameObject); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { contextMenu = MenuForAnimationTimeLine(Animationline, linetrack); } if (!hasBox && isContext && DisplayAreaTemp.Contains(UnityEngine.Event.current.mousePosition)) { UnityEngine.Event.current.Use(); contextMenu.ShowAsContext(); } }