diff options
Diffstat (limited to 'Assets/ActionTool/Editor/ActionPreviewEditor.cs')
-rw-r--r-- | Assets/ActionTool/Editor/ActionPreviewEditor.cs | 130 |
1 files changed, 117 insertions, 13 deletions
diff --git a/Assets/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/ActionTool/Editor/ActionPreviewEditor.cs index 45048f0e..f277ce97 100644 --- a/Assets/ActionTool/Editor/ActionPreviewEditor.cs +++ b/Assets/ActionTool/Editor/ActionPreviewEditor.cs @@ -1,4 +1,5 @@ -using System.Collections;
+using System;
+using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
@@ -12,6 +13,12 @@ namespace ActionTool public int frame;
}
+ public struct EventParam
+ {
+ public string eventName;
+ public int frame;
+ }
+
public class ActionPreviewEditor : EditorWindow
{
Texture m_UITextureStop;
@@ -100,6 +107,7 @@ namespace ActionTool GUI.enabled = ActionManager.animationData != null;
GUI_Toolbar_NewHurtBox(ref x, ref y);
GUI_Toolbar_NewHitBox(ref x, ref y);
+ GUI_Toolbar_Detail(ref x, ref y);
GUI_Toolbar_Delete(ref x, ref y);
GUI.enabled = true;
@@ -306,11 +314,6 @@ namespace ActionTool ui.DrawVerticalLineFast(kTimeLineViewXOffset + bgRect.width * action.curAnimTimeNormal, y, y + ActionManager.eventAndBoxCount * kFrameHeight, Color.red);
}
- void GUI_Events()
- {
-
- }
-
void GUI_Boxes()
{
float y = m_GridY + ActionManager.kMaxEventsPerFrame * kFrameHeight;
@@ -319,7 +322,7 @@ namespace ActionTool return;
DrawBoxList(animData.hurtBoxes, ref y, Color.green);
DrawBoxList(animData.hitBoxes, ref y, Color.red);
- DrawBoxFrameMenuItem();
+ GenericMenu_BoxFrame();
}
void DrawBoxList(List<ColliderData> boxes, ref float y, Color c)
@@ -374,10 +377,10 @@ namespace ActionTool bool frameSelect = GUI.Toggle(frameRect, frameSelected, "",styles.keyFrameButton);
if(!frameSelected && frameSelect)
{
- ActionManager.OnSelectBox(box);
- ActionManager.OnSelectColliderFrame(frame);
- }
- else if(frameSelect && !frameSelect)
+ ActionManager.OnSelectBox(box);
+ ActionManager.OnSelectColliderFrame(frame);
+ }
+ else if(frameSelect && !frameSelect)
{
ActionManager.OnSelectColliderFrame(null);
}
@@ -404,7 +407,7 @@ namespace ActionTool GUI.color = prevColor;
}
- void DrawBoxFrameMenuItem()
+ void GenericMenu_BoxFrame()
{
Event e = Event.current;
if (e.button != 1 || !e.isMouse || e.type != EventType.MouseDown)
@@ -470,6 +473,18 @@ namespace ActionTool x += kToolbarControlSize;
}
+ void GUI_Toolbar_Detail(ref float x, ref float y)
+ {
+ x += kToolbarControlMargin;
+ Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
+ GUI.enabled = ActionManager.colliderData != null;
+ if (GUI.Button(rect, new GUIContent(styles.infoIcon, "Detail")))
+ {
+ }
+ GUI.enabled = true;
+ x += kToolbarControlSize;
+ }
+
void GUI_Toolbar_Delete(ref float x, ref float y)
{
x += kToolbarControlMargin;
@@ -498,13 +513,102 @@ namespace ActionTool {
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_Events()
+ {
+ DrawAllEvents();
+ GenericMenu_Event();
+ }
+
+ void DrawAllEvents()
+ {
+ if (ActionManager.animationData == null)
+ return;
+
+ List<int> 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<int>.Release(frames);
+ }
+
+ void DrawFrameEvent(int frame)
+ {
+ List<AnimationEventBase> 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;
+ Vector2 pos = new Vector2(kTimeLineViewXOffset + frame * kFrameWidth, y);
+ Rect frameRect = new Rect(pos.x, pos.y, kFrameWidth, kFrameHeight);
+ bool isSelect = ActionManager.animationEvent == animEvent;
+ bool frameSelect = GUI.Toggle(frameRect, isSelect, "E", styles.keyFrameButton);
+ if(!isSelect && frameSelect)
+ {
+ ActionManager.OnSelectAnimationEvent(animEvent);
+ }
+ y += kFrameHeight;
+ }
+ ListPool<AnimationEventBase>.Release(animEvents);
+ }
+
+ void GenericMenu_Event()
+ {
+ Event e = Event.current;
+ if (e.button != 1 || !e.isMouse || e.type != EventType.MouseDown)
+ return;
+
+ ActionData action = ActionManager.actionData;
+ Vector2 position = Event.current.mousePosition;
+ Rect eventRegion = new Rect(kTimeLineViewXOffset, m_GridY, action.totalFrame * kFrameWidth, TimelineEvent.kMaxEventsPerFrame * 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(TimelineEvent.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, null);
+ eventMenu.ShowAsContext();
+ }
+
+ }
}
\ No newline at end of file |