-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathUIManagerEditor.cs
162 lines (120 loc) · 4.58 KB
/
UIManagerEditor.cs
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
158
159
160
161
162
#region Header
/* ============================================
* Author : Strix
* Initial Creation Date : 2020-03-15
* Summary :
*
*
* 참고한 코드
* - ReorderableList - https://unityindepth.tistory.com/56
* Template : For Unity Editor V1
============================================ */
#endregion Header
using System.Collections.Generic;
using System.IO;
using UnityEngine;
using UnityEditor;
using UIFramework;
using System.Linq;
/// <summary>
///
/// </summary>
public class UIManagerEditor : EditorWindow
{
/* const & readonly declaration */
/* enum & struct declaration */
/* public - Field declaration */
public UISetting pSetting;
/* protected & private - Field declaration */
// ========================================================================== //
/* public - [Do~Something] Function */
[MenuItem("Tools/Strix/UIManager Editor")]
static void ShowWindow()
{
UIManagerEditor pWindow = (UIManagerEditor)GetWindow(typeof(UIManagerEditor), false);
pWindow.pSetting = GetCurrentSetting();
pWindow.minSize = new Vector2(300, 500);
pWindow.Show();
}
private static UISetting GetCurrentSetting()
{
string[] arrFileGUID = AssetDatabase.FindAssets($"t:{nameof(UISetting)}");
UISetting pCurrentSetting;
if (arrFileGUID.Length > 0)
{
UISetting[] arrSetting = arrFileGUID.Select(p => AssetDatabase.LoadAssetAtPath<UISetting>(AssetDatabase.GUIDToAssetPath(p))).ToArray();
pCurrentSetting = arrSetting.FirstOrDefault(p => p.bIsCurrent);
if (pCurrentSetting == null)
pCurrentSetting = arrSetting.First();
}
else
pCurrentSetting = CreateAsset<UISetting>();
pCurrentSetting.bIsCurrent = true;
return pCurrentSetting;
}
// ========================================================================== //
/* protected - [Override & Unity API] */
Vector2 _vecScrollPos_EditorSetting;
private void OnGUI()
{
SerializedObject pSO = new SerializedObject(this);
_vecScrollPos_EditorSetting = EditorGUILayout.BeginScrollView(_vecScrollPos_EditorSetting, GUILayout.Height(300f));
{
SerializedProperty pProperty = pSO.FindProperty($"{nameof(pSetting)}");
EditorGUILayout.PropertyField(pProperty);
}
EditorGUILayout.EndScrollView();
Draw_CSExportButton();
if (GUI.changed)
{
pSO.ApplyModifiedProperties();
EditorUtility.SetDirty(this);
}
}
/* protected - [abstract & virtual] */
// ========================================================================== //
#region Private
private void Draw_CSExportButton()
{
string strExportCS = $"Export Editor Setting // Path is (Assets/{pSetting.strExportCSPath}.cs)";
EditorGUILayout.BeginHorizontal();
{
if (GUILayout.Button(strExportCS))
{
if (string.IsNullOrEmpty(pSetting.strExportCSPath))
{
UnityEngine.Debug.LogError($"{nameof(pSetting.strExportCSPath)} - string.IsNullOrEmpty({(pSetting.strExportCSPath)})");
return;
}
ExportCS();
}
}
EditorGUILayout.EndHorizontal();
}
private void ExportCS()
{
CustomCodedom pCodeDom = new CustomCodedom();
pCodeDom.DoExportCS($"{Application.dataPath}/{pSetting.strExportCSPath}");
AssetDatabase.Refresh();
UnityEngine.Debug.Log($"{nameof(ExportCS)} Complete");
}
public static T CreateAsset<T>() where T : ScriptableObject
{
T pAsset = ScriptableObject.CreateInstance<T>();
#if UNITY_EDITOR
const string strCreateAssetPath = "Resources";
string strAbsoluteDirectory = Application.dataPath + $"/{strCreateAssetPath}";
if (Directory.Exists(strAbsoluteDirectory) == false)
Directory.CreateDirectory(strAbsoluteDirectory);
string assetPathAndName = AssetDatabase.GenerateUniqueAssetPath($"Assets/{strCreateAssetPath}/New {typeof(T)}.asset");
AssetDatabase.CreateAsset(pAsset, assetPathAndName);
AssetDatabase.SaveAssets();
AssetDatabase.Refresh();
EditorUtility.FocusProjectWindow();
pAsset = (T)AssetDatabase.LoadAssetAtPath(assetPathAndName, typeof(T));
Selection.activeObject = pAsset;
#endif
return pAsset;
}
#endregion Private
}