using System; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEditor; namespace ActionTool { public struct BoxParam { public ColliderData collider; public int frame; } public struct EventParam { public string eventName; public int frame; } public class ActionPreviewEditor : EditorWindow { Texture m_UITextureStop; Texture m_UITexturePause; Texture m_UITexturePlay; Texture m_UITextureNext; Texture m_UITextureEnd; Texture m_UITexturePrevious; Texture m_UITextureStart; Texture m_UITextureNewHurtBox; Texture m_UITextureNewHitBox; Texture m_UITextureNewThrowBox; Texture m_UITextureNewBlockBox; Texture m_UITextureNewDefendBox; GUIStyle m_StyleBold; const float kToolbarControlMargin = 5; const float kToolbarHeight = 50; const float kToolbarControlSize = kToolbarHeight - kToolbarControlMargin * 2; const float kCurveYOffset = 80; const float kTimeLineViewXOffset = 20; float kTimeLineViewYOffset = 110; const float kFrameWidth = 10; const float kFrameHeight = 20; float m_GridY = 0; float m_ToolbarOffset = 0; // <= 0 bool m_ShowLeftButton; bool m_ShowRightButton; Rect m_LeftRegion; Rect m_RightRegion; bool m_IsLeftOrRightButtonClicked; ActionEditorStyles styles; ActionEditorUI ui; private void OnEnable() { titleContent = new GUIContent("Action Preview"); m_UITextureStop = (Texture)Resources.Load("button_control_stop"); m_UITexturePause = (Texture)Resources.Load("button_control_pause"); m_UITexturePlay = (Texture)Resources.Load("button_control_play"); m_UITextureNext = (Texture)Resources.Load("button_control_next"); m_UITextureEnd = (Texture)Resources.Load("button_control_end"); m_UITexturePrevious = (Texture)Resources.Load("button_control_previous"); m_UITextureStart = (Texture)Resources.Load("button_control_start"); m_UITextureNewHurtBox = (Texture)Resources.Load("hurtbox"); m_UITextureNewHitBox = (Texture)Resources.Load("hitbox"); m_UITextureNewThrowBox = (Texture)Resources.Load("throwbox"); m_UITextureNewBlockBox = (Texture)Resources.Load("blockbox"); m_UITextureNewDefendBox = (Texture)Resources.Load("defendbox"); m_IsLeftOrRightButtonClicked = false; } void Update() { ActionManager.UpdateFrame(); if(ActionManager.RootMotionEditor != null) ActionManager.RootMotionEditor.Repaint(); } private void OnDisable() { ActionManager.PreviewWindow = null; } private void OnGUI() { //if(ActionManager.actionData == null) //{ // this.Close(); // return; //} styles = ActionEditorStyles.Get(); if (ActionManager.CurrentAnimationName == null || ActionManager.CurrentAnimationName == "") { EditorGUILayout.HelpBox("选择动画", MessageType.Warning); return; } if (styles == null) styles = ActionEditorStyles.Get(); if (ui == null) ui = ActionEditorUI.Get(); GUI_Toolbar(); float y = kToolbarHeight + 5; GUI_Detail(ref y); GUI_Properties(ref y); GUI_Parameters(ref y); GUI_Toggle(ref y); GUI_Curves(ref y); GUI_Curve(ref y); GUI_PlaybackTime(ref y); y += 5; GUI_Setting(ref y); GUI_TimeLineView(ref y); } void GUI_Toolbar() { Event e = Event.current; float x = m_ToolbarOffset, y = kToolbarControlMargin; m_IsLeftOrRightButtonClicked = (e.isMouse && ((m_ShowLeftButton && m_LeftRegion.Contains(e.mousePosition)) || (m_ShowRightButton && m_RightRegion.Contains(e.mousePosition)))); GUI.enabled = !m_IsLeftOrRightButtonClicked; GUI_Toolbar_BG(); GUI_Toolbar_Start(ref x, ref y); GUI_Toolbar_Previous(ref x, ref y); GUI_Toolbar_Stop(ref x, ref y); GUI_Toolbar_Pause(ref x, ref y); GUI_Toolbar_Next(ref x, ref y); GUI_Toolbar_End(ref x, ref y); GUI_DrawSeperateLine(x + 10 + kToolbarControlMargin, 0, kToolbarHeight); x += 20; GUI.enabled = !m_IsLeftOrRightButtonClicked && ActionManager.animationData != null; GUI_Toolbar_NewHurtBox(ref x, ref y); GUI_Toolbar_NewHitBox(ref x, ref y); GUI_Toolbar_NewThrowBox(ref x, ref y); GUI_Toolbar_NewBlockBox(ref x, ref y); GUI_Toolbar_NewDefendBox(ref x, ref y); //GUI_Toolbar_Detail(ref x, ref y); //GUI_Toolbar_Delete(ref x, ref y); GUI.enabled = !m_IsLeftOrRightButtonClicked; GUI_DrawSeperateLine(x + 10 + kToolbarControlMargin, 0, kToolbarHeight); x += 20; GUI.enabled = !m_IsLeftOrRightButtonClicked && ActionManager.animationData == null; GUI_Toolbar_NewAnimationData(ref x, ref y); GUI.enabled = !m_IsLeftOrRightButtonClicked; GUI.enabled = !m_IsLeftOrRightButtonClicked && ActionManager.animationData != null; GUI_Toolbar_Save(ref x, ref y); GUI.enabled = !m_IsLeftOrRightButtonClicked; GUI.enabled = true; GUI_Toolbar_Expand(x); } void GUI_Toolbar_BG() { GUI.DrawTexture(new Rect(0, 0, position.width, 50), EditorStyles.toolbar.normal.background); } void GUI_Toolbar_Start(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if(GUI.Button(rect, m_UITextureStart)) { ActionManager.Start(); } x += kToolbarControlSize; } void GUI_Toolbar_Previous(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITexturePrevious)) { ActionManager.Previous(); } x += kToolbarControlSize; } void GUI_Toolbar_Stop(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureStop)) { ActionManager.Stop(); } x += kToolbarControlSize; } void GUI_Toolbar_Pause(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); Texture tex = ActionManager.IsPlay ? m_UITexturePlay : m_UITexturePause; if (GUI.Button(rect, tex)) { ActionManager.Pause(); } x += kToolbarControlSize; } void GUI_Toolbar_Next(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureNext)) { ActionManager.Next(); } x += kToolbarControlSize; } void GUI_Toolbar_End(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, m_UITextureEnd)) { ActionManager.End(); } x += kToolbarControlSize; } void GUI_Detail(ref float y) { var actionData = ActionManager.actionData; var animationData = ActionManager.animationData; float xl = 5, xr = xl + 105; GUI.Label(new Rect(xl, y, 105, 15), "Animation Name:", styles.textMiddle); float width = styles.textMiddleBold.CalcSize(new GUIContent(ActionManager.CurrentAnimationName)).x; GUI.Label(new Rect(xr, y, width, 15), ActionManager.CurrentAnimationName, styles.textMiddleBold); if(GUI.Button(new Rect(xr + width + 10, y, 50, 15), "Info")) { ActionInfoEditor.ShowContent("Animation Info", "Length: " + ActionManager.curClip.length + "s \n" + "WrapMode: " + ActionManager.curClip.wrapMode + "\n" + "IsLooping: " + ActionManager.curClip.isLooping + "\n" + "FrameRate: " + ActionManager.curClip.frameRate ); } y += 15; GUI.Label(new Rect(xl, y, 105, 15), "AnimationData:", styles.textMiddle); if(ActionManager.animationData != null) { width = styles.textMiddleBold.CalcSize(new GUIContent(ActionManager.AnimationDataPath)).x; GUI.Label(new Rect(xr, y, width, 15), ActionManager.AnimationDataPath, styles.textMiddleBold); if (GUI.Button(new Rect(xr + width + 10, y, 50, 15), "Info")) { AnimationData animData = ActionManager.animationData; ActionInfoEditor.ShowContent("AnimationData Info", "Events: " + (animData.animationEvents == null ? 0 : animData.animationEvents.Count) + "\n" + "HurtBoxes: " + (animData.hurtBoxes == null ? 0 : animData.hurtBoxes.Count) + "\n" + "HitBoxes: " + (animData.hitBoxes == null ? 0 : animData.hitBoxes.Count) + "\n" + "ThrowBoxes: " + (animData.throwBoxes == null ? 0 : animData.throwBoxes.Count) + "\n" + "BlockBoxes: " + (animData.blockBoxes == null ? 0 : animData.blockBoxes.Count) + "\n" + "DefendBoxes: " + (animData.defendBoxes == null ? 0 : animData.defendBoxes.Count) ); } } else { GUI.Label(new Rect(xr, y, 100, 15), "None", styles.textMiddleBold); } y += 15; GUI.Label(new Rect(xl, y, 105, 15), "RootMotion:", styles.textMiddle); if(actionData.rootMotion != null && (animationData == null || animationData.overrideRootMotion == false)) { string content = ActionManager.actionData.rootMotionPath + " (Editor Only)"; width = styles.textMiddleBold.CalcSize(new GUIContent(content)).x; GUI.Label(new Rect(xr, y, width, 15), content, styles.textMiddleBold); if (GUI.Button(new Rect(xr + width + 10, y, 50, 15), "Info")) { RootMotionData rootMotion = ActionManager.actionData.rootMotion; ActionInfoEditor.ShowContent("RootMotion Info", "Frame Count: " + rootMotion.frameCount ); } if(animationData != null) { if (GUI.Button(new Rect(xr + width + 10 + 60, y, 60, 15), "Override")) { animationData.AddRootMotionOverriderData(); } } } else if(animationData != null && animationData.overrideRootMotion == true) { width = styles.textMiddle.CalcSize(new GUIContent("Override")).x; GUI.Label(new Rect(xr, y, width, 15), "Override", styles.textMiddle); if (GUI.Button(new Rect(xr + width + 10, y, 60, 15), "Edit")) { ActionManager.EditRootMotionOverrideData(); } Color bg = GUI.backgroundColor; GUI.backgroundColor = Color.red; if (GUI.Button(new Rect(xr + width + 10 + 70, y, 60, 15), "Delete")) { animationData.DeleteRootMotionOverrideData(); } GUI.backgroundColor = bg; } else { GUI.Label(new Rect(xr, y, 50, 15), "None", styles.textMiddleBold); if(animationData != null) { if (GUI.Button(new Rect(xr + 60 + 10 + 60, y, 60, 15), "Override")) { animationData.AddRootMotionOverriderData(); } } } y += 15; } void GUI_PlaybackTime(ref float y) { float xl = 5, xr = xl + 105; GUI.Label(new Rect(xl, y, 105, 15), "Playback Frame:", styles.textMiddle); GUI.Label(new Rect(xr, y, 110, 15), ActionManager.actionData.curAnimFrame.ToString("f2"), styles.textMiddleBold); GUI.Label(new Rect(xl + 150, y, 105, 15), "Normalized Time:", styles.textMiddle); GUI.Label(new Rect(xr + 150, y, 110, 15), ActionManager.actionData.curAnimTimeNormal.ToString("f2"), styles.textMiddleBold); GUI.Label(new Rect(xl + 150 * 2, y, 105, 15), "Event Frame:", styles.textMiddle); GUI.Label(new Rect(xr + 150 + 125, y, 110, 15), ((int)ActionManager.actionData.curAnimFrame).ToString(), styles.textMiddleBold); GUI.Label(new Rect(xl + 150 + 130 + 130, y, 105, 15), "Time:", styles.textMiddle); GUI.Label(new Rect(xr + 150 + 130 + 70 , y, 510, 15), ((int)ActionManager.actionData.curAnimFrame).ToString(), styles.textMiddleBold); y += 15; } void GUI_Curve(ref float y) { AnimationData animData = ActionManager.animationData; if (animData == null) return; float x = 5; GUI.Label(new Rect(x, y, 105, 15), "Speed Curve:", styles.textMiddle); x += 105; animData.speedCurve = EditorGUI.CurveField(new Rect(x, y, 210, 15), animData.speedCurve); ui.DrawVerticalLineFast(x + 210 * ActionManager.actionData.curAnimTimeNormal, y , y + 15, Color.red); y += 15; } void GUI_Properties(ref float y) { AnimationData animData = ActionManager.animationData; if (animData == null) return; var properties = animData.properties; float x = 5; GUI.Label(new Rect(x, y, 105, 15), "Properties:", styles.textMiddle); x += 105; GUI.Label(new Rect(x, y, 10, 15), (properties != null ? properties.Count : 0).ToString(), styles.textMiddleBold); x += 20; if (GUI.Button(new Rect(x, y, 50, 15), "Edit")) { EditorWindow.GetWindow(true); } y += 15; } void GUI_Parameters(ref float y) { AnimationData animData = ActionManager.animationData; if (animData == null) return; var parameters = animData.parameters; float x = 5; GUI.Label(new Rect(x, y, 105, 15), "Parameters:", styles.textMiddle); x += 105; GUI.Label(new Rect(x, y, 10, 15), (parameters != null ? parameters.Count : 0).ToString(), styles.textMiddleBold); x += 20; if (GUI.Button(new Rect(x, y, 50, 15), "Edit")) { EditorWindow.GetWindow(true); } y += 15; } void GUI_Toggle(ref float y) { AnimationData animData = ActionManager.animationData; if (animData == null) return; var toggles = animData.toggles; float x = 5; GUI.Label(new Rect(x, y, 105, 15), "Toggles:", styles.textMiddle); x += 105; GUI.Label(new Rect(x, y, 10, 15), (toggles != null ? toggles.Count : 0).ToString(), styles.textMiddleBold); //if(toggles != null && toggles.Count > 0) //{ x += 20; if(GUI.Button(new Rect(x, y, 50, 15), "Edit")) { EditorWindow.GetWindow(true); } //} y += 15; } void GUI_Curves(ref float y) { AnimationData animData = ActionManager.animationData; if (animData == null) return; var curves = animData.curves; float x = 5; GUI.Label(new Rect(x, y, 105, 15), "Curves:", styles.textMiddle); x += 105; GUI.Label(new Rect(x, y, 10, 15), (curves != null ? curves.Count : 0).ToString(), styles.textMiddleBold); x += 20; if (GUI.Button(new Rect(x, y, 50, 15), "Edit")) { EditorWindow.GetWindow(true); } y += 15; } void GUI_Setting(ref float y) { ActionData action = ActionManager.actionData; Rect bgRect = new Rect(3, y - 4, position.width - 6, 15 + 8); EditorGUI.DrawRect(bgRect, new Color32(65, 65, 65, 255)); float x = 5; action.applyRootMotion = GUI.Toggle(new Rect(x, y, 120, 15), action.applyRootMotion, "Apply RootMotion", styles.toggleSmallBold); x += 130; action.applyCurve = GUI.Toggle(new Rect(x, y, 120, 15), action.applyCurve, "Apply SpeedCurve", styles.toggleSmallBold); x += 130; action.applyCurves = GUI.Toggle(new Rect(x, y, 120, 15), action.applyCurves, "Apply Curves", styles.toggleSmallBold); y += 20; } Vector2 scrollPos = Vector2.zero; void GUI_TimeLineView(ref float iy) { if (ActionManager.actionData == null) return; ActionData action = ActionManager.actionData; kTimeLineViewYOffset = iy; float y = iy; float contentHeight = ActionManager.GridRowCount * kFrameHeight + 40; Rect content = new Rect(0, 0, ((int)action.totalFrame + 1)* kFrameWidth + 30, contentHeight); float height = 300; if (position.height - kTimeLineViewYOffset > contentHeight + 15) height = contentHeight + 15; else height = position.height - kTimeLineViewYOffset; Rect viewport = new Rect(0, y, position.width, height); scrollPos = GUI.BeginScrollView(viewport, scrollPos, content); y = 0; GUI_FrameText(ref y); GUI_Slider(ref y); GUI_Grid(ref y); GUI_Events(); GUI_RM(); GUI_Boxes(); GUI_FrameLine(); GUI.EndScrollView(); } void GUI_FrameText(ref float y) { ActionData action = ActionManager.actionData; int sampleCount = (int)action.totalFrame + 1; Rect rect = new Rect(0, y, 20, 15); for(int i = 0; i < sampleCount; i++) { rect.x = kTimeLineViewXOffset + i * kFrameWidth - ((i >= 10) ? 7 : 5); if(i % 5 == 0) { Color c = GUI.color; GUI.color = i % 10 == 0 ? Color.yellow : GUI.color; GUI.Label(rect, i.ToString(), styles.textSmall); GUI.color = c; } } y += 11; } void GUI_Slider( ref float y) { ActionData action = ActionManager.actionData; Rect rect = new Rect(kTimeLineViewXOffset - 4, y, action.totalFrame * kFrameWidth + 7, 15); float t = GUI.HorizontalSlider(rect,action.curAnimTimeNormal, 0, 1); if(t != action.curAnimTimeNormal) { if(ActionManager.IsPlay) ActionManager.Pause(); action.curAnimTimeNormal = t; } if(ActionManager.IsPlay) { this.Repaint(); } y += 20; } void GUI_Grid(ref float y) { m_GridY = y; ActionData action = ActionManager.actionData; int sampleCount = (int)action.totalFrame + 1; Rect bgRect = new Rect(kTimeLineViewXOffset, y, sampleCount * kFrameWidth, ActionManager.GridRowCount * kFrameHeight); GUI.Box(bgRect, ""); Color lineColor = new Color(0.3f, 0.3f, 0.3f); Color lineColor2 = new Color(0.5f, 0.5f, 0.5f); for (int i = 0; i < ActionManager.GridRowCount + 1; i++) { ui.DrawHorizontalLineFast(y + i * kFrameHeight, kTimeLineViewXOffset, kTimeLineViewXOffset + sampleCount * kFrameWidth, lineColor); } for(int i = 0; i <= sampleCount; ++i) { Color c = i % 5 == 0 ? lineColor2 : lineColor; float x = kTimeLineViewXOffset + i * kFrameWidth; //x = Mathf.Clamp(x, kTimeLineViewXOffset, kTimeLineViewXOffset + action.totalFrame * kFrameWidth); ui.DrawVerticalLineFast(x, y, y + ActionManager.GridRowCount * kFrameHeight, c); } y += ActionManager.GridRowCount * kFrameHeight; } void GUI_FrameLine() { float y = m_GridY; ActionData action = ActionManager.actionData; Rect bgRect = new Rect(kTimeLineViewXOffset, y, action.totalFrame * kFrameWidth, ActionManager.GridRowCount * kFrameHeight); ui.defaultUIMaterail.SetPass(0); ui.DrawVerticalLineFast(kTimeLineViewXOffset + bgRect.width * action.curAnimTimeNormal, y, y + ActionManager.GridRowCount * kFrameHeight, Color.red); } void GUI_RM() { var animData = ActionManager.animationData; if (animData == null || animData.overrideRootMotion == false) return; float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight; Rect rect = new Rect(kTimeLineViewXOffset - 17, y - 1, 17, kFrameHeight); if(GUI.Button(rect, "", styles.boxToggle)) { ActionManager.EditRootMotionOverrideData(); } Rect lb = rect; lb.y += 3; GUI.Label(lb, "RM", styles.textBoldSmall); // var rmData = animData.rootMotionOverrideData; if (rmData == null) return; for(int i = 0; i < rmData.positions.Count; ++i) { var posData = rmData.positions[i]; if (posData == null) continue; int frame = posData.frame; Vector2 pos = new Vector2(kTimeLineViewXOffset + frame * kFrameWidth, y); if(GUI.Button(new Rect(pos.x - 1, pos.y + 4, kFrameWidth + 1, kFrameWidth), "", styles.keyButton)) { ActionManager.actionData.SetCurrentAnimTime(frame); } } } void GUI_Boxes() { var animData = ActionManager.animationData; bool hasRM = animData != null && animData.overrideRootMotion == true; float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1 + (hasRM ? 1:0)) * kFrameHeight; if (animData == null) return; DrawBoxList(animData.hurtBoxes, ref y, Color.green); DrawBoxList(animData.hitBoxes, ref y, Color.red); DrawBoxList(animData.throwBoxes, ref y, Color.blue); DrawBoxList(animData.blockBoxes, ref y, Color.yellow); DrawBoxList(animData.defendBoxes, ref y, Color.magenta); GenericMenu_BoxFrame(); } void DrawBoxList(List boxes, ref float y, Color c) { if (boxes == null || boxes.Count == 0) return; int count = boxes.Count; for(int i = 0; i < boxes.Count; ++i) { DrawBox(i, boxes[i], y + i * kFrameHeight, c); } y += count * kFrameHeight; } void DrawBox(int index, ColliderData box, float y, Color c) { ActionData action = ActionManager.actionData; Color prevColor = GUI.backgroundColor; GUI.backgroundColor = c; Rect rect = new Rect(kTimeLineViewXOffset - 17, y - 1, 17, kFrameHeight); bool selected = ActionManager.colliderData == box; bool select = GUI.Toggle(rect, selected, index.ToString(), styles.boxToggle); GUI.backgroundColor = prevColor; prevColor = GUI.color; GUI.color = c; if (select) { ActionManager.OnSelectBox(box, index); } else if(selected && !select) { ActionManager.OnSelectBox(null); } if(box.frames != null && box.frames.Count > 0) { int prevIndex = -1; for(int i = 0; i < box.frames.Count; ++i) { ColliderData.ColliderFrame frame = box.frames[i]; int frameIndex = frame.frame; Vector2 pos = new Vector2(kTimeLineViewXOffset + frameIndex * kFrameWidth, y); Rect frameRect = new Rect(pos.x, pos.y, kFrameWidth, kFrameHeight); bool frameSelected = frame == ActionManager.editColliderFrame; bool frameSelect = GUI.Toggle(frameRect, frameSelected, "",styles.keyFrameButton); if(!frameSelected && frameSelect) { //ActionManager.OnSelectBox(box, i); ActionManager.OnSelectColliderFrame(frame, box); } else if(frameSelect && !frameSelect) { ActionManager.OnSelectColliderFrame(null, null); } if(prevIndex != -1) { float length = (frameIndex - prevIndex - 1) * kFrameWidth; Rect region = new Rect(kTimeLineViewXOffset + (prevIndex + 1) * kFrameWidth, y, length, kFrameHeight); float animFrame = action.curAnimFrame; Color col = c * 0.4f; //if (ActionManager.IsPlay) //{ bool highlight = action.curAnimFrame >= prevIndex && action.curAnimFrame < frameIndex; col = highlight ? c * 0.6f : c * 0.4f; //} EditorGUI.DrawRect(region, col); } if (frame.active) prevIndex = frameIndex; else prevIndex = -1; } } GUI.color = prevColor; } void GenericMenu_BoxFrame() { Event e = Event.current; if (e.button != 1 || !e.isMouse || e.type != EventType.MouseDown) return; ActionData action = ActionManager.actionData; AnimationData animData = ActionManager.animationData; int sampleCount = (int)action.totalFrame + 1; float y = m_GridY + (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight + (animData.overrideRootMotion ? kFrameHeight : 0); Vector2 position = e.mousePosition; int boxCount = ActionManager.animationData.GetBoxesCount(); Rect boxRegion = new Rect(kTimeLineViewXOffset, y, sampleCount * kFrameWidth, boxCount * kFrameHeight); if (!boxRegion.Contains(position)) return; // 找到对应的box和帧 Vector2 pos = new Vector2(position.x - boxRegion.x, position.y - boxRegion.y); int index = (int)(pos.y / kFrameHeight); int frame = (int)(pos.x / kFrameWidth); ColliderData box = ActionManager.animationData.GetColliderByIndex(index); if(box != null) { BoxParam param = new BoxParam(); param.collider = box; param.frame = frame; //if(ActionManager.colliderData != box) // ActionManager.OnSelectBox(box, index); GenericMenu _newFrameMenu = new GenericMenu(); _newFrameMenu.AddItem(new GUIContent("New Frame"), false, ActionManager.AddNewBoxFrame, param); _newFrameMenu.AddItem(new GUIContent("Delete"), false, ActionManager.DeleteBoxFrame, param); _newFrameMenu.ShowAsContext(); } else { Debug.LogError("[ActionTool] 错误的点击"); } } void GUI_DrawSeperateLine(float x, float y, float height) { ui.defaultUIMaterail.SetPass(0); Color lineColor = new Color(0.3f, 0.3f, 0.3f); Color lineColor2 = new Color(0.1f, 0.1f, 0.1f); ui.DrawVerticalLineFast(x, y, y +height, lineColor2); ui.DrawVerticalLineFast(x+1, y, y +height, lineColor); } void GUI_Toolbar_NewHurtBox(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, new GUIContent(" + ", m_UITextureNewHurtBox, "New hurt box"))) { ActionManager.NewHurtBox(); } x += kToolbarControlSize; } void GUI_Toolbar_NewHitBox(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, new GUIContent(" + ", m_UITextureNewHitBox, "New hit box"))) { ActionManager.NewHitBox(); } x += kToolbarControlSize; } void GUI_Toolbar_NewThrowBox(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, new GUIContent(" + ", m_UITextureNewThrowBox, "New hit box"))) { ActionManager.NewHitBox(); } x += kToolbarControlSize; } void GUI_Toolbar_NewDefendBox(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, new GUIContent(" + ", m_UITextureNewDefendBox, "New hit box"))) { ActionManager.NewHitBox(); } x += kToolbarControlSize; } void GUI_Toolbar_NewBlockBox(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, new GUIContent(" + ", m_UITextureNewBlockBox, "New hit box"))) { ActionManager.NewHitBox(); } x += kToolbarControlSize; } void GUI_Toolbar_Detail(ref float x, ref float y) { x += kToolbarControlMargin + 20; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); GUI.enabled = !m_IsLeftOrRightButtonClicked && ActionManager.colliderData != null; if (GUI.Button(rect, new GUIContent(styles.infoIcon, "Detail"))) { ActionManager.EditCollider(); } GUI.enabled = true; x += kToolbarControlSize; } void GUI_Toolbar_Delete(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); GUI.enabled = !m_IsLeftOrRightButtonClicked && ActionManager.colliderData != null; if (GUI.Button(rect, new GUIContent(styles.deleteIcon, "Delete this collider"))) { ActionManager.DeleteCurBox(); } GUI.enabled = true; x += kToolbarControlSize; } void GUI_Toolbar_NewAnimationData(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); if (GUI.Button(rect, new GUIContent(styles.addFileIcon, "Add new animation data file"))) { ActionManager.CreateAnimationData(); } x += kToolbarControlSize; } void GUI_Toolbar_Save(ref float x, ref float y) { x += kToolbarControlMargin; Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); //Color c = GUI.backgroundColor; if (GUI.Button(rect, new GUIContent(styles.saveFileIcon, "Save"))) { ActionManager.SaveAnimationData(); } //GUI.backgroundColor = c; x += kToolbarControlSize; } void GUI_Toolbar_Expand(float x) { x += 5; float width = position.width; if (width >= x - m_ToolbarOffset) { m_ShowLeftButton = m_ShowRightButton = false; return; } float btnWidth = 20; Rect leftRect = new Rect(-2, kToolbarControlMargin - 6, btnWidth, kToolbarControlSize + 11); Rect rightRect = new Rect(position.width - 18, kToolbarControlMargin - 6, btnWidth, kToolbarControlSize + 11); m_LeftRegion = leftRect; m_RightRegion = rightRect; Color col = GUI.backgroundColor; GUI.backgroundColor = Color.gray; if (x > width) { m_ShowRightButton = true; if (GUI.Button(rightRect, ">", EditorStyles.miniButtonLeft)) { m_ToolbarOffset -= Mathf.Min(kToolbarControlSize, x - width); } } if(m_ToolbarOffset < 0) { m_ShowLeftButton = true; if (GUI.Button(leftRect, "<", EditorStyles.miniButtonRight)) { m_ToolbarOffset += Mathf.Min(kToolbarControlSize, -m_ToolbarOffset); } } GUI.backgroundColor = col; } void GUI_Events() { float y = m_GridY; Rect rect = new Rect(kTimeLineViewXOffset - 17, y - 1, 17, (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight); if (GUI.Button(rect, "", styles.boxToggle)) { AnimationData animData = ActionManager.animationData; Dictionary events = new Dictionary(); for (int i = 0; i < animData.animationEvents.Count; ++i) { var e = animData.animationEvents[i]; if(!events.ContainsKey(e.type.ToString())) events.Add(e.type.ToString(), 0); events[e.type.ToString()]++; } string str = ""; foreach(var e in events) { str += "\n" + e.Key.ToString() + ": " + e.Value; } ActionInfoEditor.ShowContent("Event Info", "Events: " + (animData.animationEvents == null ? 0 : animData.animationEvents.Count) + str ); } Rect lb = rect; //lb.y += 3; lb.x += 2; GUI.Label(lb, "EV", styles.textBoldSmallMid); DrawAllEvents(); GenericMenu_Event(); } void DrawAllEvents() { if (ActionManager.animationData == null) return; List frames = ActionManager.animationData.GetAnimationEventFrameIndices(); if (frames == null || frames.Count == 0) return; for(int i= 0;i < frames.Count; ++ i) { int frame = frames[i]; DrawFrameEvent(frame); } ListPool.Release(frames); } void DrawFrameEvent(int frame) { List animEvents = ActionManager.animationData.GetAnimationEventsAtFrame(frame); if (animEvents == null || animEvents.Count == 0) return; float y = m_GridY; for (int i = 0; i < animEvents.Count; ++i) { var animEvent = animEvents[i]; if (animEvent == null) continue; Color bgColor = Color.black; if(ActionManager.Settings != null) { bgColor = ActionManager.Settings.GetColor(animEvent.type.ToString()); } Vector2 pos = new Vector2(kTimeLineViewXOffset + frame * kFrameWidth, y); Rect frameRect = new Rect(pos.x, pos.y, kFrameWidth, kFrameHeight); bool isSelect = ActionManager.animationEvent == animEvent; Color prevColor = GUI.backgroundColor; GUI.backgroundColor = bgColor; bool frameSelect = GUI.Toggle(frameRect, isSelect, new GUIContent("", animEvent.Name), styles.keyFrameButton); GUI.backgroundColor = prevColor; Rect labelRect = new Rect(pos.x, pos.y + 2, kFrameWidth, kFrameHeight); Color col = GUI.color; GUI.color = Color.yellow; GUI.Label(labelRect, animEvent.shortName, styles.textBoldSmall); GUI.color = col; if (!isSelect && frameSelect) { ActionManager.OnSelectAnimationEvent(animEvent); } y += kFrameHeight; } ListPool.Release(animEvents); } void GenericMenu_Event() { Event e = Event.current; if (e.button != 1 || !e.isMouse || e.type != EventType.MouseDown) return; ActionData action = ActionManager.actionData; int sampleCount = (int)action.totalFrame + 1; Vector2 position = Event.current.mousePosition; Rect eventRegion = new Rect(kTimeLineViewXOffset, m_GridY, sampleCount * kFrameWidth, (ActionManager.MaxEventsPerFrame + 1) * kFrameHeight); if (!eventRegion.Contains(position)) return; Vector2 pos = new Vector2(position.x - eventRegion.x, position.y - eventRegion.y); int frame = (int)(pos.x / kFrameWidth); GenericMenu eventMenu = new GenericMenu(); foreach(var name in Enum.GetNames(typeof(TimelineEventProxy.EEventType))) { GUIContent item = null; string shortName = name.Replace("Event", ""); int underscore = shortName.IndexOf('_'); if(underscore != -1) { string category = shortName.Substring(0, underscore); shortName = shortName.Substring(underscore + 1, shortName.Length - underscore - 1); item = new GUIContent("New Event/" + category + "/" + shortName); } else { item = new GUIContent("New Event/" + shortName); } EventParam param = new EventParam(); param.eventName = name; param.frame = frame; eventMenu.AddItem(item, false, ActionManager.AddNewEvent, param); } eventMenu.AddItem(new GUIContent("Copy"), false, null); eventMenu.AddItem(new GUIContent("Paste"), false, ActionManager.PasteEvent, frame); eventMenu.ShowAsContext(); } } }