forked from MattRix/UnityDecompiled
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssetSaveDialog.cs
More file actions
268 lines (243 loc) · 7.1 KB
/
AssetSaveDialog.cs
File metadata and controls
268 lines (243 loc) · 7.1 KB
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
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
namespace UnityEditor
{
internal class AssetSaveDialog : EditorWindow
{
private class Styles
{
public GUIStyle selected = "ServerUpdateChangesetOn";
public GUIStyle box = "OL Box";
public GUIStyle button = "LargeButton";
public GUIContent saveSelected = EditorGUIUtility.TextContent("Save Selected");
public GUIContent saveAll = EditorGUIUtility.TextContent("Save All");
public GUIContent dontSave = EditorGUIUtility.TextContent("Don't Save");
public GUIContent close = EditorGUIUtility.TextContent("Close");
public float buttonWidth;
public Styles()
{
this.buttonWidth = Mathf.Max(Mathf.Max(this.button.CalcSize(this.saveSelected).x, this.button.CalcSize(this.saveAll).x), this.button.CalcSize(this.dontSave).x);
}
}
private static AssetSaveDialog.Styles s_Styles = null;
private List<string> m_Assets;
private List<string> m_AssetsToSave;
private ListViewState m_LV = new ListViewState();
private int m_InitialSelectedItem = -1;
private bool[] m_SelectedItems;
private List<GUIContent> m_Content;
private void SetAssets(string[] assets)
{
this.m_Assets = new List<string>(assets);
this.RebuildLists(true);
this.m_AssetsToSave = new List<string>();
}
public static void ShowWindow(string[] inAssets, out string[] assetsThatShouldBeSaved)
{
int num = 0;
for (int i = 0; i < inAssets.Length; i++)
{
string text = inAssets[i];
if (text.EndsWith("meta"))
{
num++;
}
}
int num2 = inAssets.Length - num;
if (num2 == 0)
{
assetsThatShouldBeSaved = inAssets;
}
else
{
string[] array = new string[num2];
string[] array2 = new string[num];
num2 = 0;
num = 0;
for (int j = 0; j < inAssets.Length; j++)
{
string text2 = inAssets[j];
if (text2.EndsWith("meta"))
{
array2[num++] = text2;
}
else
{
array[num2++] = text2;
}
}
AssetSaveDialog windowDontShow = EditorWindow.GetWindowDontShow<AssetSaveDialog>();
windowDontShow.titleContent = EditorGUIUtility.TextContent("Save Assets");
windowDontShow.SetAssets(array);
windowDontShow.ShowUtility();
windowDontShow.ShowModal();
assetsThatShouldBeSaved = new string[windowDontShow.m_AssetsToSave.Count + num];
windowDontShow.m_AssetsToSave.CopyTo(assetsThatShouldBeSaved, 0);
array2.CopyTo(assetsThatShouldBeSaved, windowDontShow.m_AssetsToSave.Count);
}
}
public static GUIContent GetContentForAsset(string path)
{
Texture cachedIcon = AssetDatabase.GetCachedIcon(path);
if (path.StartsWith("Library/"))
{
path = ObjectNames.NicifyVariableName(AssetDatabase.LoadMainAssetAtPath(path).name);
}
if (path.StartsWith("Assets/"))
{
path = path.Substring(7);
}
return new GUIContent(path, cachedIcon);
}
private void OnGUI()
{
if (AssetSaveDialog.s_Styles == null)
{
AssetSaveDialog.s_Styles = new AssetSaveDialog.Styles();
base.minSize = new Vector2(500f, 300f);
base.position = new Rect(base.position.x, base.position.y, base.minSize.x, base.minSize.y);
}
GUILayout.Space(10f);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Space(10f);
GUILayout.Label("Unity is about to save the following modified files. Unsaved changes will be lost!", new GUILayoutOption[0]);
GUILayout.Space(10f);
GUILayout.EndHorizontal();
GUILayout.Space(10f);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Space(10f);
int row = this.m_LV.row;
int num = 0;
IEnumerator enumerator = ListViewGUILayout.ListView(this.m_LV, AssetSaveDialog.s_Styles.box, new GUILayoutOption[0]).GetEnumerator();
try
{
while (enumerator.MoveNext())
{
ListViewElement listViewElement = (ListViewElement)enumerator.Current;
if (this.m_SelectedItems[listViewElement.row] && Event.current.type == EventType.Repaint)
{
Rect position = listViewElement.position;
position.x += 1f;
position.y += 1f;
position.width -= 1f;
position.height -= 1f;
AssetSaveDialog.s_Styles.selected.Draw(position, false, false, false, false);
}
GUILayout.Label(this.m_Content[listViewElement.row], new GUILayoutOption[0]);
if (ListViewGUILayout.HasMouseUp(listViewElement.position))
{
Event.current.command = true;
Event.current.control = true;
ListViewGUILayout.MultiSelection(row, listViewElement.row, ref this.m_InitialSelectedItem, ref this.m_SelectedItems);
}
if (this.m_SelectedItems[listViewElement.row])
{
num++;
}
}
}
finally
{
IDisposable disposable;
if ((disposable = (enumerator as IDisposable)) != null)
{
disposable.Dispose();
}
}
GUILayout.Space(10f);
GUILayout.EndHorizontal();
GUILayout.Space(10f);
GUILayout.BeginHorizontal(new GUILayoutOption[0]);
GUILayout.Space(10f);
if (GUILayout.Button(AssetSaveDialog.s_Styles.close, AssetSaveDialog.s_Styles.button, new GUILayoutOption[]
{
GUILayout.Width(AssetSaveDialog.s_Styles.buttonWidth)
}))
{
this.CloseWindow();
}
GUILayout.FlexibleSpace();
GUI.enabled = (num > 0);
bool flag = num == this.m_Assets.Count;
if (GUILayout.Button(AssetSaveDialog.s_Styles.dontSave, AssetSaveDialog.s_Styles.button, new GUILayoutOption[]
{
GUILayout.Width(AssetSaveDialog.s_Styles.buttonWidth)
}))
{
this.IgnoreSelectedAssets();
}
if (GUILayout.Button((!flag) ? AssetSaveDialog.s_Styles.saveSelected : AssetSaveDialog.s_Styles.saveAll, AssetSaveDialog.s_Styles.button, new GUILayoutOption[]
{
GUILayout.Width(AssetSaveDialog.s_Styles.buttonWidth)
}))
{
this.SaveSelectedAssets();
}
if (this.m_Assets.Count == 0)
{
this.CloseWindow();
}
GUI.enabled = true;
GUILayout.Space(10f);
GUILayout.EndHorizontal();
GUILayout.Space(10f);
}
private void Cancel()
{
base.Close();
GUIUtility.ExitGUI();
}
private void CloseWindow()
{
base.Close();
GUIUtility.ExitGUI();
}
private void SaveSelectedAssets()
{
List<string> list = new List<string>();
for (int i = 0; i < this.m_SelectedItems.Length; i++)
{
if (this.m_SelectedItems[i])
{
this.m_AssetsToSave.Add(this.m_Assets[i]);
}
else
{
list.Add(this.m_Assets[i]);
}
}
this.m_Assets = list;
this.RebuildLists(false);
}
private void IgnoreSelectedAssets()
{
List<string> list = new List<string>();
for (int i = 0; i < this.m_SelectedItems.Length; i++)
{
if (!this.m_SelectedItems[i])
{
list.Add(this.m_Assets[i]);
}
}
this.m_Assets = list;
this.RebuildLists(false);
if (this.m_Assets.Count == 0)
{
this.CloseWindow();
}
}
private void RebuildLists(bool selected)
{
this.m_LV.totalRows = this.m_Assets.Count;
this.m_SelectedItems = new bool[this.m_Assets.Count];
this.m_Content = new List<GUIContent>(this.m_Assets.Count);
for (int i = 0; i < this.m_Assets.Count; i++)
{
this.m_SelectedItems[i] = selected;
this.m_Content.Add(AssetSaveDialog.GetContentForAsset(this.m_Assets[i]));
}
}
}
}