summaryrefslogtreecommitdiff
path: root/Assets/ActionTool/Editor/ActionEventEditor.cs
blob: 8edcd1c24803374d3a902421792165b8253a6a7c (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
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
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.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 = "";
                    foreach(var attr in field.GetCustomAttributes())
                    {
                        if(attr.GetType() == typeof(TooltipAttribute))
                        {
                            TooltipAttribute tooltipattr = attr as TooltipAttribute;
                            if(tooltip != null)
                            {
                                tooltip = tooltipattr.tooltip;
                            }
                        }
                    }
                    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)));
                    }
                    GUILayout.Space(5);
                }
            }

            EditorGUILayout.EndScrollView();
        }

        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");
        }

    }
}