Nextrek
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
|
//----------------------------------------------
// NGUI: Next-Gen UI kit
// Copyright © 2011-2013 Tasharen Entertainment
//----------------------------------------------
using UnityEngine;
using UnityEditor;
using System.Collections.Generic;
public class NGUISelectionTools
{
[MenuItem("GameObject/Selection/Force Delete")]
static void ForceDelete()
{
Object[] gos = Selection.GetFiltered(typeof(GameObject), SelectionMode.TopLevel);
if (gos != null && gos.Length > 0)
{
for (int i = 0; i < gos.Length; ++i)
{
Object go = gos[i];
NGUITools.DestroyImmediate(go);
}
}
}
[MenuItem("GameObject/Selection/Toggle 'Active' #&a")]
static void ActivateDeactivate()
{
if (HasValidTransform())
{
GameObject[] gos = Selection.gameObjects;
bool val = !NGUITools.GetActive(Selection.activeGameObject);
foreach (GameObject go in gos) NGUITools.SetActive(go, val);
}
}
[MenuItem("GameObject/Selection/Clear Local Transform")]
static void ClearLocalTransform()
{
if (HasValidTransform())
{
Transform t = Selection.activeTransform;
NGUIEditorTools.RegisterUndo("Clear Local Transform", t);
t.localPosition = Vector3.zero;
t.localRotation = Quaternion.identity;
t.localScale = Vector3.one;
}
}
[MenuItem("GameObject/Selection/Add New Child #&n")]
static void CreateLocalGameObject ()
{
if (PrefabCheck())
{
// Make this action undoable
NGUIEditorTools.RegisterUndo("Add New Child");
// Create our new GameObject
GameObject newGameObject = new GameObject();
newGameObject.name = "GameObject";
// If there is a selected object in the scene then make the new object its child.
if (Selection.activeTransform != null)
{
newGameObject.transform.parent = Selection.activeTransform;
newGameObject.name = "Child";
// Place the new GameObject at the same position as the parent.
newGameObject.transform.localPosition = Vector3.zero;
newGameObject.transform.localRotation = Quaternion.identity;
newGameObject.transform.localScale = new Vector3(1f, 1f, 1f);
newGameObject.layer = Selection.activeGameObject.layer;
}
// Select our newly created GameObject
Selection.activeGameObject = newGameObject;
}
}
[MenuItem("GameObject/Selection/List Dependencies")]
static void ListDependencies()
{
if (HasValidSelection())
{
Debug.Log("Selection depends on the following assets:\n\n" + GetDependencyText(Selection.objects, false));
}
}
//========================================================================================================
#region Helper Functions
class AssetEntry
{
public string path;
public List<System.Type> types = new List<System.Type>();
}
/// <summary>
/// Helper function that checks to see if there are objects selected.
/// </summary>
static bool HasValidSelection()
{
if (Selection.objects == null || Selection.objects.Length == 0)
{
Debug.LogWarning("You must select an object first");
return false;
}
return true;
}
/// <summary>
/// Helper function that checks to see if there is an object with a Transform component selected.
/// </summary>
static bool HasValidTransform()
{
if (Selection.activeTransform == null)
{
Debug.LogWarning("You must select an object first");
return false;
}
return true;
}
/// <summary>
/// Helper function that checks to see if a prefab is currently selected.
/// </summary>
static bool PrefabCheck()
{
if (Selection.activeTransform != null)
{
// Check if the selected object is a prefab instance and display a warning
PrefabType type = PrefabUtility.GetPrefabType(Selection.activeGameObject);
if (type == PrefabType.PrefabInstance)
{
return EditorUtility.DisplayDialog("Losing prefab",
"This action will lose the prefab connection. Are you sure you wish to continue?",
"Continue", "Cancel");
}
}
return true;
}
/// <summary>
/// Function that collects a list of file dependencies from the specified list of objects.
/// </summary>
static List<AssetEntry> GetDependencyList (Object[] objects, bool reverse)
{
Object[] deps = reverse ? EditorUtility.CollectDeepHierarchy(objects) : EditorUtility.CollectDependencies(objects);
List<AssetEntry> list = new List<AssetEntry>();
foreach (Object obj in deps)
{
string path = AssetDatabase.GetAssetPath(obj);
if (!string.IsNullOrEmpty(path))
{
bool found = false;
System.Type type = obj.GetType();
foreach (AssetEntry ent in list)
{
if (ent.path.Equals(path))
{
if (!ent.types.Contains(type)) ent.types.Add(type);
found = true;
break;
}
}
if (!found)
{
AssetEntry ent = new AssetEntry();
ent.path = path;
ent.types.Add(type);
list.Add(ent);
}
}
}
deps = null;
objects = null;
return list;
}
/// <summary>
/// Helper function that removes the Unity class prefix from the specified string.
/// </summary>
static string RemovePrefix (string text)
{
text = text.Replace("UnityEngine.", "");
text = text.Replace("UnityEditor.", "");
return text;
}
/// <summary>
/// Helper function that gets the dependencies of specified objects and returns them in text format.
/// </summary>
static string GetDependencyText (Object[] objects, bool reverse)
{
List<AssetEntry> dependencies = GetDependencyList(objects, reverse);
List<string> list = new List<string>();
string text = "";
foreach (AssetEntry ae in dependencies)
{
text = ae.path.Replace("Assets/", "");
if (ae.types.Count > 1)
{
text += " (" + RemovePrefix(ae.types[0].ToString());
for (int i = 1; i < ae.types.Count; ++i)
{
text += ", " + RemovePrefix(ae.types[i].ToString());
}
text += ")";
}
list.Add(text);
}
list.Sort();
text = "";
foreach (string s in list) text += s + "\n";
list.Clear();
list = null;
dependencies.Clear();
dependencies = null;
return text;
}
#endregion
}
|
Revision |
Author |
Commited |
Message |
83
|
FMMortaroli
|
Tue 13 May, 2014 11:32:51 +0000 |
|