-
Notifications
You must be signed in to change notification settings - Fork 2
/
SkillEditorWindow.cs
229 lines (202 loc) · 6.97 KB
/
SkillEditorWindow.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEditor;
using System.IO;
public class SkillEditorWindow : EditorWindow
{
class PlayerEditor
{
public int _characterIndex = 0;
public int _folderIndex = 0;
public string characterName = string.Empty;
public string folderName = string.Empty;
public string characterFilter = string.Empty;
public List<string> characteList = new List<string>();
public Player player = null;
}
PlayerEditor m_player = new PlayerEditor();
/// <summary>
/// 文件名
/// </summary>
List<string> m_folderList = new List<string>();
/// <summary>
/// 所有预制体名
/// </summary>
List<string> m__characterList = new List<string>();
/// <summary>
/// 按文件名储存 预制体
/// </summary>
Dictionary<string, List<string>> m_folderPrefabs = new Dictionary<string, List<string>>();
/// <summary>
/// 技能详情窗口
/// </summary>
SkillWindow skillWindow;
/// <summary>
/// 储存 创建新的技能 的名字
/// </summary>
string newSkillName = string.Empty;
/// <summary>
/// 窗口初始化 (打开窗口)
/// </summary>
[MenuItem("Tools/技能编译器")]
public static void Init()
{
//只有运行的时候 才会打开
if (Application.isPlaying)
{
SkillEditorWindow window = EditorWindow.GetWindow<SkillEditorWindow>("SkillEditor");
if (window != null)
{
window.Show();
}
}
}
private void OnEnable()
{
DoSearchFolder();
DoSearchCharacter();
}
/// <summary>
/// 索引 所有 文件夹
/// </summary>
void DoSearchFolder()
{
m_folderList.Clear();
m_folderList.Add("all");
string[] folders = Directory.GetDirectories(GetCharacterPath());
foreach (var item in folders)
{
m_folderList.Add(Path.GetFileName(item));
}
}
/// <summary>
/// 索引所有的 预制
/// </summary>
void DoSearchCharacter()
{
string[] files = Directory.GetFiles(GetCharacterPath(), "*.prefab", SearchOption.AllDirectories);
m__characterList.Clear();
foreach (var item in files)
{
m__characterList.Add(Path.GetFileNameWithoutExtension(item));
}
m__characterList.Sort();
m__characterList.Insert(0, "null");
m_player.characteList.AddRange(m__characterList);
}
string GetCharacterPath()
{
return Application.dataPath + "/GameDate/Model";
}
private void OnGUI()
{
int folderIndex = EditorGUILayout.Popup(m_player._folderIndex, m_folderList.ToArray());
if (folderIndex != m_player._folderIndex)
{
m_player._folderIndex = folderIndex;
m_player._characterIndex = -1;
string folderName = m_folderList[m_player._folderIndex];
List<string> list;
if (folderName.Equals("all"))
{
list = m__characterList;
}
else
{
if (!m_folderPrefabs.TryGetValue(folderName, out list))
{
list = new List<string>();
string[] files = Directory.GetFiles(GetCharacterPath() + "/" + folderName, "*.prefab", SearchOption.AllDirectories);
foreach (var item in files)
{
list.Add(Path.GetFileNameWithoutExtension(item));
}
m_folderPrefabs[folderName] = list;
}
//SetPlayerCharacters(m_player, list);
}
m_player.characteList.Clear();
m_player.characteList.AddRange(list);
}
int characterIndex = EditorGUILayout.Popup(m_player._characterIndex, m_player.characteList.ToArray());
if (characterIndex != m_player._characterIndex)
{
m_player._characterIndex = characterIndex;
if (m_player.characterName != m_player.characteList[m_player._characterIndex])
{
m_player.characterName = m_player.characteList[m_player._characterIndex];
if (!string.IsNullOrEmpty(m_player.characterName))
{
if (m_player.player != null)
{
m_player.player.Destroy();
}
m_player.player = Player.Init(m_player.characterName);
}
}
}
/*float speed = EditorGUILayout.Slider((m_player.player == null ? 0f : m_player.player.AnimSpeed), 0.1f, 5);
if (m_player.player != null && m_player.player.AnimSpeed != speed)
{
m_player.player.AnimSpeed = speed;
}*/
newSkillName = GUILayout.TextField(newSkillName);
if (GUILayout.Button("创建新的技能"))
{
if (!string.IsNullOrEmpty(newSkillName) && m_player.player != null)
{
List<SkillBase> skills = m_player.player.AddNewSkill(newSkillName);
OpenSkillWindow(newSkillName, skills);
newSkillName = "";
}
}
if (m_player.player != null)
{
ScrollViewPos = GUILayout.BeginScrollView(ScrollViewPos, false, true);
foreach (var item in m_player.player.skillsList)
{
GUILayout.BeginHorizontal();
if (GUILayout.Button(item.Key))
{
List<SkillBase> skillComponents = m_player.player.GetSkill(item.Key);
foreach (var ite in skillComponents)
{
ite.Init();
}
OpenSkillWindow(item.Key, skillComponents);
}
GUILayoutOption[] option = new GUILayoutOption[] {
GUILayout.Width(60),
GUILayout.Height(19)
};
if (GUILayout.Button("删除技能", option))
{
m_player.player.RevSkill(item.Key);
break;
}
GUILayout.EndHorizontal();
}
GUILayout.EndScrollView();
}
}
Vector2 ScrollViewPos = new Vector2(0, 0);
void OpenSkillWindow(string newSkillName, List<SkillBase> skillComponents)
{
if (skillComponents != null)
{
if (skillWindow == null)
{
skillWindow = EditorWindow.GetWindow<SkillWindow>("");
}
skillWindow.titleContent = new GUIContent(newSkillName);
skillWindow.SetInitSkill(skillComponents, m_player.player);
skillWindow.Show();
skillWindow.Repaint();
}
}
/* void SetPlayerCharacters(PlayerEditor player, List<string> list)
{
player.characteList.Clear();
}*/
}