summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor/ActionRootMotionEditor.cs
blob: ff0dae62f67a69d90200ba513f207198a66c8e1a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;

namespace ActionTool
{
    public class ActionRootMotionEditor : EditorWindow
    {
        ActionEditorStyles styles;

        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;

        Texture2D tex;

        private void OnEnable()
        {
            maxSize = new Vector2(300, 80);
            minSize = maxSize;
            this.titleContent = new GUIContent("RootMotion Editor");

            m_UITextureRecord = (Texture)Resources.Load("button_control_record");
            m_UITextureTakeRecord = (Texture)Resources.Load("button_control_takerecord");
            tex = new Texture2D(1, 1, TextureFormat.RGBA32, false);
            tex.SetPixel(0, 0, new Color(1f, 0, 0) * 0.8f);
            tex.Apply();
        }

        private void OnDisable()
        {

        }

        private void Update()
        {

        }

        private void OnGUI()
        {
            if(ActionManager.animationData == null || ActionManager.animationData.overrideRootMotion == null)
            {
                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);
        }

        void GUI_Record(ref float x, ref float y)
        {
            x += kToolbarControlMargin;
            Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
            IsRecord = GUI.Toggle(rect, IsRecord, m_UITextureRecord, GUI.skin.button);
            x += kToolbarControlSize;
        }

        void GUI_TakeRecord(ref float x, ref float y)
        {
            x += kToolbarControlMargin;
            Rect rect = new Rect(x, y, kToolbarControlSize, kToolbarControlSize);
            if (GUI.Button(rect, m_UITextureTakeRecord))
            {

            }
            x += kToolbarControlSize;
        }

    }
}