From 98f31f197a126850a5878cd6e583ae6dbf64ab3d Mon Sep 17 00:00:00 2001 From: chai Date: Wed, 15 Sep 2021 12:50:26 +0800 Subject: *rename --- .../ActionTool/Editor/ActionColliderEditor.cs | 346 +++++++ .../ActionTool/Editor/ActionColliderEditor.cs.meta | 11 + .../ActionTool/Editor/ActionColliderFrameEditor.cs | 109 +++ .../Editor/ActionColliderFrameEditor.cs.meta | 11 + Assets/Tools/ActionTool/Editor/ActionData.cs | 390 ++++++++ Assets/Tools/ActionTool/Editor/ActionData.cs.meta | 11 + Assets/Tools/ActionTool/Editor/ActionEditor.cs | 262 +++++ .../Tools/ActionTool/Editor/ActionEditor.cs.meta | 11 + .../Tools/ActionTool/Editor/ActionEditorStyles.cs | 171 ++++ .../ActionTool/Editor/ActionEditorStyles.cs.meta | 11 + Assets/Tools/ActionTool/Editor/ActionEditorUI.cs | 99 ++ .../Tools/ActionTool/Editor/ActionEditorUI.cs.meta | 11 + .../Tools/ActionTool/Editor/ActionEventEditor.cs | 368 +++++++ .../ActionTool/Editor/ActionEventEditor.cs.meta | 11 + Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs | 47 + .../ActionTool/Editor/ActionInfoEditor.cs.meta | 11 + Assets/Tools/ActionTool/Editor/ActionManager.cs | 548 +++++++++++ .../Tools/ActionTool/Editor/ActionManager.cs.meta | 11 + Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs | 40 + .../ActionTool/Editor/ActionNoteEditor.cs.meta | 11 + .../Tools/ActionTool/Editor/ActionPreviewEditor.cs | 1027 ++++++++++++++++++++ .../ActionTool/Editor/ActionPreviewEditor.cs.meta | 11 + .../ActionTool/Editor/ActionRootMotionEditor.cs | 121 +++ .../Editor/ActionRootMotionEditor.cs.meta | 11 + .../ActionTool/Editor/ActionToolSettingsEditor.cs | 62 ++ .../Editor/ActionToolSettingsEditor.cs.meta | 11 + .../ActionTool/Editor/AnimationCurveEditor.cs | 54 + .../ActionTool/Editor/AnimationCurveEditor.cs.meta | 11 + .../ActionTool/Editor/AnimationParameterEditor.cs | 54 + .../Editor/AnimationParameterEditor.cs.meta | 11 + .../ActionTool/Editor/AnimationPropertyEditor.cs | 54 + .../Editor/AnimationPropertyEditor.cs.meta | 11 + .../ActionTool/Editor/AnimationToggleEditor.cs | 69 ++ .../Editor/AnimationToggleEditor.cs.meta | 11 + 34 files changed, 4008 insertions(+) create mode 100644 Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionData.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionData.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionEditorUI.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionEditorUI.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionEventEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionEventEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionManager.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionManager.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs.meta create mode 100644 Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs create mode 100644 Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs.meta (limited to 'Assets/Tools/ActionTool/Editor') diff --git a/Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs b/Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs new file mode 100644 index 00000000..adb8819f --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs @@ -0,0 +1,346 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + // 编辑事件 + public class ActionColliderEditor : EditorWindow + { + EditorWindow sceneView; + ActionEditorStyles styles; + + ColliderBox collider; + + Dictionary m_Foldout = new Dictionary (); + + int indent = 0; + + private void OnEnable() + { + titleContent = new GUIContent("Collider Editor"); + m_Foldout.Clear(); + } + + private void OnDisable() + { + m_Foldout.Clear(); + ActionManager.colliderData = null; + ActionManager.ColliderWindow = null; + if(ActionManager.PreviewWindow != null) + ActionManager.PreviewWindow.Repaint(); + } + + private void Update() + { + } + + Vector2 scroll; + private void OnGUI() + { + if (ActionManager.colliderData == null) + { + this.Close(); + return; + } + + collider = ActionManager.colliderData.collider; + if (collider == null) + return; + + if (styles == null) styles = ActionEditorStyles.Get(); + + GUILayout.Space(2); + + EditorGUILayout.LabelField(collider.type.ToString() + " " + ActionManager.colliderIndex, styles.textBoldBig, GUILayout.Height(25)); + + GUILayout.Space(2); + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Save")) + { + + } + if (GUILayout.Button("Revert")) + { + + } + Color prevColor = GUI.backgroundColor; + GUI.backgroundColor = Color.red; + if (GUILayout.Button("Delete")) + { + ActionManager.DeleteCurBox(); + } + GUI.backgroundColor = prevColor; + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(5); + + scroll = EditorGUILayout.BeginScrollView(scroll); + + Type type = collider.GetType(); + FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + if (fields != null && fields.Length > 0) + { + int collliderType = -1; + FoldoutAttribute foldout = null; + int foldoutElementCount = 0; + for (int i = 0; i < fields.Length; ++i) + { + FieldInfo field = fields[i]; + string name = field.Name + " (" + field.FieldType.Name + ")"; + string tooltip = ""; + bool skip = false; + foreach (var attr in field.GetCustomAttributes()) + { + if (attr.GetType() == typeof(ColliderTypeAttribute)) + { + ColliderTypeAttribute t = attr as ColliderTypeAttribute; + collliderType = (int)t.type; + } + } + if (collliderType != -1 && collliderType != (int)collider.type) + { + skip = true; + } + if (skip) + { + continue; + } + foreach (var attr in field.GetCustomAttributes()) + { + if (attr.GetType() == typeof(WhenAttribute)) + { + WhenAttribute when = attr as WhenAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((float)condition.GetValue(collider) != when.value) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(WhenNotAttribute)) + { + WhenNotAttribute when = attr as WhenNotAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((float)condition.GetValue(collider) == when.value) + { + skip = true; + break; + } + } + else if(attr.GetType() == typeof(IfAttribute)) + { + IfAttribute when = attr as IfAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if (!(bool)condition.GetValue(collider)) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(IfNotAttribute)) + { + IfNotAttribute when = attr as IfNotAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((bool)condition.GetValue(collider)) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(FoldoutAttribute)) + { + if(collliderType == -1 || collliderType == (int)collider.type) + { + foldout = attr as FoldoutAttribute; + if (!m_Foldout.ContainsKey(foldout.title)) + m_Foldout.Add(foldout.title, false); + m_Foldout[foldout.title] = EditorGUILayout.Foldout(m_Foldout[foldout.title], foldout.title); + foldoutElementCount = 0; + indent = 13; + } + } + else if (attr.GetType() == typeof(CommentAttribute)) + { + CommentAttribute comment = attr as CommentAttribute; + GUIStyle style = GUI.skin.GetStyle("Label"); + TextAnchor preanchor = style.alignment; + style.alignment = comment.alignment; + GUI_Label(new GUIContent(comment.comment), style); + style.alignment = preanchor; + } + } + if(foldout != null && (++foldoutElementCount) <= foldout.count) + { + skip |= !m_Foldout[foldout.title]; + } + if (skip) + { + if (foldout != null && foldoutElementCount == foldout.count) + { + foldout = null; + foldoutElementCount = 0; + indent = 0; + } + GUI.enabled = true; + continue; + } + + foreach (var attr in field.GetCustomAttributes()) + { + if (attr.GetType() == typeof(TooltipAttribute)) + { + TooltipAttribute tooltipattr = attr as TooltipAttribute; + if (tooltip != null) + { + tooltip = tooltipattr.tooltip; + } + } + else if (attr.GetType() == typeof(DisallowModifiyInGUI)) + { + GUI.enabled = false; + } + else if (attr.GetType() == typeof(SpaceAttribute)) + { + SpaceAttribute space = attr as SpaceAttribute; + GUILayout.Space(space.height); + } + } + + GUI_Label(new GUIContent(name, tooltip), styles.textBold); + + if (field.FieldType == typeof(Vector3)) + { + field.SetValue(collider, GUI_Vector3((Vector3)field.GetValue(collider))); + } + else if (field.FieldType == typeof(Vector2)) + { + field.SetValue(collider, GUI_Vector2((Vector2)field.GetValue(collider))); + } + else if(field.FieldType == typeof(Color)) + { + field.SetValue(collider, GUI_Color((Color)field.GetValue(collider))); + } + else if (field.FieldType == typeof(string)) + { + field.SetValue(collider, GUI_String((string)field.GetValue(collider))); + } + else if (field.FieldType == typeof(bool)) + { + field.SetValue(collider, GUI_Bool((bool)field.GetValue(collider))); + } + else if (field.FieldType == typeof(AnimationCurve)) + { + field.SetValue(collider, GUI_Curve(field.GetValue(collider) as AnimationCurve)); + } + else if (field.FieldType.IsEnum) + { + field.SetValue(collider, GUI_Enum((Enum)field.GetValue(collider))); + } + else if (field.FieldType == typeof(float)) + { + field.SetValue(collider, GUI_Float((float)field.GetValue(collider))); + } + else if (field.FieldType == typeof(int)) + { + field.SetValue(collider, GUI_Int((int)field.GetValue(collider))); + } + GUI.enabled = true; + GUILayout.Space(5); + + if (foldout != null && foldoutElementCount == foldout.count) + { + foldout = null; + foldoutElementCount = 0; + indent = 0; + } + } + } + EditorGUILayout.EndScrollView(); + } + + Rect GetControlRect() + { + Rect rect = EditorGUILayout.GetControlRect(); + rect.x += indent; + rect.width -= indent; + return rect; + } + + void GUI_Label(GUIContent label, GUIStyle style) + { + Rect rect = GetControlRect(); + EditorGUI.LabelField(rect, label, style); + } + + Vector3 GUI_Vector3(Vector3 value) + { + Rect rect = GetControlRect(); + return EditorGUI.Vector3Field(rect, "", value); + } + + Vector2 GUI_Vector2(Vector2 value) + { + Rect rect = GetControlRect(); + return EditorGUI.Vector2Field(rect, "", value); + } + + string GUI_String(string value) + { + Rect rect = GetControlRect(); + return EditorGUI.TextField(rect, "", value); + } + + bool GUI_Bool(bool value) + { + Rect rect = GetControlRect(); + return GUI.Toggle(rect, value, "Check"); + } + + void GUI_Enum(string value) + { + Rect rect = GetControlRect(); + GUI.Label(rect, value); + } + + float GUI_Float(float value) + { + Rect rect = GetControlRect(); + return EditorGUI.FloatField(rect, "", value); + } + + int GUI_Int(int value) + { + Rect rect = GetControlRect(); + return EditorGUI.IntField(rect, "", value); + } + + AnimationCurve GUI_Curve(AnimationCurve curve) + { + Rect rect = GetControlRect(); + return EditorGUI.CurveField(rect, "", curve); + } + + Enum GUI_Enum(Enum enumValue) + { + Rect rect = GetControlRect(); + return EditorGUI.EnumPopup(rect, "", enumValue); + } + + Color GUI_Color(Color col) + { + Rect rect = GetControlRect(); + return EditorGUI.ColorField(rect, col); + } + + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs.meta new file mode 100644 index 00000000..2fd8e91f --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionColliderEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8507f595519bce344b9b7f27fa2f0f32 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs b/Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs new file mode 100644 index 00000000..4efd1f93 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs @@ -0,0 +1,109 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + // 编辑collider帧 + public class ActionColliderFrameEditor : EditorWindow + { + EditorWindow sceneView; + + private void OnEnable() + { + titleContent = new GUIContent("Collider Frame Editor"); + maxSize = new Vector2(300, 180); + minSize = maxSize; + + if(!sceneView) + sceneView = EditorWindow.GetWindow(); + } + + private void OnDisable() + { + // sceneView = null; + ActionManager.OnSelectColliderFrame(null); + } + + private void Update() + { + } + + private void OnGUI() + { + var frame = ActionManager.editColliderFrame; + if (frame == null) + { + this.Close(); + return; + } + + GUI.changed = false; + + GUILayout.Space(5); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("frame: "); + EditorGUILayout.LabelField(frame.frame.ToString()); + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField("active: "); + frame.active = EditorGUILayout.Toggle(frame.active); + EditorGUILayout.EndHorizontal(); + + EditorGUILayout.LabelField("position: "); + frame.position = EditorGUILayout.Vector3Field("", frame.position); + + EditorGUILayout.LabelField("size: "); + frame.size = EditorGUILayout.Vector3Field("", frame.size); + + GUILayout.Space(10); + + GUILayout.BeginHorizontal(); + + if(GUILayout.Button("Left abit")) + { + ActionData action = ActionManager.actionData; + float normaltime = frame.frame / action.totalFrame; + action.curAnimTimeNormal = normaltime - 0.001f; + } + + if (GUILayout.Button("Right abit")) + { + ActionData action = ActionManager.actionData; + float normaltime = frame.frame / action.totalFrame; + action.curAnimTimeNormal = normaltime + 0.001f; + } + + if (GUILayout.Button("Current")) + { + ActionData action = ActionManager.actionData; + float normaltime = frame.frame / action.totalFrame; + action.curAnimTimeNormal = normaltime; + } + + GUILayout.EndHorizontal(); + + GUILayout.Space(10); + + Color prevColor = GUI.backgroundColor; + GUI.backgroundColor = Color.red; + if (GUILayout.Button("Delete")) + { + ActionManager.DeleteCurFrame(); + } + GUI.backgroundColor = prevColor; + + if (GUI.changed) + { + if (sceneView != null) + sceneView.Repaint(); + if (ActionManager.PreviewWindow != null) + ActionManager.PreviewWindow.Repaint(); + } + } + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs.meta new file mode 100644 index 00000000..393c3deb --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionColliderFrameEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 3fcd174d4fc741a4986f1a08413e6ada +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionData.cs b/Assets/Tools/ActionTool/Editor/ActionData.cs new file mode 100644 index 00000000..3da31388 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionData.cs @@ -0,0 +1,390 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using System.Linq; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + // 正在编辑的动画 + public class ActionData + { + private Animator m_Animator; + private AnimationClip m_Clip; + + private AnimationData m_AnimData; // asset + + private List m_EventList { get { return m_AnimData != null ? m_AnimData.animationEvents : null; } } + + private AnimationEventBase m_CurEventInfo; // 当前正在编辑的event + + private TimelineEventProxy m_TimelineEventProxy; + + private static List m_Projectiles = new List(); + private static List m_ParticleSystems = new List(); + + #region metadata + private float m_TotalFrame; //timeline采样的总帧数 + public float totalFrame { get { return m_TotalFrame; } } + private float m_SampleRate; // 每次采样的时间间隔 + public float sampleRate { get { return m_SampleRate; } } + #endregion + + public float curAnimFrame { get { return m_CurAnimFrame; } } + + public float curAnimTimeNormal + { + get + { + return m_CurAnimFrame / m_TotalFrame; + } + set + { + float v = value % m_TotalFrame; + m_CurAnimFrame = v * m_TotalFrame; + } + } + + private int m_PrevFrame; + private float m_CurAnimFrame; + private double m_PrevLocalTime; + private float m_PrevNormalTime; + + private int m_PrevAnimEventFrame; // 上次的帧数(整数) + + private bool m_NotApplyCurves; + public bool applyCurves { get { return !m_NotApplyCurves; } set { m_NotApplyCurves = !value; } } // 是否开启curve控制速度 + private bool m_NotApplyCurve; + public bool applyCurve { get { return !m_NotApplyCurve; } set { m_NotApplyCurve = !value; } } // 是否开启curve控制速度 + private bool m_NotApplyRM; + public bool applyRootMotion { get { return !m_NotApplyRM; } set { m_NotApplyRM = !value; } } + + private const string kStateName = "Action"; + + public RootMotionData rootMotion { get{ return m_RootMotion; } } + private RootMotionData m_RootMotion; + + public string rootMotionPath + { + get + { + return AssetDatabase.GetAssetPath(m_RootMotion); + } + } + + public void Initialize(Animator animator, AnimationClip clip, RootMotionData rootmotion) + { + m_Animator = animator; + m_Clip = clip; + if(m_Clip != null) + { + m_TotalFrame = m_Clip.length * ActionManager.FPS; + m_SampleRate = m_Clip.length / m_TotalFrame; + } + m_PrevFrame = -1; + m_CurAnimFrame = 0; + m_PrevLocalTime = 0; + m_Animator.Play(kStateName, 0, 0); + m_RootMotion = rootmotion; + + m_TimelineEventProxy = new TimelineEventProxy(ActionManager.unitRoot.transform); + m_TimelineEventProxy.isInEditMode = true; + m_TimelineEventProxy.registerProjectile = RegisterProjectile; + m_TimelineEventProxy.registerParticleSystem = RegisterParticleSystem; + } + + public void SetCurrentAnimTime(float time) + { + m_CurAnimFrame = time; + } + + public void SetCurrentEvent(int index) + { + if(index < 0) + { + m_CurEventInfo = null; + } + else if(m_EventList != null) + { + m_CurEventInfo = m_EventList[index]; + } + else + { + m_CurEventInfo = null; + } + } + + public AnimationEventBase GetEvent(int index) + { + if(m_EventList != null && index >= 0 && index < m_EventList.Count) + { + return m_EventList[index]; + } + else + { + return null; + } + } + + public int GetEventCount() + { + if (m_EventList != null) + return m_EventList.Count; + return 0; + } + + public void RemoveCurrentEvent() + { + if(m_EventList != null) + { + m_EventList.Remove(m_CurEventInfo); + m_CurEventInfo = null; + } + } + + public void RemoveAllEvent() + { + if(m_EventList != null) + { + m_EventList.Clear(); + m_CurEventInfo = null; + } + } + + public void StartFrame() + { + m_PrevFrame = -1; + m_PrevLocalTime = EditorApplication.timeSinceStartup; + } + + public void UpdateFrame() + { + float dt = (float)(EditorApplication.timeSinceStartup - m_PrevLocalTime); + + if (ActionManager.IsPlay) + { + float deltaFrame = dt * ActionManager.FPS * ActionManager.Speed; + + if (applyCurve) + { + float normalizeTime = m_CurAnimFrame / m_TotalFrame; + AnimationData animData = ActionManager.animationData; + if (animData) + { + AnimationCurve curve = animData.speedCurve; + deltaFrame *= curve.Evaluate(normalizeTime); + } + } + + m_CurAnimFrame += deltaFrame; + + if (m_CurAnimFrame > m_TotalFrame) + { + ActionManager.ResetUnitRootPosAndRot(); + m_PrevNormalTime = 0; + } + m_CurAnimFrame %= m_TotalFrame; + } + + UpdateParticles(dt); + + UpdateProjectiles(dt); + + ActionManager.gizmos.SetCurAnimFrame(m_CurAnimFrame); + + SampleFrame(); + + RunEvent(); + + m_PrevLocalTime = EditorApplication.timeSinceStartup; + } + + // 播放当前帧 + public void SampleFrame() + { + if (m_Animator == null) + return; + + float normalizeTime = m_CurAnimFrame / m_TotalFrame; + + if(applyRootMotion) + { + var animData = ActionManager.animationData; + bool overrideRM = animData != null && animData.overrideRootMotion == true; + + if(!overrideRM && m_RootMotion) + { + // Action Tool这里需要转换一下root motion的轴 + ActionManager.unitRoot.transform.position = RootMotionUtility.ExchangeXZ(m_RootMotion.GetRootMotion(normalizeTime)); + } + else if(overrideRM) + { + if(!ActionRootMotionEditor.IsRecord) + { + ActionManager.unitRoot.transform.position = animData.rootMotionOverrideData.GetPosition(m_CurAnimFrame); + } + else // 只在第一次播到这一帧的时候设置位置,否则场景里没法编辑位置 + { + int curAnimEventFrame = (int)m_CurAnimFrame; + normalizeTime = curAnimEventFrame / m_TotalFrame; + if (curAnimEventFrame != m_PrevAnimEventFrame) + { + ActionManager.unitRoot.transform.position = animData.rootMotionOverrideData.GetPosition(curAnimEventFrame); + } + m_PrevAnimEventFrame = curAnimEventFrame; + } + } + } + + m_Animator.speed = 1; + m_Animator.Play(kStateName, 0, normalizeTime); + m_Animator.Update(0); + m_Animator.speed = 0; + + } + + public int GetCurrentFrame() + { + float animTime = sampleRate * m_CurAnimFrame; + int curFrame = Mathf.RoundToInt(animTime * ActionManager.FPS); + return curFrame; + } + + public void RunEvent() + { + if (m_TimelineEventProxy != null) + m_TimelineEventProxy.ExecuteAnimationEvents(ActionManager.animationData, m_CurAnimFrame); + } + + public void CreateEvent(TimelineEventProxy.EEventType eventtype, int startFrame) + { + var classes = Assembly + .GetAssembly(typeof(AnimationEventBase)) + .GetTypes() + .Where(t => t.IsSubclassOf(typeof(AnimationEventBase))); + Type type = null; + foreach (var itor in classes) + { + string name = itor.Name; + if(itor.Name == eventtype.ToString()) + { + type = itor; + break; + } + } + if(type != null) + { + var e = Activator.CreateInstance(type) as AnimationEventBase; + //e.type = eventtype; + e.startFrame = startFrame; + AddEvent(e); + } + else + { + Debug.LogError("[ActionTool] 没有对应类型的event" + eventtype.ToString()); + } + } + + public void AddEvent(AnimationEventBase evnt) + { + if (m_AnimData == null || m_EventList == null) + { + Debug.LogError("[ActionTool] 没有对应的action数据,是否在" + ActionManager.unitAnimationDataFolder + "创建"); + return; + } + m_EventList.Add(evnt); + } + + public void SaveActionData() + { + if (m_AnimData == null) + return; + EditorUtility.SetDirty(m_AnimData); + AssetDatabase.SaveAssets(); + } + + public void Clear() + { + m_Animator = null; + m_Clip = null; + m_AnimData = null; + m_CurEventInfo = null; + m_TotalFrame = 0; + m_CurAnimFrame = 0; + m_PrevFrame = 0; + m_PrevLocalTime = 0; + m_SampleRate = 0; + } + + public static void RegisterProjectile(Projectile projectile) + { + m_Projectiles.Add(projectile); + } + + public static void RegisterParticleSystem(FxClear vfx) + { + m_ParticleSystems.Add(vfx); + } + + void UpdateProjectiles(float dt) + { + List removed = ListPool.Get(); + // 更新projectile + for (int i = 0; i < m_Projectiles.Count; ++i) + { + if (m_Projectiles[i] == null) + continue; + m_Projectiles[i].Update(dt); + if (m_Projectiles[i] != null) + { + TransformEx.DoRecursively(m_Projectiles[i].transform, (t) => { + ParticleSystem ps = t.GetComponent(); + if (ps != null) + { + ps.Simulate(m_Projectiles[i].time); + } + }, true); + } + else + { + removed.Add(m_Projectiles[i]); + } + } + ListPool.Release(removed); + } + + void UpdateParticles(float dt) + { + List removed = ListPool.Get(); + // 更新粒子系统 + for (int i = 0; i < m_ParticleSystems.Count; ++i) + { + if (m_ParticleSystems[i] == null) + continue; + if (m_ParticleSystems[i] != null) + { + m_ParticleSystems[i].UpdateFunc(dt); + if (m_ParticleSystems[i] != null) + { + TransformEx.DoRecursively(m_ParticleSystems[i].transform, (t) => { + ParticleSystem ps = t.GetComponent(); + if (ps != null) + { + ps.Simulate(m_ParticleSystems[i].time); + } + }, true); + } + else + { + removed.Add(m_ParticleSystems[i]); + } + } + } + ListPool.Release(removed); + } + + } + +} diff --git a/Assets/Tools/ActionTool/Editor/ActionData.cs.meta b/Assets/Tools/ActionTool/Editor/ActionData.cs.meta new file mode 100644 index 00000000..4e6fe1ca --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionData.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: eccac258cc2e3a94cb5b1c569b96c366 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionEditor.cs b/Assets/Tools/ActionTool/Editor/ActionEditor.cs new file mode 100644 index 00000000..b06ef89b --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEditor.cs @@ -0,0 +1,262 @@ +using System.IO; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; +using UnityEditor.SceneManagement; + +namespace ActionTool +{ + + public class ActionEditor : EditorWindow + { + [MenuItem("Erika/ActionTool/Open")] + static void OpenTools() + { + ActionManager.AnimationWindow = GetWindow(); + } + + string m_SearchText = ""; + ActionEditorStyles styles; + ActionEditorUI ui; + int currentPickerWindow; + + IEnumerator coLoadAnimationAssets; + Dictionary animationAssets = new Dictionary(); + + public void OnEnable() + { + titleContent = new GUIContent("Action Editor"); + + EditorApplication.update += OnUpdate; + ActionManager.onSelectObj += OnSelectObj; + } + + void OnUpdate() + { + if(coLoadAnimationAssets != null) + { + if (!coLoadAnimationAssets.MoveNext()) + { + coLoadAnimationAssets = null; + } + } + } + + public void OnDisable() + { + EditorApplication.update -= OnUpdate; + ActionManager.onSelectObj -= OnSelectObj; + } + + public void OnGUI() + { + if (styles == null) styles = ActionEditorStyles.Get(); + if (ui == null) ui = ActionEditorUI.Get(); + if (ActionManager.CurrentUnit == null) + ActionManager.Release(); + + GUILayout.Space(5); + GUI_SelectUnit(); + GUILayout.Space(5); + GUI_AnimationList(); + GUILayout.Space(5); + } + + private void GUI_SelectUnit() + { + GUILayout.BeginHorizontal(); + + GameObject selectObj = EditorGUILayout.ObjectField(ActionManager.CurrentUnit, typeof(GameObject), false, GUILayout.Width(position.width - 160)) as GameObject; + + if (selectObj != null && selectObj != ActionManager.CurrentUnit) + { + ActionManager.OnSelectObj(selectObj); + if (ActionManager.AnimationWindow != null) + { + ActionManager.AnimationWindow.Repaint(); + } + } + + if (GUILayout.Button("Select", GUILayout.Width(70))) + { + currentPickerWindow = EditorGUIUtility.GetControlID(FocusType.Passive) + 100; + EditorGUIUtility.ShowObjectPicker(ActionManager.CurrentUnit, false, "l:UnitPrefab", currentPickerWindow); + } + + string commandName = Event.current.commandName; + if(/*commandName.Equals("ObjectSelectorUpdated") || */commandName.Equals("ObjectSelectorClosed")) + { + GameObject go = EditorGUIUtility.GetObjectPickerObject() as GameObject; + if (/*go != null && */ActionManager.CurrentUnit != go) + { + ActionManager.OnSelectObj(go); + this.Repaint(); + } + } + + if (GUILayout.Button("Reimport", GUILayout.Width(70))) + { + ActionManager.OnSelectObj(ActionManager.CurrentUnit); + } + + GUILayout.EndHorizontal(); + + //var scene = EditorSceneManager.GetActiveScene(); + //if (scene == null || scene.path != ActionManager.scenePath) + //{ + // if(GUILayout.Button("打开ActionToolScene")) + // { + // EditorSceneManager.OpenScene(ActionManager.scenePath); + // } + //} + + if (ActionManager.CurrentUnit == null) + { + EditorGUILayout.HelpBox("选择角色prefab", MessageType.Warning); + } + + } + + private Vector2 m_AnimtionListScroll; + private void GUI_AnimationList() + { + if (!ActionManager.HasSelectObj()) + return; + + EditorGUILayout.LabelField("Animation List"); + + m_SearchText = GUILayout.TextField(m_SearchText, "SearchTextField", GUILayout.Width(position.width - 20)).ToLower(); + + string animFolder = ActionManager.unitAnimationClipFolder; + + string[] animfiles = Directory.GetFiles(animFolder); + + if (animfiles != null && animfiles.Length > 0) + { + GUIStyle style = GUI.skin.GetStyle("Button"); + TextAnchor prevAnchor = style.alignment; + TextClipping prevClipping = style.clipping; + bool prevRichText = style.richText; + style.alignment = TextAnchor.MiddleCenter; + style.clipping = TextClipping.Clip; + style.richText = false; + + m_AnimtionListScroll = EditorGUILayout.BeginScrollView(m_AnimtionListScroll); + + for (int i = 0; i < animfiles.Length; ++i) + { + string file = animfiles[i]; + if (file.Contains(".meta")) + continue; + string animName = Path.GetFileNameWithoutExtension(file); + bool show = m_SearchText == string.Empty || m_SearchText == "" || animName.ToLower().Contains(m_SearchText); + if (!show) + continue; + bool bChecked = ActionManager.CurrentAnimationName == animName; + EditorGUILayout.BeginHorizontal(); + + bool check = GUILayout.Toggle(bChecked, animName, style, GUILayout.Width(position.width - 60)); + if (check && ActionManager.CurrentAnimationName != animName) + ActionManager.OnSelectAnimation(animName); + + bool isFavorite = false; + if (animationAssets != null && animationAssets.ContainsKey(file)) + { + isFavorite = IsFavoritAnimation(animationAssets[file]); + } + if ((!animationAssets.ContainsKey(file) || animationAssets[file] == null) && coLoadAnimationAssets == null) + { + coLoadAnimationAssets = CoLoadAnimationAssets(); + } + Color bgColor = GUI.backgroundColor; + GUI.backgroundColor = isFavorite ? Color.yellow : Color.gray; + if (GUILayout.Button("", styles.starButton, GUILayout.Width(12), GUILayout.Height(13))) + { + isFavorite = !isFavorite; + if(animationAssets.ContainsKey(file)) + { + if(!isFavorite) + { + AssetDatabase.SetLabels(animationAssets[file], new string[0]); + } + else + { + AssetDatabase.SetLabels(animationAssets[file], new string[1] { "GoodAnimation" }); + } + } + } + GUI.backgroundColor = bgColor; + + if (GUILayout.Button("", styles.selectObj, GUILayout.Width(15), GUILayout.Height(15))) + { + ui.SelectObject(file); + } + + EditorGUILayout.EndHorizontal(); + } + + EditorGUILayout.EndScrollView(); + + style.alignment = prevAnchor; + style.clipping = prevClipping; + style.richText = prevRichText; + } + } + + bool IsFavoritAnimation(Object animationFile) + { + var labels = AssetDatabase.GetLabels(animationFile); + for (int j = 0; j < labels.Length; ++j) + { + if (labels[j] == "GoodAnimation") + return true; + } + return false; + } + + IEnumerator CoLoadAnimationAssets() + { + if (!ActionManager.HasSelectObj()) + yield break; + + if (animationAssets != null) + animationAssets.Clear(); + else + animationAssets = new Dictionary(); + + string animFolder = ActionManager.unitAnimationClipFolder; + + string[] animfiles = Directory.GetFiles(animFolder); + + for (int i = 0; i < animfiles.Length; ++i) + { + string file = animfiles[i]; + if (file.Contains(".meta")) + continue; + var animFile = AssetDatabase.LoadMainAssetAtPath(file); + if (animationAssets.ContainsKey(file)) + { + animationAssets[file] = animFile; + } + else + { + animationAssets.Add(file, animFile); + } + if (IsFavoritAnimation(animFile)) + { + this.Repaint(); + } + yield return null; + } + } + + void OnSelectObj(params object[] objs) + { + animationAssets.Clear(); + coLoadAnimationAssets = CoLoadAnimationAssets(); + } + + } + +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionEditor.cs.meta new file mode 100644 index 00000000..4c2ff1fe --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ce7158026a0c5f74eb9acc71dea8288c +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs b/Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs new file mode 100644 index 00000000..08993560 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs @@ -0,0 +1,171 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + internal class ActionEditorStyles + { + public GUIStyle textBoldBig; + public GUIStyle textBoldSmall; + public GUIStyle textBoldSmallMid; + public GUIStyle textBold; + public GUIStyle selectObj; + public GUIStyle textSmall; + public GUIStyle textMiddle; + public GUIStyle textMiddleBold; + public GUIStyle boxToggle; + public GUIStyle keyFrameButton; + + public GUIStyle toggleSmallBold; + + public GUIStyle foldout; + + public GUIStyle keyButton; + + public GUIStyle starButton; + public GUIStyle starButton2; + + public GUIStyle infoButton; + + public Texture2D selectIcon; + public Texture2D keyFrameIcon; + public Texture2D addFileIcon; + public Texture2D saveFileIcon; + public Texture2D deleteIcon; + public Texture2D infoIcon; + public Texture2D keyIcon; + public Texture2D recordIcon; + public Texture2D starIcon; + public Texture2D starIcon2; + + private static ActionEditorStyles s_instance; + public static ActionEditorStyles Get() + { + bool flag = s_instance == null; + if (flag) + { + s_instance = new ActionEditorStyles(); + } + return s_instance; + } + + private ActionEditorStyles() + { + selectIcon = (Texture2D)Resources.Load("select_white"); + selectIcon.filterMode = FilterMode.Point; + + //selectIcon = EditorGUIUtility.FindTexture("ClothInspector.SelectTool"); + + keyFrameIcon = EditorGUIUtility.FindTexture("animationkeyframe"); + addFileIcon = EditorGUIUtility.FindTexture("d_Collab.FileAdded"); + saveFileIcon = EditorGUIUtility.FindTexture("d_Collab.FileUpdated"); + deleteIcon = EditorGUIUtility.FindTexture("d_P4_DeletedLocal"); + infoIcon = EditorGUIUtility.FindTexture("UnityEditor.InspectorWindow"); + keyIcon = EditorGUIUtility.FindTexture("d_animationkeyframe"); + starIcon = EditorGUIUtility.FindTexture("Favorite"); + starIcon2 = EditorGUIUtility.FindTexture("Favorite Icon"); + recordIcon = EditorGUIUtility.FindTexture("d_Animation.Record"); + + InitStyle(out textBoldBig, GUI.skin.label, s => { + s.fontStyle = FontStyle.Bold; + s.fontSize = 18; + s.alignment = TextAnchor.MiddleCenter; + }); + + InitStyle(out textBold, GUI.skin.label, s => { + s.fontStyle = FontStyle.Bold; + }); + InitStyle(out textBoldSmall, GUI.skin.label, s => { + s.fontSize = 9; + s.fontStyle = FontStyle.Bold; + }); + InitStyle(out textBoldSmallMid, GUI.skin.label, s => { + s.fontSize = 9; + s.fontStyle = FontStyle.Bold; + s.alignment = TextAnchor.MiddleCenter; + }); + InitStyle(out selectObj, GUI.skin.button, s => { + s.normal.background = selectIcon; + s.active.background = selectIcon; + s.focused.background = selectIcon; + s.hover.background = selectIcon; + }); + InitStyle(out textSmall, GUI.skin.label, s => { + s.fontSize = 8; + }); + InitStyle(out textMiddle, GUI.skin.label, s => { + s.fontSize = 10; + }); + InitStyle(out textMiddleBold, GUI.skin.label, s => { + s.fontSize = 10; + s.fontStyle = FontStyle.Bold; + }); + InitStyle(out boxToggle, EditorStyles.miniButtonLeft, s => { + s.fontSize = 8; + s.normal.textColor = Color.white; + s.onNormal.textColor = Color.white; + s.active.textColor = Color.white; + s.onActive.textColor = Color.white; + }); + InitStyle(out keyFrameButton, GUI.skin.button, s => { + s.fontSize = 9; + s.clipping = TextClipping.Overflow; + s.alignment = TextAnchor.MiddleCenter; + s.fontStyle = FontStyle.Bold; + s.normal.textColor = Color.yellow; + s.active.textColor = Color.yellow; + s.focused.textColor = Color.yellow; + s.hover.textColor = Color.yellow; + }); + InitStyle(out keyButton, GUI.skin.button, s => + { + s.normal.background = keyIcon; + s.active.background = keyIcon; + s.hover.background = keyIcon; + s.focused.background = keyIcon; + }); + InitStyle(out starButton, GUI.skin.button, s => + { + s.normal.background = starIcon; + s.active.background = starIcon; + s.hover.background = starIcon; + s.focused.background = starIcon; + }); + InitStyle(out starButton2, GUI.skin.button, s => + { + s.normal.background = starIcon2; + s.active.background = starIcon2; + s.hover.background = starIcon2; + s.focused.background = starIcon2; + }); + InitStyle(out infoButton, GUI.skin.button, s => + { + s.normal.background = infoIcon; + s.active.background = infoIcon; + s.hover.background = infoIcon; + s.focused.background = infoIcon; + }); + InitStyle(out toggleSmallBold, GUI.skin.toggle, s => { + s.fontSize = 10; + //s.fontStyle = FontStyle.Bold; + }); + InitStyle(out foldout, EditorStyles.foldout, s => { + }); + } + + private delegate void Initter(GUIStyle style); + private static void InitStyle(out GUIStyle normal, GUIStyle other, Initter initter) + { + normal = new GUIStyle(other); + initter(normal); + } + private static void InitStyle(out GUIStyle normal, Initter initter) + { + normal = new GUIStyle(); + initter(normal); + } + + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs.meta b/Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs.meta new file mode 100644 index 00000000..8adef727 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEditorStyles.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 13b6cd36eabea4b42aadd96b3a816fe3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionEditorUI.cs b/Assets/Tools/ActionTool/Editor/ActionEditorUI.cs new file mode 100644 index 00000000..a1e2ba36 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEditorUI.cs @@ -0,0 +1,99 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + internal class ActionEditorUI + { + static ActionEditorUI s_instance; + + static Material m_material; + + public Material defaultUIMaterail { get { return m_material; } } + + public static ActionEditorUI Get() + { + bool flag = s_instance == null; + if (flag) + { + s_instance = new ActionEditorUI(); + } + return s_instance; + } + + private ActionEditorUI() + { + m_material = new Material(Shader.Find("Hidden/Internal-Colored")); + m_material.hideFlags = HideFlags.HideAndDontSave; + } + + public void DrawVerticalLineFast(float x, float minY, float maxY, Color color) + { + // GL画线在GenericMenu弹出来时会有问题 + //bool bWin = Application.platform == RuntimePlatform.WindowsEditor; + //if (bWin) + //{ + // GL.Color(color); + // GL.Vertex(new Vector3(x - 0.5f, minY, 0f)); + // GL.Vertex(new Vector3(x + 0.5f, minY, 0f)); + // GL.Vertex(new Vector3(x + 0.5f, maxY, 0f)); + // GL.Vertex(new Vector3(x - 0.5f, maxY, 0f)); + //} + //else + //{ + // GL.Color(color); + // GL.Vertex(new Vector3(x, minY, 0f)); + // GL.Vertex(new Vector3(x, maxY, 0f)); + //} + Rect rect = new Rect(x-0.5f, minY, 1, maxY - minY); + EditorGUI.DrawRect(rect, color); + } + + public void DrawHorizontalLineFast(float y, float minX, float maxX, Color color) + { + //bool bWin = Application.platform == RuntimePlatform.WindowsEditor; + //if (bWin) + //{ + // GL.Color(color); + // GL.Vertex(new Vector3(minX, y - 0.5f, 0f)); + // GL.Vertex(new Vector3(minX, y + 0.5f, 0f)); + // GL.Vertex(new Vector3(maxX, y + 0.5f, 0f)); + // GL.Vertex(new Vector3(maxX, y - 0.5f, 0f)); + //} + //else + //{ + // GL.Color(color); + // GL.Vertex(new Vector3(minX, y, 0f)); + // GL.Vertex(new Vector3(maxX, y, 0f)); + //} + Rect rect = new Rect(minX, y - 0.5f, maxX - minX, 1); + EditorGUI.DrawRect(rect, color); + } + + public void DrawRectFrame(Rect rect, Color col) + { + DrawHorizontalLineFast(rect.y, rect.x, rect.x + rect.width, col); + DrawHorizontalLineFast(rect.y + rect.height, rect.x, rect.x + rect.width, col); + DrawVerticalLineFast(rect.x, rect.y, rect.y + rect.height, col); + DrawVerticalLineFast(rect.x + rect.width, rect.y, rect.y + rect.height, col); + } + + public void SelectObject(Object obj) + { + Selection.activeObject = obj; + EditorGUIUtility.PingObject(obj); + } + + public void SelectObject(string path) + { + Object obj = AssetDatabase.LoadAssetAtPath(path, typeof(Object)) as Object; + if(obj) + { + SelectObject(obj); + } + } + + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionEditorUI.cs.meta b/Assets/Tools/ActionTool/Editor/ActionEditorUI.cs.meta new file mode 100644 index 00000000..6d66f438 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEditorUI.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: c0e7eed5cfcabd24f980de3b9fc699ac +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs b/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs new file mode 100644 index 00000000..b0eb86cf --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs @@ -0,0 +1,368 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Reflection; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + // 编辑事件 + public class ActionEventEditor : EditorWindow + { + EditorWindow sceneView; + ActionEditorStyles styles; + AnimationEventBase animEvent; + + private void OnEnable() + { + titleContent = new GUIContent("Event Editor"); + } + + private void OnDisable() + { + ActionManager.OnSelectAnimationEvent(null); + } + + private void Update() + { + } + + Vector2 scroll; + private void OnGUI() + { + animEvent = ActionManager.animationEvent; + if (animEvent == null) + { + this.Close(); + return; + } + + if (styles == null) styles = ActionEditorStyles.Get(); + + string eventName = animEvent.name; + int frame = animEvent.startFrame; + + Type type = animEvent.GetType(); + + GUILayout.Space(2); + + EditorGUILayout.LabelField(eventName, styles.textBoldBig, GUILayout.Height(25)); + + GUILayout.Space(2); + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Save")) + { + + } + if (GUILayout.Button("Revert")) + { + + } + Color prevColor = GUI.backgroundColor; + GUI.backgroundColor = Color.red; + if (GUILayout.Button("Delete")) + { + ActionManager.DeleteEvent(animEvent); + ActionManager.OnSelectAnimationEvent(null); + } + GUI.backgroundColor = prevColor; + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(5); + + EditorGUILayout.BeginHorizontal(); + if (GUILayout.Button("Copy")) + { + ActionManager.CopyAnimationEvent(animEvent); + } + EditorGUILayout.EndHorizontal(); + + GUILayout.Space(5); + + EditorGUILayout.LabelField("startFrame (int)", styles.textBold); + GUI.enabled = false; + EditorGUILayout.TextField(frame.ToString()); + GUI.enabled = true; + + GUILayout.Space(5); + + scroll = EditorGUILayout.BeginScrollView(scroll); + + GUILayout.Space(5); + + FieldInfo[] fields = type.GetFields(BindingFlags.Public | BindingFlags.Instance | BindingFlags.DeclaredOnly); + if(fields != null && fields.Length > 0) + { + for(int i = 0; i < fields.Length; ++i) + { + FieldInfo field = fields[i]; + string name = field.Name + " (" + field.FieldType.Name + ")"; + string tooltip = ""; + bool skip = false; + bool isHDR = false; + foreach (var attr in field.GetCustomAttributes()) + { + if(attr.GetType() == typeof(TooltipAttribute)) + { + TooltipAttribute tooltipattr = attr as TooltipAttribute; + if(tooltip != null) + { + tooltip = tooltipattr.tooltip; + } + } + else if (attr.GetType() == typeof(DisallowModifiyInGUI)) + { + GUI.enabled = false; + } + else if (attr.GetType() == typeof(WhenAttribute)) + { + WhenAttribute when = attr as WhenAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if (!when.IsSatisfied((int)condition.GetValue(animEvent))) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(AndWhenAttribute)) + { + AndWhenAttribute when = attr as AndWhenAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if (!when.IsSatisfied((int)condition.GetValue(animEvent))) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(WhenNotAttribute)) + { + WhenNotAttribute when = attr as WhenNotAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((int)condition.GetValue(animEvent) == when.value) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(IfAttribute)) + { + IfAttribute when = attr as IfAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if (!(bool)condition.GetValue(animEvent)) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(IfNotAttribute)) + { + IfNotAttribute when = attr as IfNotAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((bool)condition.GetValue(animEvent)) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(SpaceAttribute)) + { + SpaceAttribute space = attr as SpaceAttribute; + GUILayout.Space(space.height); + } + else if (attr.GetType() == typeof(CommentAttribute)) + { + CommentAttribute comment = attr as CommentAttribute; + GUIStyle style = GUI.skin.GetStyle("Label"); + TextAnchor preanchor = style.alignment; + style.alignment = comment.alignment; + GUI_Label(new GUIContent(comment.comment), style); + style.alignment = preanchor; + } + else if (attr.GetType() == typeof(WhenAttribute)) + { + WhenAttribute when = attr as WhenAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((float)condition.GetValue(animEvent) != when.value) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(WhenNotAttribute)) + { + WhenNotAttribute when = attr as WhenNotAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((float)condition.GetValue(animEvent) == when.value) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(IfAttribute)) + { + IfAttribute when = attr as IfAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if (!(bool)condition.GetValue(animEvent)) + { + skip = true; + break; + } + } + else if (attr.GetType() == typeof(IfNotAttribute)) + { + IfNotAttribute when = attr as IfNotAttribute; + string conditionName = when.conditionName; + FieldInfo condition = type.GetField(conditionName); + if ((bool)condition.GetValue(animEvent)) + { + skip = true; + break; + } + } + else if(attr.GetType() == typeof(HDRAttribute)) + { + isHDR = true; + } + } + if (skip) + { + GUI.enabled = true; + continue; + } + EditorGUILayout.LabelField(new GUIContent(name, tooltip), styles.textBold); + if (field.FieldType == typeof(Vector3)) + { + field.SetValue(animEvent, GUI_Vector3((Vector3)field.GetValue(animEvent))); + } + else if (field.FieldType == typeof(Vector2)) + { + field.SetValue(animEvent, GUI_Vector2((Vector2)field.GetValue(animEvent))); + } + else if (field.FieldType == typeof(string)) + { + field.SetValue(animEvent, GUI_String((string)field.GetValue(animEvent))); + } + else if (field.FieldType == typeof(bool)) + { + field.SetValue(animEvent, GUI_Bool((bool)field.GetValue(animEvent))); + } + else if(field.FieldType == typeof(AnimationCurve)) + { + field.SetValue(animEvent, GUI_Curve(field.GetValue(animEvent) as AnimationCurve)); + } + else if(field.FieldType.IsEnum) + { + field.SetValue(animEvent, GUI_Enum((Enum)field.GetValue(animEvent))); + } + else if(field.FieldType == typeof(float)) + { + field.SetValue(animEvent, GUI_Float((float)field.GetValue(animEvent))); + } + else if (field.FieldType == typeof(int)) + { + field.SetValue(animEvent, GUI_Int((int)field.GetValue(animEvent))); + } + else if(field.FieldType == typeof(Color)) + { + if(isHDR) + { + field.SetValue(animEvent, GUI_ColorHDR((Color)field.GetValue(animEvent))); + } + else + { + field.SetValue(animEvent, GUI_Color((Color)field.GetValue(animEvent))); + } + } + else + { + Color c = GUI.color; + GUI.color = Color.red; + GUI_Label(new GUIContent("Unknown Type " + field.FieldType), GUI.skin.GetStyle("Label")); + GUI.color = c; + } + GUILayout.Space(5); + } + } + + EditorGUILayout.EndScrollView(); + } + + void GUI_Label(GUIContent label, GUIStyle style) + { + Rect rect = EditorGUILayout.GetControlRect(); + EditorGUI.LabelField(rect, label, style); + } + + float GUI_Float(float value) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.FloatField(rect, "", value); + } + + int GUI_Int(int value) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.IntField(rect, "", value); + } + + AnimationCurve GUI_Curve(AnimationCurve curve) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.CurveField(rect, "", curve); + } + + Enum GUI_Enum(Enum enumValue) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.EnumPopup(rect, "", enumValue); + } + + Vector3 GUI_Vector3(Vector3 value) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.Vector3Field(rect, "", value); + } + + Vector2 GUI_Vector2(Vector2 value) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.Vector2Field(rect, "", value); + } + + string GUI_String(string value) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.TextField(rect, "", value); + } + + bool GUI_Bool(bool value) + { + Rect rect = EditorGUILayout.GetControlRect(); + return GUI.Toggle(rect, value, "Check"); + } + + Color GUI_Color(Color col) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.ColorField(rect, col); + } + + Color GUI_ColorHDR(Color col) + { + Rect rect = EditorGUILayout.GetControlRect(); + return EditorGUI.ColorField(rect, new GUIContent(""), col, true, true, true); + } + + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs.meta new file mode 100644 index 00000000..6a130af1 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionEventEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 7e3fa648b1f19c141ad717db41c10772 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs b/Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs new file mode 100644 index 00000000..0d4a0f4f --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs @@ -0,0 +1,47 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + // 编辑collider帧 + public class ActionInfoEditor : EditorWindow + { + private static string title; + private static string content; + private static Vector2 size; + + public static void ShowContent(string tlt, string cnt) + { + title = tlt; + content = cnt; + size = GUI.skin.label.CalcSize(new GUIContent(content)); + var editor = EditorWindow.GetWindow(true); + editor.titleContent = new GUIContent(title); + editor.OnEnable(); + } + + private void OnEnable() + { + titleContent = new GUIContent(title); + maxSize = new Vector2(50 + size.x, 10 + size.y); + minSize = maxSize; + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + Vector2 size= GUI.skin.label.CalcSize(new GUIContent(content)); + GUI.Label(new Rect(5,5, size.x, size.y), content); + } + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs.meta new file mode 100644 index 00000000..49da3876 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionInfoEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 8121c73011a3e1c4ea6beaf52d54e673 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionManager.cs b/Assets/Tools/ActionTool/Editor/ActionManager.cs new file mode 100644 index 00000000..d9279745 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionManager.cs @@ -0,0 +1,548 @@ +using System; +using System.IO; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +namespace ActionTool +{ + // ActionTool callback delegates + public delegate void CallbackHandler(params object[] objs); + + public static class ActionManager + { + public enum UnitType + { + PC, + NPC, + } + + public static string s_Controller = "Assets/ActionTool/controller_temp.controller"; + static string s_SettingPath = "Assets/ActionTool/ActionTool Settings.asset"; + public static string scenePath { get { return "Assets/ActionTool/ActionToolScene.unity"; } } + + //public static string s_AnimFolder = "Assets/Art/Animations/"; + //public static string s_AnimationDataFolder = "Assets/Data/AnimationData/"; + //static string s_RootMotionDataFolder = "Assets/Data/RootMotionData/"; + + public static ActionEditor AnimationWindow; + public static ActionPreviewEditor PreviewWindow; + public static ActionEventEditor EventEditWindow; + public static ActionColliderFrameEditor ColliderFrameWindow; + public static ActionColliderEditor ColliderWindow; + public static ActionRootMotionEditor RootMotionEditor; + + public static ActionToolSettings Settings; + + //规定timeline上事件的采样频率是30帧 + public const int FPS = 30; + + public static float Speed = 1; + + public static GameObject CurrentUnit + { + get + { + return s_CurrentUnit; + } + } + + public static string CurrentAnimationName + { + get + { + return s_CurrentAnimationName; + } + } + + private static GameObject s_CurrentUnit; + private static string s_CurrentAnimationName; + public static GameObject unitInstance { get { return s_UnitInstance; } } + public static GameObject unitRoot { get; private set; } + private static GameObject s_UnitInstance; + private static Animator s_Animator; + private static AnimatorOverrideController s_OverrideContorller; + + private static ActionData s_CurActionData; + public static ActionData actionData { get { return s_CurActionData; } } + + public static Vector3 s_InitPosition = Vector3.zero; + public static Quaternion s_InitRotation = Quaternion.identity; + + private static RootMotionData s_RootMotion; + + private static AnimationData m_SharedAnimationData; // 资源 + public static AnimationData sharedAnimationData { get { return m_SharedAnimationData; } } + private static AnimationData m_AnimationData; + public static AnimationData animationData + { + get + { + return m_AnimationData; + } + set + { + m_AnimationData = value; + if (gizmos) + { + gizmos.SetAnimationData(value); + } + } + } + public static AnimationClip curClip; + + public static string AnimationDataPath + { + get + { + return AssetDatabase.GetAssetPath(sharedAnimationData); + } + } + + private static AnimationEventBase m_CurAnimationEvent; + public static AnimationEventBase animationEvent { get { return m_CurAnimationEvent; } } + + private static ColliderData s_CurColliderData; + public static ColliderData colliderData { get { return s_CurColliderData; } set { s_CurColliderData = value; } } + + public static ColliderData.ColliderFrame s_CurEditColliderFrame; + public static ColliderData.ColliderFrame editColliderFrame { get { return s_CurEditColliderFrame; } } + public static ColliderData s_CurEditFrameCollider; + + private static ActionToolGizmos s_Gizmos; + public static ActionToolGizmos gizmos { get { return s_Gizmos; } } + + // 是否在自动播放 + private static bool s_IsPlay; + public static bool IsPlay { get { return s_IsPlay; } } + + private static GameObject s_RootActionTool; + private const string kRootActionTool = "RootActionTool"; + private const string kUnitRoot = "UnitRoot"; + + private static AnimationEventBase copiedAnimationEvent; + + public static int MaxEventsPerFrame // 所有帧里面事件最多有几个 + { + get + { + if (animationData == null) + return 0; + return animationData.GetMaxAnimationEventsCount(); + } + } + + public static int GridRowCount + { + get + { + bool hasRM = animationData != null && animationData.overrideRootMotion == true; + return (MaxEventsPerFrame + 1) + (animationData != null ? animationData.GetBoxesCount() : 0) + (hasRM ? 1 : 0); + } + } + + public static string unitFolder; + public static string unitAnimationDataFolder { get { return unitFolder + "AnimationData/"; } } + public static string unitRootMotionFolder { get { return unitFolder + "RootMotion/"; } } + public static string unitAnimationClipFolder { get { return unitFolder + "AnimationClip/"; } } + public static string unitDataFolder { get { return unitFolder + "UnitData/"; } } + + public static int colliderIndex; + + public static CallbackHandler onSelectObj; + + public static void OnSelectObj(GameObject obj) + { + Release(); + s_CurrentUnit = obj; + if(s_CurrentUnit != null) + { + string path = AssetDatabase.GetAssetPath(obj); + string folder = Path.GetDirectoryName(path).Replace('\\', '/'); + folder = folder.Substring(0, folder.LastIndexOf('/')); + unitFolder = folder + "/"; + s_UnitInstance = GameObject.Instantiate(obj); + InitializeUnitInstance(s_UnitInstance); + } + onSelectObj?.Invoke(obj); + } + + public static void OnSelectAnimation(string animation) + { + s_CurrentAnimationName = animation; + if (PreviewWindow == null) + PreviewWindow = EditorWindow.GetWindow(); + PreviewWindow.Repaint(); + + string animpath = unitAnimationClipFolder + animation + ".anim"; + AnimationClip clip = AssetDatabase.LoadAssetAtPath(animpath, typeof(AnimationClip)) as AnimationClip; + curClip = clip; + if (clip) + { + s_OverrideContorller["EmptyAction"] = clip; + } + + string rootmotionData = unitRootMotionFolder + animation + ".asset"; + s_RootMotion = AssetDatabase.LoadAssetAtPath(rootmotionData); + if (s_RootMotion == null) + { + Debug.LogError("[ActionTool] 没有对应的rootmotion, " + rootmotionData); + } + + if (s_CurActionData == null) + s_CurActionData = new ActionData(); + s_CurActionData.Initialize(s_Animator, clip, s_RootMotion); + + string animationDataPath = unitAnimationDataFolder + animation + ".asset"; + AnimationData asset = AssetDatabase.LoadAssetAtPath(animationDataPath); + m_SharedAnimationData = asset; + if(asset != null) + animationData = UnityEngine.Object.Instantiate(asset); + else + animationData = null; + + OnSelectAnimationEvent(null); + OnSelectColliderFrame(null, null); + OnSelectBox(null); + if (EventEditWindow) EventEditWindow.Close(); + if (ColliderFrameWindow) ColliderFrameWindow.Close(); + + } + + public static bool HasSelectObj() + { + return s_CurrentUnit != null; + } + + public static void Release() + { + if(s_UnitInstance != null) + GameObject.DestroyImmediate(s_UnitInstance); + s_UnitInstance = null; + s_CurrentUnit = null; + s_CurrentAnimationName = null; + s_Animator = null; + s_RootActionTool = GameObject.Find(kRootActionTool); + if (s_RootActionTool) + GameObject.DestroyImmediate(s_RootActionTool); + s_CurActionData = null; + s_CurEditColliderFrame = null; + s_CurColliderData = null; + s_CurrentAnimationName = null; + } + + private static void InitializeUnitInstance(GameObject unit) + { + if (unit == null) + return; + + unit.transform.position = Vector3.zero; + unit.transform.rotation = Quaternion.Euler(0, 90, 0); + + var tempUnitRoot = GameObject.Find(kUnitRoot); + if (tempUnitRoot) + GameObject.DestroyImmediate(tempUnitRoot); + unitRoot = new GameObject(kUnitRoot); + unitRoot.transform.localScale = Vector3.one; + unitRoot.transform.rotation = s_InitRotation; + unitRoot.transform.position = s_InitPosition; + unit.transform.SetParent(unitRoot.transform); + + s_RootActionTool = GameObject.Find(kRootActionTool); + if(s_RootActionTool == null) + s_RootActionTool = new GameObject(kRootActionTool); + + unitRoot.transform.SetParent(s_RootActionTool.transform); + + s_Animator = unit.GetComponentInChildren(); + if(s_Animator == null) + { + Debug.LogError("[ActionTool] 角色prefab下没有animator"); + return; + } + + RuntimeAnimatorController controller = AssetDatabase.LoadAssetAtPath(s_Controller, typeof(RuntimeAnimatorController)) as RuntimeAnimatorController; + if(controller == null) + { + Debug.LogError("[ActionTool] 文件丢失" + s_Controller); + return; + } + + s_OverrideContorller = new AnimatorOverrideController(controller); + s_OverrideContorller.name = "override controller"; + s_Animator.runtimeAnimatorController = s_OverrideContorller; + + s_Animator.applyRootMotion = false; + + s_Gizmos = s_RootActionTool.AddComponent(); + s_Gizmos.Initialize(unitRoot); + + Settings = AssetDatabase.LoadAssetAtPath(s_SettingPath); + } + + public static void UpdateFrame() + { + if (s_CurActionData != null) + s_CurActionData.UpdateFrame(); + } + + public static void Pause() + { + s_IsPlay = !s_IsPlay; + if(s_IsPlay && s_CurActionData != null) + { + s_CurActionData.StartFrame(); + } + } + + public static void Start() + { + if (s_CurActionData != null) + s_CurActionData.curAnimTimeNormal = 0; + } + + public static void Stop() + { + if (s_CurActionData != null) + { + if (s_IsPlay) + Pause(); + s_CurActionData.curAnimTimeNormal = 0; + } + } + + public static void Previous() + { + if (s_IsPlay) + Pause(); + float cur = s_CurActionData.curAnimFrame; + float pre = Mathf.Ceil(cur - 1); + pre = (int)Mathf.Clamp(pre, 0, s_CurActionData.totalFrame); + s_CurActionData.SetCurrentAnimTime(pre); + } + + public static void Next() + { + if (s_IsPlay) + Pause(); + float cur = s_CurActionData.curAnimFrame; + float next = Mathf.Floor(cur + 1); + next = (int)Mathf.Clamp(next, 0, s_CurActionData.totalFrame); + s_CurActionData.SetCurrentAnimTime(next); + } + + public static void End() + { + if (s_CurActionData != null) + s_CurActionData.curAnimTimeNormal = 1; + } + + public static void CreateAnimationData() + { + string animation = s_CurrentAnimationName; + string animationDataPath = unitAnimationDataFolder + animation + ".asset"; + string animpath = unitAnimationClipFolder + animation + ".anim"; + AnimationData animData = new AnimationData(); + animData.animationName = s_CurrentAnimationName; + animData.animationPath = animpath; + AssetDatabase.CreateAsset(animData, animationDataPath); + AssetDatabase.Refresh(); + m_SharedAnimationData = animData; + animationData = UnityEngine.Object.Instantiate(animData); + } + + public static void SaveAnimationData() + { + if (animationData == null) + { + Debug.LogError("[ActionTool] 没有animation data数据"); + return; + } + string animation = s_CurrentAnimationName; + string animationDataPath = unitAnimationClipFolder + animation + ".asset"; + EditorUtility.CopySerialized(animationData, m_SharedAnimationData); + m_SharedAnimationData.OnSaveToDisk(); + EditorUtility.SetDirty(m_SharedAnimationData); + AssetDatabase.SaveAssets(); + AssetDatabase.Refresh(); + } + + public static void NewHurtBox() + { + if (animationData == null) + { + Debug.LogError("[ActionTool] 没有animation data数据"); + return; + } + ColliderData box = new ColliderData(ColliderBox.EColliderType.HurtBox, ColliderBox.Pivot.MiddleBottom); + animationData.AddBox(ref animationData.hurtBoxes, box); + } + + public static void NewHitBox() + { + if (animationData == null) + { + Debug.LogError("[ActionTool] 没有animation data数据"); + return; + } + ColliderData box = new ColliderData(ColliderBox.EColliderType.HitBox, ColliderBox.Pivot.MiddleCenter); + animationData.AddBox(ref animationData.hitBoxes, box); + } + + public static void DeleteCurBox() + { + if(animationData != null && s_CurColliderData != null) + { + animationData.DeleteBox(s_CurColliderData); + s_CurColliderData = null; + } + } + + public static void EditCollider() + { + if (s_CurColliderData == null) + return; + if(ColliderWindow == null) + ColliderWindow = EditorWindow.GetWindow(true); + } + + public static void OnSelectBox(ColliderData collider, int index = 0) + { + s_CurColliderData = collider; + if (ColliderWindow != null) + ColliderWindow.Repaint(); + colliderIndex = index; + EditCollider(); + } + + public static void AddNewBoxFrame(object param) + { + BoxParam frame = (BoxParam)param; + int frameIndex = frame.frame; + var data = frame.collider; + if(data != null) + { + var frameData = data.AddFrame(frameIndex); + OnSelectColliderFrame(frameData, data); + } + } + + public static void DeleteBoxFrame(object param) + { + BoxParam frame = (BoxParam)param; + int frameIndex = frame.frame; + var data = frame.collider; + if (data != null) + { + data.DeleteFrame(frameIndex); + } + } + + public static void DeleteCurFrame() + { + if (s_CurEditFrameCollider == null) + return; + if (s_CurEditColliderFrame == null) + return; + s_CurEditFrameCollider.DeleteFrame(s_CurEditColliderFrame.frame); + + s_CurEditColliderFrame = null; + } + + public static void OnSelectColliderFrame(ColliderData.ColliderFrame frame, ColliderData collider = null) + { + s_CurEditColliderFrame = frame; + s_CurEditFrameCollider = collider; + + if (frame != null) + { + ColliderFrameWindow = EditorWindow.GetWindow(true); + + ActionData action = ActionManager.actionData; + float normaltime = frame.frame / action.totalFrame; + action.curAnimTimeNormal = normaltime; + } + } + + public static void AddNewEvent(object param) + { + EventParam eventParam = (EventParam )param; + string eventName = eventParam.eventName; // TimelineEventProxy.EEventType + int frame = eventParam.frame; + Debug.Log("[ActionTool] Add new event " + eventName); + if (animationData == null) + { + Debug.LogError("[ActionTool] 没有animation data数据"); + return; + } + Type type = TimelineEventProxy.GetTypeByName(eventName); + if(type == null) + { + Debug.LogError("[ActionTool] 没有创建对应的类, " + eventName); + return; + } + AnimationEventBase animEvent = Activator.CreateInstance(type) as AnimationEventBase; + if(animEvent) + { + animEvent.name = animEvent.type.ToString(); + animEvent.startFrame = frame; + animationData.AddEvent(animEvent); + OnSelectAnimationEvent(animEvent); + } + else + { + Debug.LogError("[ActionTool] 实例化失败, " + eventName); + return; + } + } + + public static void PasteEvent(object param) + { + if (copiedAnimationEvent == null) + return; + int frame = (int)param; + AnimationEventBase animEvent = UnityEngine.Object.Instantiate(copiedAnimationEvent); + if(animEvent != null) + { + animEvent.name = animEvent.type.ToString(); + animEvent.startFrame = frame; + animationData.AddEvent(animEvent); + OnSelectAnimationEvent(animEvent); + } + } + + public static void OnSelectAnimationEvent(AnimationEventBase animEvent) + { + m_CurAnimationEvent = animEvent; + if(animEvent != null) + { + EventEditWindow = EditorWindow.GetWindow(true); + } + } + + public static void DeleteEvent(AnimationEventBase animEvent) + { + if (animationData == null) + return; + animationData.DeleteEvent(animEvent); + } + + public static void EditRootMotionOverrideData() + { + RootMotionEditor = EditorWindow.GetWindow(true); + } + + public static void CopyAnimationEvent(AnimationEventBase animEvent) + { + copiedAnimationEvent = UnityEngine.Object.Instantiate(animEvent); + } + + public static void ResetUnitRootPosAndRot() + { + unitRoot.transform.position = s_InitPosition; + unitRoot.transform.rotation = s_InitRotation; + } + + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionManager.cs.meta b/Assets/Tools/ActionTool/Editor/ActionManager.cs.meta new file mode 100644 index 00000000..86dd9397 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionManager.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 5edc3f3e858191742a0db785219adbe3 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs b/Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs new file mode 100644 index 00000000..d6a0a425 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs @@ -0,0 +1,40 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + // 编辑collider帧 + public class ActionNoteEditor : EditorWindow + { + private void OnEnable() + { + titleContent = new GUIContent("Note"); + maxSize = new Vector2(300, 110); + minSize = new Vector2(300, 110); + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + var animData = ActionManager.animationData; + if(animData == null) + { + this.Close(); + return; + } + GUILayout.Space(5); + animData.note = GUILayout.TextArea(animData.note, GUILayout.Height(100)); + GUILayout.Space(5); + } + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs.meta new file mode 100644 index 00000000..a47cc903 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionNoteEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 48a105c4026c65b428a22db4c350c5ef +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs b/Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs new file mode 100644 index 00000000..03858393 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs @@ -0,0 +1,1027 @@ +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 + ); + } + if (animationData) + { + Color bgColor = GUI.backgroundColor; + GUI.backgroundColor = animationData.note != null && animationData.note != "" ? bgColor : Color.gray; + if (GUI.Button(new Rect(xr + width + 10 + 50 + 10, y, 16, 14), "", styles.infoButton)) + { + EditorWindow.GetWindow(true); + } + GUI.backgroundColor = bgColor; + } + 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.textMiddleBold.CalcSize(new GUIContent("Override")).x; + GUI.Label(new Rect(xr, y, width, 15), "Override", styles.textMiddleBold); + 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); + width = styles.textMiddleBold.CalcSize(new GUIContent("None")).x; + if (animationData != null) + { + if (GUI.Button(new Rect(xr + width + 10, 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)Mathf.Ceil(action.totalFrame)) * 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)Mathf.Ceil(action.totalFrame); + 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)Mathf.Ceil(action.totalFrame); + + 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)Mathf.Ceil(action.totalFrame); + 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)Mathf.Ceil(action.totalFrame); + 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(); + } + + } + +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs.meta new file mode 100644 index 00000000..5b4ca315 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionPreviewEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 309177f6ffca86847b5a989422c96fdc +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs b/Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs new file mode 100644 index 00000000..eb076fc3 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs @@ -0,0 +1,121 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + public class ActionRootMotionEditor : EditorWindow + { + ActionEditorStyles styles; + + // isrecord的时候playbackFrame是整数 + public static bool IsRecord { get; private set; } + + const float kToolbarControlMargin = 5; + const float kToolbarHeight = 50; + const float kToolbarControlSize = kToolbarHeight - kToolbarControlMargin * 2; + float m_ToolbarOffset = 0; // <= 0 + + Texture m_UITextureRecord; + Texture m_UITextureTakeRecord; + Texture m_UITextureTrashCan; + + Texture2D tex; + + private void OnEnable() + { + maxSize = new Vector2(300, 90); + minSize = maxSize; + this.titleContent = new GUIContent("RootMotion Editor"); + + m_UITextureRecord = (Texture)Resources.Load("button_control_record"); + m_UITextureTakeRecord = (Texture)Resources.Load("button_control_takerecord"); + m_UITextureTrashCan = EditorGUIUtility.FindTexture("d_TreeEditor.Trash"); + + tex = new Texture2D(1, 1, TextureFormat.RGBA32, false); + tex.SetPixel(0, 0, new Color(1f, 0, 0) * 0.5f); + tex.Apply(); + + IsRecord = false; + + ActionManager.gizmos.ShowRootMotionGizmos(true); + } + + private void OnDisable() + { + IsRecord = false; + + ActionManager.gizmos.ShowRootMotionGizmos(false); + } + + private void Update() + { + + } + + private void OnGUI() + { + if(ActionManager.animationData == null || ActionManager.animationData.overrideRootMotion == false) + { + this.Close(); + return; + } + if (IsRecord) + { + GUI.DrawTexture(new Rect(0, 0, maxSize.x, maxSize.y), tex, ScaleMode.StretchToFill); + } + float x = m_ToolbarOffset, y = kToolbarControlMargin; + GUI_Record(ref x, ref y); + GUI_TakeRecord(ref x, ref y); + GUI_Delete(ref x, ref y); + GUI.enabled = false; + EditorGUI.Vector3Field(new Rect(0, kToolbarHeight, position.width, 20), "Position: ", ActionManager.unitRoot.transform.position); + GUI.enabled = true; + } + + void GUI_Record(ref float x, ref float y) + { + x += kToolbarControlMargin; + Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); + IsRecord = GUI.Toggle(rect, IsRecord, EditorGUIUtility.IconContent("d_Animation.Record", "Record"), GUI.skin.button); + x += kToolbarControlSize; + } + + void GUI_TakeRecord(ref float x, ref float y) + { + if (!IsRecord) + GUI.enabled = false; + x += kToolbarControlMargin; + Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); + if (GUI.Button(rect, EditorGUIUtility.IconContent("Animation.AddKeyframe", "Key Frame"))) + { + Vector3 pos = ActionManager.unitRoot.transform.position; + int frame = (int)ActionManager.actionData.curAnimFrame; + ActionManager.animationData.rootMotionOverrideData.SetPosition(frame, pos); + ActionManager.PreviewWindow.Repaint(); + EditorWindow.GetWindow()?.Repaint(); + SceneView.RepaintAll(); + } + GUI.enabled = true; + x += kToolbarControlSize; + } + + void GUI_Delete(ref float x, ref float y) + { + if (!IsRecord) + GUI.enabled = false; + x += kToolbarControlMargin; + Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize); + if (GUI.Button(rect, m_UITextureTrashCan)) + { + int frame = (int)ActionManager.actionData.curAnimFrame; + ActionManager.animationData.rootMotionOverrideData.RemovePositionAtFrame(frame); + ActionManager.PreviewWindow.Repaint(); + } + GUI.enabled = true; + x += kToolbarControlSize; + } + + } +} \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs.meta new file mode 100644 index 00000000..599c18ad --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2e61eeb773ddf2e478e01d9b6a5ab786 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs b/Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs new file mode 100644 index 00000000..c35688dd --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs @@ -0,0 +1,62 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using UnityEditor; +using UnityEngine; + +[CustomEditor(typeof(ActionToolSettings))] +public class ActionToolSettingsEditor : Editor +{ + ActionToolSettings setting; + + public void OnEnable() + { + setting = target as ActionToolSettings; + } + + public void OnDisable() + { + + } + + public override void OnInspectorGUI() + { + if (setting == null) + return; + + //foreach(var col in setting.eventColors) + //{ + // EditorGUILayout.BeginHorizontal(); + // EditorGUILayout.LabelField(col.Key.ToString()); + // Color c = EditorGUILayout.ColorField(col.Value); + // setting.eventColors[col.Key] = c; + // EditorGUILayout.EndHorizontal(); + //} + + EditorGUI.BeginChangeCheck(); + + foreach (var name in Enum.GetNames(typeof(TimelineEventProxy.EEventType))) + { + EditorGUILayout.BeginHorizontal(); + EditorGUILayout.LabelField(name); + Color old = setting.eventNames.Contains(name) ? setting.eventColors[setting.eventNames.IndexOf(name)] : Color.black; + Color c = EditorGUILayout.ColorField(old); + if (!setting.eventNames.Contains(name)) + { + setting.eventNames.Add(name); + setting.eventColors.Add(c); + } + setting.eventColors[setting.eventNames.IndexOf(name)] = c; + EditorGUILayout.EndHorizontal(); + } + + if(EditorGUI.EndChangeCheck()) + { + EditorUtility.SetDirty(setting); + //AssetDatabase.SaveAssets(); + //AssetDatabase.Refresh(); + } + } + +} + \ No newline at end of file diff --git a/Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs.meta b/Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs.meta new file mode 100644 index 00000000..9e1702fd --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/ActionToolSettingsEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 2208059a63398d941a5613752569a003 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs b/Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs new file mode 100644 index 00000000..b50fe884 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + [CustomPropertyDrawer(typeof(CurveDictionary))] + public class CurveDictionaryDrawer : SerializableDictionaryPropertyDrawer { } + + public class AnimationCurveEditor : EditorWindow + { + + SerializedObject obj; + + private void OnEnable() + { + titleContent = new GUIContent("Curves"); + maxSize = new Vector2(300, 2000); + minSize = new Vector2(300, 200); + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + { + this.Close(); + return; + } + + if (obj == null || obj.targetObject != animData) + { + obj = new SerializedObject(animData); + } + + var curves = obj.FindProperty("curves"); + EditorGUILayout.PropertyField(curves, true); + if (obj.ApplyModifiedProperties()) + { + } + } + } + +} diff --git a/Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs.meta b/Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs.meta new file mode 100644 index 00000000..fb35d0db --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationCurveEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: e9fc645a569609847964fd93876b8d5d +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs b/Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs new file mode 100644 index 00000000..a62ea4a1 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + [CustomPropertyDrawer(typeof(ParameterDictionary))] + public class ParameterDictionaryDrawer : SerializableDictionaryPropertyDrawer { } + + public class AnimationParameterEditor : EditorWindow + { + + SerializedObject obj; + + private void OnEnable() + { + titleContent = new GUIContent("Parameters"); + minSize = new Vector2(300, 200); + maxSize = new Vector2(300, 2000); + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + { + this.Close(); + return; + } + + if (obj == null || obj.targetObject != animData) + { + obj = new SerializedObject(animData); + } + + var curves = obj.FindProperty("parameters"); + EditorGUILayout.PropertyField(curves, true); + if (obj.ApplyModifiedProperties()) + { + } + } + } + +} diff --git a/Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs.meta b/Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs.meta new file mode 100644 index 00000000..f0555041 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationParameterEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 4ffd18cdca7a4c2439cef0254dcf751a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs b/Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs new file mode 100644 index 00000000..59786bf9 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs @@ -0,0 +1,54 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + [CustomPropertyDrawer(typeof(PropertyDictionary))] + public class PropertyDictionaryDrawer : SerializableDictionaryPropertyDrawer { } + + public class AnimationPropertyEditor : EditorWindow + { + + SerializedObject obj; + + private void OnEnable() + { + titleContent = new GUIContent("Properties"); + minSize = new Vector2(300, 200); + maxSize = new Vector2(300, 2000); + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + { + this.Close(); + return; + } + + if (obj == null || obj.targetObject != animData) + { + obj = new SerializedObject(animData); + } + + var curves = obj.FindProperty("properties"); + EditorGUILayout.PropertyField(curves, true); + if (obj.ApplyModifiedProperties()) + { + } + } + } + +} diff --git a/Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs.meta b/Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs.meta new file mode 100644 index 00000000..efdc8fad --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationPropertyEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: ac9aacf41a77d2d4b8dbda78defdf534 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs b/Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs new file mode 100644 index 00000000..6b5cc57a --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs @@ -0,0 +1,69 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEditor; + +namespace ActionTool +{ + + + [CustomPropertyDrawer(typeof(ToggleTimeDictionary))] + public class ToggleTimeDictionaryDrawer : SerializableDictionaryPropertyDrawer { } + + public class AnimationToggleEditor : EditorWindow + { + + SerializedObject obj; + + private void OnEnable() + { + titleContent = new GUIContent("Toggles"); + maxSize = new Vector2(300, 2000); + minSize = new Vector2(300, 200); + } + + private void OnDisable() + { + } + + private void Update() + { + } + + private void OnGUI() + { + AnimationData animData = ActionManager.animationData; + if (animData == null) + { + this.Close(); + return; + } + + if (obj == null || obj.targetObject != animData) + { + obj = new SerializedObject(animData); + } + + var toggles = obj.FindProperty("toggles"); + EditorGUILayout.PropertyField(toggles, true); + + if(obj.ApplyModifiedProperties()) + { + if (animData.toggles != null && animData.toggles.Count > 0) + { + List keys = new List(animData.toggles.Keys); + for(int i = 0; i < keys.Count; ++i) + { + Vector2 minMax = animData.toggles[keys[i]].fromTo; + minMax.x = Mathf.Clamp(minMax.x, 0, 1); + minMax.y = Mathf.Clamp(minMax.y, 0, 1); + minMax.x = Mathf.Clamp(minMax.x, 0, minMax.y); + minMax.y = Mathf.Clamp(minMax.y, minMax.x, 1); + animData.toggles[keys[i]] = new FromTo(minMax); + } + } + } + } + } + +} diff --git a/Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs.meta b/Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs.meta new file mode 100644 index 00000000..2be25d40 --- /dev/null +++ b/Assets/Tools/ActionTool/Editor/AnimationToggleEditor.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 11f79c8cc79fb9e449a43bf66fd1c8f0 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: -- cgit v1.1-26-g67d0