diff options
author | chai <chaifix@163.com> | 2021-09-15 12:50:26 +0800 |
---|---|---|
committer | chai <chaifix@163.com> | 2021-09-15 12:50:26 +0800 |
commit | 98f31f197a126850a5878cd6e583ae6dbf64ab3d (patch) | |
tree | 207f726fb027c227d2fd58bd1bc340cb3a7eaf67 /Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs | |
parent | ad950c25abdf7f5a2f0428863d4035e9eb168fd5 (diff) |
*rename
Diffstat (limited to 'Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs')
-rw-r--r-- | Assets/Tools/ActionTool/Editor/ActionRootMotionEditor.cs | 121 |
1 files changed, 121 insertions, 0 deletions
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<SceneView>()?.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 |