열차 목업의 내부 확인용 프로젝트
smchoi
2024-06-14 3d45944b4b2abc384e2539fa72cd7925bbcf2543
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
156
157
//////////////////////////////////////////////////////
// MK Glow Editor Helper Main                             //
//                                                    //
// Created by Michael Kremmel                       //
// www.michaelkremmel.de                            //
// Copyright © 2020 All rights reserved.            //
//////////////////////////////////////////////////////
#if UNITY_EDITOR
using UnityEngine;
using UnityEditor;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
 
namespace MK.Glow.Editor
{
    public static partial class EditorHelper
    {
        /// <summary>
        /// Draw a default splitter
        /// </summary>
        public static void DrawSplitter()
        {
            var rect = GUILayoutUtility.GetRect(0f, 1f);
 
            rect.xMin = 0f;
            rect.width += 4f;
 
            if(Event.current.type != EventType.Repaint)
                return;
 
            EditorGUI.DrawRect(rect, EditorStyles.splitter);
        }
 
        /// <summary>
        /// Foldout for settings
        /// </summary>
        /// <param name="title"></param>
        /// <param name="titleRight"></param>
        /// <returns></returns>
        private static Rect DrawFoldoutHeader(string title, string titleRight = "")
        {
            var gap = GUILayoutUtility.GetRect(0f, 0f);
            gap.xMin = 0f;
            gap.width += 4f;
            EditorGUI.DrawRect(gap, Color.clear);
            DrawSplitter();
            var rect = GUILayoutUtility.GetRect(16f, 16f);
 
            rect.xMin = 0f;
            rect.width += 4f;
 
            var lavelRect = new Rect(rect);
            lavelRect.xMin += 22;
            EditorGUI.DrawRect(rect, EditorStyles.headerBackground);
            EditorGUI.LabelField(lavelRect, title, UnityEditor.EditorStyles.boldLabel);
            EditorGUI.LabelField(lavelRect, titleRight, EditorStyles.rightAlignetLabel);
 
            return rect;
        }
        
        /// <summary>
        /// Creates a empty space with the height of 1
        /// </summary>
        public static void VerticalSpace()
        {
            GUILayoutUtility.GetRect(1f, EditorGUIUtility.standardVerticalSpacing);
        }
 
        /// <summary>
        /// Draws a header
        /// </summary>
        /// <param name="text"></param>
        public static void DrawHeader(string text)
        {
            EditorGUILayout.LabelField(text, UnityEditor.EditorStyles.boldLabel);
        }
 
        /// <summary>
        /// Draw a clickable behavior including a checkbox for a feature
        /// </summary>
        /// <param name="obj"></param>
        /// <param name="title"></param>
        /// <param name="titleRight"></param>
        /// <param name="behavior"></param>
        /// <param name="feature"></param>
        /// <returns></returns>
        public static bool HandleBehavior(UnityEngine.Object obj, string title, string titleRight, SerializedProperty behavior, SerializedProperty feature)
        {
            Rect rect = DrawFoldoutHeader(title, titleRight);
                
            var e = Event.current;
 
            var foldoutRect = new Rect(EditorGUIUtility.currentViewWidth * 0.5f, rect.y, 13f, 13f);
            if(behavior.hasMultipleDifferentValues)
            {
                foldoutRect.x -= 13;
            }
 
            //DrawSplitter();
            if(feature != null)
            {
                EditorGUI.showMixedValue = feature.hasMultipleDifferentValues;
                var toggleRect = new Rect(rect.x + 4f, rect.y + ((feature.hasMultipleDifferentValues) ? 0.0f : 2.0f), 13f, 13f);
                bool fn = feature.boolValue;
                EditorGUI.BeginChangeCheck();
 
                fn = EditorGUI.Toggle(toggleRect, "", fn, EditorStyles.headerCheckbox);
 
                if(EditorGUI.EndChangeCheck())
                {
                    feature.boolValue = fn;
                    if(feature.boolValue)
                        Undo.RegisterCompleteObjectUndo(obj, feature.displayName + " enabled");
                    else
                        Undo.RegisterCompleteObjectUndo(obj, feature.displayName + " disabled");
                }
                EditorGUI.showMixedValue = false;
 
                EditorGUI.showMixedValue = behavior.hasMultipleDifferentValues;
            }
 
            EditorGUI.BeginChangeCheck();
            if(e.type == EventType.MouseDown)
            {
                if(rect.Contains(e.mousePosition))
                {
                    if(behavior.hasMultipleDifferentValues)
                        behavior.boolValue = false;
                    else
                        behavior.boolValue = !behavior.boolValue;
                    e.Use();
                }
            }
            if(EditorGUI.EndChangeCheck())
            {
                if(behavior.boolValue)
                    Undo.RegisterCompleteObjectUndo(obj, behavior.displayName + " Show");
                else
                    Undo.RegisterCompleteObjectUndo(obj, behavior.displayName + " Hide");
            }
 
            EditorGUI.showMixedValue = false;
 
            if(e.type == EventType.Repaint && behavior.hasMultipleDifferentValues)
                UnityEditor.EditorStyles.radioButton.Draw(foldoutRect, "", false, false, true, false);
            else
                EditorGUI.Foldout(foldoutRect, behavior.boolValue, "");
 
            if(behavior.hasMultipleDifferentValues)
                return true;
            else
                return behavior.boolValue;
        }
    }
}
#endif