├── .gitignore
├── Assets
├── 2086.gif
├── 2086.gif.meta
├── 6408.png
├── 6408.png.meta
├── 6409.png
├── 6409.png.meta
├── Editor.meta
├── Editor
│ ├── AssetsDependenciesTool.meta
│ └── AssetsDependenciesTool
│ │ ├── DependenciesByTool.cs
│ │ ├── DependenciesByTool.cs.meta
│ │ ├── DependenciesTool.cs
│ │ ├── DependenciesTool.cs.meta
│ │ ├── ShowSelectedObjectsTool.cs
│ │ └── ShowSelectedObjectsTool.cs.meta
├── Image 1.prefab
├── Image 1.prefab.meta
├── Image.prefab
├── Image.prefab.meta
├── test.unity
└── test.unity.meta
├── ProjectSettings
├── AudioManager.asset
├── DynamicsManager.asset
├── EditorBuildSettings.asset
├── EditorSettings.asset
├── GraphicsSettings.asset
├── InputManager.asset
├── NavMeshLayers.asset
├── NetworkManager.asset
├── Physics2DSettings.asset
├── ProjectSettings.asset
├── QualitySettings.asset
├── TagManager.asset
└── TimeManager.asset
├── README.md
├── by.png
└── pro.png
/.gitignore:
--------------------------------------------------------------------------------
1 | Library/*
2 | Temp/*
3 | *.csproj
4 | *.sln
5 | *.suo
6 | *.userprefs
7 | obj/*
8 |
--------------------------------------------------------------------------------
/Assets/2086.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/Assets/2086.gif
--------------------------------------------------------------------------------
/Assets/2086.gif.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: f4fd9ef8b07365742aa919db3f04eb9f
3 | TextureImporter:
4 | fileIDToRecycleName: {}
5 | serializedVersion: 2
6 | mipmaps:
7 | mipMapMode: 0
8 | enableMipMap: 0
9 | linearTexture: 0
10 | correctGamma: 0
11 | fadeOut: 0
12 | borderMipMap: 0
13 | mipMapFadeDistanceStart: 1
14 | mipMapFadeDistanceEnd: 3
15 | bumpmap:
16 | convertToNormalMap: 0
17 | externalNormalMap: 0
18 | heightScale: .25
19 | normalMapFilter: 0
20 | isReadable: 0
21 | grayScaleToAlpha: 0
22 | generateCubemap: 0
23 | seamlessCubemap: 0
24 | textureFormat: -1
25 | maxTextureSize: 1024
26 | textureSettings:
27 | filterMode: -1
28 | aniso: -1
29 | mipBias: -1
30 | wrapMode: 1
31 | nPOTScale: 0
32 | lightmap: 0
33 | compressionQuality: 50
34 | spriteMode: 1
35 | spriteExtrude: 1
36 | spriteMeshType: 1
37 | alignment: 0
38 | spritePivot: {x: .5, y: .5}
39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
40 | spritePixelsToUnits: 100
41 | alphaIsTransparency: 1
42 | textureType: 8
43 | buildTargetSettings: []
44 | spriteSheet:
45 | sprites: []
46 | spritePackingTag:
47 | userData:
48 |
--------------------------------------------------------------------------------
/Assets/6408.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/Assets/6408.png
--------------------------------------------------------------------------------
/Assets/6408.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ec30eda7ae798bc498a303ae9ae78c51
3 | TextureImporter:
4 | fileIDToRecycleName: {}
5 | serializedVersion: 2
6 | mipmaps:
7 | mipMapMode: 0
8 | enableMipMap: 0
9 | linearTexture: 0
10 | correctGamma: 0
11 | fadeOut: 0
12 | borderMipMap: 0
13 | mipMapFadeDistanceStart: 1
14 | mipMapFadeDistanceEnd: 3
15 | bumpmap:
16 | convertToNormalMap: 0
17 | externalNormalMap: 0
18 | heightScale: .25
19 | normalMapFilter: 0
20 | isReadable: 0
21 | grayScaleToAlpha: 0
22 | generateCubemap: 0
23 | seamlessCubemap: 0
24 | textureFormat: -1
25 | maxTextureSize: 1024
26 | textureSettings:
27 | filterMode: -1
28 | aniso: -1
29 | mipBias: -1
30 | wrapMode: 1
31 | nPOTScale: 0
32 | lightmap: 0
33 | compressionQuality: 50
34 | spriteMode: 1
35 | spriteExtrude: 1
36 | spriteMeshType: 1
37 | alignment: 0
38 | spritePivot: {x: .5, y: .5}
39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
40 | spritePixelsToUnits: 100
41 | alphaIsTransparency: 1
42 | textureType: 8
43 | buildTargetSettings: []
44 | spriteSheet:
45 | sprites: []
46 | spritePackingTag:
47 | userData:
48 |
--------------------------------------------------------------------------------
/Assets/6409.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/Assets/6409.png
--------------------------------------------------------------------------------
/Assets/6409.png.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 8d8c23729dc82554e8a2de5f33bf1409
3 | TextureImporter:
4 | fileIDToRecycleName: {}
5 | serializedVersion: 2
6 | mipmaps:
7 | mipMapMode: 0
8 | enableMipMap: 0
9 | linearTexture: 0
10 | correctGamma: 0
11 | fadeOut: 0
12 | borderMipMap: 0
13 | mipMapFadeDistanceStart: 1
14 | mipMapFadeDistanceEnd: 3
15 | bumpmap:
16 | convertToNormalMap: 0
17 | externalNormalMap: 0
18 | heightScale: .25
19 | normalMapFilter: 0
20 | isReadable: 0
21 | grayScaleToAlpha: 0
22 | generateCubemap: 0
23 | seamlessCubemap: 0
24 | textureFormat: -1
25 | maxTextureSize: 1024
26 | textureSettings:
27 | filterMode: -1
28 | aniso: -1
29 | mipBias: -1
30 | wrapMode: 1
31 | nPOTScale: 0
32 | lightmap: 0
33 | compressionQuality: 50
34 | spriteMode: 1
35 | spriteExtrude: 1
36 | spriteMeshType: 1
37 | alignment: 0
38 | spritePivot: {x: .5, y: .5}
39 | spriteBorder: {x: 0, y: 0, z: 0, w: 0}
40 | spritePixelsToUnits: 100
41 | alphaIsTransparency: 1
42 | textureType: 8
43 | buildTargetSettings: []
44 | spriteSheet:
45 | sprites: []
46 | spritePackingTag:
47 | userData:
48 |
--------------------------------------------------------------------------------
/Assets/Editor.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 02dc2263cd4c84f478d02c62eb837fcf
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 373029374679b444dbd3567a40a98deb
3 | folderAsset: yes
4 | DefaultImporter:
5 | userData:
6 |
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool/DependenciesByTool.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Reflection;
6 | using System.Text;
7 | using System.Text.RegularExpressions;
8 | using UnityEditor;
9 | using UnityEngine;
10 |
11 | [InitializeOnLoad]
12 | public class DependenciesByTool : AssetPostprocessor
13 | {
14 | private static ObjectRepo repo;
15 | private static bool initialized = false;
16 |
17 | static DependenciesByTool()
18 | {
19 | Initialize ();
20 | }
21 |
22 | private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets,
23 | string[] movedAssets, string[] movedFromAssetPaths)
24 | {
25 | bool needSerialize = false;
26 | Initialize ();
27 | for (int i=0; importedAssets != null && i < importedAssets.Length; ++i)
28 | {
29 | if(repo.ImportAsset(importedAssets[i]))
30 | {
31 | needSerialize = true;
32 | }
33 | }
34 | for (int i=0; deletedAssets != null && i < deletedAssets.Length; ++i)
35 | {
36 | repo.DeleteAsset(deletedAssets[i]);
37 | needSerialize = true;
38 | }
39 | if(needSerialize)
40 | {
41 | repo.Finialize();
42 | }
43 | }
44 |
45 | private static void Initialize()
46 | {
47 | if (false == initialized)
48 | {
49 | repo = new ObjectRepo ();
50 | repo.Initialize ();
51 | initialized = true;
52 | }
53 | }
54 | ///
55 | /// Select Objects which depend by selected Objects
56 | ///
57 | [MenuItem("Assets/Select Dependencies By/All")]
58 | private static void SelectDependenciesByAll()
59 | {
60 | _GetDependenciesBy();
61 | }
62 |
63 | #if UNITY_5
64 | [MenuItem("Assets/Select Dependencies By/All Directly")]
65 | private static void SelectDirectlyDependenciesByAll()
66 | {
67 | _GetDependenciesBy (true);
68 | }
69 | #endif
70 |
71 | [MenuItem("Assets/Select Dependencies By/AnimationController")]
72 | private static void SelectDependenciesByAnimationController()
73 | {
74 | _GetDependenciesBy(".controller");
75 | }
76 |
77 | [MenuItem("Assets/Select Dependencies By/Material")]
78 | private static void SelectDependenciesByMaterial()
79 | {
80 | _GetDependenciesBy();
81 | }
82 |
83 | [MenuItem("Assets/Select Dependencies By/Mesh")]
84 | private static void SelectDependenciesByMesh()
85 | {
86 | _GetDependenciesBy();
87 | }
88 |
89 | [MenuItem("Assets/Select Dependencies By/Model")]
90 | private static void SelectDependenciesByModel()
91 | {
92 | _GetDependenciesBy(".fbx");
93 | }
94 |
95 | [MenuItem("Assets/Select Dependencies By/Prefab")]
96 | private static void SelectDependenciesByPrefab()
97 | {
98 | _GetDependenciesBy(".prefab");
99 | }
100 |
101 | [MenuItem("Assets/Select Dependencies By/Scene")]
102 | private static void SelectDependenciesByScene()
103 | {
104 | _GetDependenciesBy(".unity");
105 | }
106 |
107 | [MenuItem("Assets/Select Dependencies By/PhysicMaterial")]
108 | private static void SelectDependenciesByPhysicMaterial()
109 | {
110 | _GetDependenciesBy();
111 | }
112 |
113 | [MenuItem("Assets/DependencyTool/Initialize")]
114 | private static void ShowDependencyInHierarchy()
115 | {
116 | repo = new ObjectRepo ();
117 | repo.Initialize (true);
118 | initialized = true;
119 | }
120 |
121 | ///
122 | /// Gets the dependencies by assetPathName
123 | ///
124 | /// The dependencies by.
125 | /// Asset path name.
126 | /// If set to true directly depend.
127 | public static List GetDependenciesBy(string assetPathName, bool directlyDepend)
128 | {
129 | List assetPathDependenciesBy = new List();
130 | string guid = AssetDatabase.AssetPathToGUID(assetPathName);
131 |
132 | List assetGuidDependenciesBy = repo.GetDepencenciesBy(guid);
133 | for (int i = 0; i < assetGuidDependenciesBy.Count; ++i)
134 | {
135 | string path = AssetDatabase.GUIDToAssetPath(assetGuidDependenciesBy[i]);
136 | assetPathDependenciesBy.Add(path);
137 | }
138 |
139 | for (int i = assetPathDependenciesBy.Count-1; i >=0 ; --i)
140 | {
141 | List dependencies = new List ();
142 | #if UNITY_5
143 | dependencies.AddRange (AssetDatabase.GetDependencies (new string[]{ assetPathDependenciesBy [i] }, !directlyDepend));
144 | #else
145 | dependencies.AddRange (AssetDatabase.GetDependencies (new string[]{ assetPathDependenciesBy [i] });
146 | #endif
147 | string path = AssetDatabase.GUIDToAssetPath (guid);
148 | if (!dependencies.Contains (path))
149 | {
150 | assetPathDependenciesBy.RemoveAt (i);
151 | }
152 | }
153 |
154 | return assetPathDependenciesBy;
155 | }
156 |
157 | ///
158 | /// Gets the dependencies by assetPathName
159 | ///
160 | /// The dependencies by.
161 | /// Asset path name.
162 | /// Type suffix.
163 | /// If set to true directly depend.
164 | public static List GetDependenciesBy(string assetPathName, string typeSuffix, bool directlyDepend)
165 | {
166 | List assetPathDependenciesBy = GetDependenciesBy(assetPathName, directlyDepend);
167 | for (int i = assetPathDependenciesBy.Count - 1; i >= 0; --i)
168 | {
169 | if (!assetPathDependenciesBy[i].ToLower().EndsWith(typeSuffix))
170 | {
171 | assetPathDependenciesBy.RemoveAt(i);
172 | }
173 | }
174 | return assetPathDependenciesBy;
175 | }
176 |
177 | private static void _GetDependenciesBy(bool directlyDepend = false) where T : UnityEngine.Object
178 | {
179 | string[] selections = Selection.assetGUIDs;
180 | List assetPathDependenciesBy = new List();
181 | for (int i = 0; selections != null && i < selections.Length; ++i)
182 | {
183 | string path = AssetDatabase.GUIDToAssetPath(selections[i]);
184 | assetPathDependenciesBy.AddRange(GetDependenciesBy(path, directlyDepend));
185 | }
186 | ShowSelectedObjectsTool.ShowSelectedObjectsInProjectBrowser(assetPathDependenciesBy);
187 | }
188 |
189 | private static void _GetDependenciesBy(string type, bool directlyDepend = false)
190 | {
191 | string[] selections = Selection.assetGUIDs;
192 | List assetPathDependenciesBy = new List();
193 | for (int i = 0; selections != null && i < selections.Length; ++i)
194 | {
195 | string path = AssetDatabase.GUIDToAssetPath(selections[i]);
196 | assetPathDependenciesBy.AddRange(GetDependenciesBy(path, type, directlyDepend));
197 | }
198 | ShowSelectedObjectsTool.ShowSelectedObjectsInProjectBrowser(assetPathDependenciesBy);
199 | }
200 | }
201 |
202 | public class ObjectRepo
203 | {
204 | private Dictionary> dicDepBy;
205 | private Dictionary> dicDep;
206 | private static string configFilePath = Application.dataPath + "/../Library/DependenciesBy.config";
207 | private static string tmpConfigFilePath = Application.dataPath + "/../Library/DependenciesBy_tmp.config";
208 | private string contentStr;
209 | private List lstChanged = new List();
210 | private List lstMoved = new List();
211 | private List lstAdded = new List();
212 | private static string usrOptionKey = "USER_OPTION";
213 |
214 | public void Initialize(bool forceReimport = false)
215 | {
216 | if (File.Exists (configFilePath) && !forceReimport)
217 | {
218 | Deserialize ();
219 | }
220 | else
221 | {
222 | bool option = false;
223 | if (forceReimport)
224 | {
225 | option = true;
226 | }
227 | else if (PlayerPrefs.HasKey(usrOptionKey))
228 | {
229 | option = false;
230 | }
231 | else
232 | {
233 | option = EditorUtility.DisplayDialog ("Info", "Dependency tool need to walk through your working repository. " +
234 | "This may take a few minutes(depending on the assets num). You can ignore this and initialize it manual from Menu(Assets/DependencyTool/Initialize). " +
235 | "Generate Now?", "OK", "Cancel");
236 | }
237 | if (option)
238 | {
239 | PlayerPrefs.DeleteKey(usrOptionKey);
240 | PlayerPrefs.Save();
241 | ParseFromRepo();
242 | }
243 | else
244 | {
245 | PlayerPrefs.SetInt(usrOptionKey, 1);
246 | PlayerPrefs.Save();
247 | dicDepBy = new Dictionary>();
248 | dicDep = new Dictionary>();
249 | }
250 | }
251 | }
252 |
253 | public void Finialize()
254 | {
255 | Serialize ();
256 | }
257 |
258 | public List GetDepencenciesBy(string guid)
259 | {
260 | if (dicDepBy.ContainsKey (guid)) {
261 | return dicDepBy [guid];
262 | } else {
263 | return null;
264 | }
265 | }
266 |
267 | public void ParseFromRepo()
268 | {
269 | string[] assets = AssetDatabase.GetAllAssetPaths();
270 | dicDepBy = new Dictionary>(assets.Length);
271 | dicDep = new Dictionary>(assets.Length);
272 |
273 | for (int i = 0; assets != null && i < assets.Length; ++i)
274 | {
275 | EditorUtility.DisplayProgressBar("Dependencies Tool Initializing",
276 | "this may take a few minutes, progress:" + i + "/" + assets.Length,
277 | (float)i / assets.Length);
278 | ImportAsset(assets[i]);
279 | }
280 | if (assets != null && assets.Length > 0)
281 | {
282 | EditorUtility.ClearProgressBar();
283 | }
284 |
285 | Serialize();
286 | }
287 |
288 | public bool ImportAsset(string assetPath)
289 | {
290 | if(!assetPath.StartsWith("Assets/") ||
291 | Directory.Exists(Application.dataPath + "/../" + assetPath))
292 | return false;
293 |
294 | string guid = AssetDatabase.AssetPathToGUID (assetPath);
295 | string[] dependencies = AssetDatabase.GetDependencies(new string[]{assetPath});
296 |
297 | if (dependencies == null || dependencies.Length == 0)
298 | return false;
299 |
300 | List lstDep = null;
301 | bool assetModified = false;
302 |
303 | if (false == dicDep.TryGetValue(guid, out lstDep))
304 | {
305 | lstDep = new List();
306 | dicDep[guid] = lstDep;
307 | if (!lstAdded.Contains(guid))
308 | {
309 | lstAdded.Add(guid);
310 | }
311 | }
312 | for (int i=0; dependencies != null && i < dependencies.Length; ++i)
313 | {
314 | //if(dependencies[i] == assetPath) continue; // Ignore myself
315 |
316 | // add dicDepBy
317 | string depGuid = AssetDatabase.AssetPathToGUID(dependencies[i]);
318 | List lstDepBy = null;
319 | dicDepBy.TryGetValue(depGuid, out lstDepBy);
320 | if(null == lstDepBy)
321 | {
322 | lstDepBy = new List();
323 | dicDepBy[depGuid] = lstDepBy;
324 | }
325 | if(false == lstDepBy.Contains(guid))
326 | {
327 | lstDepBy.Add(guid);
328 | if(!lstChanged.Contains(depGuid))
329 | {
330 | lstChanged.Add(depGuid);
331 | }
332 | }
333 |
334 | // add dicDep
335 | if(false == lstDep.Contains(depGuid))
336 | {
337 | lstDep.Add(depGuid);
338 | assetModified = true;
339 | }
340 |
341 | if (lstDep.Count < 1)
342 | {
343 | Debug.LogError(string.Format("Parse Asset {0} Dependency error", assetPath));
344 | if (dicDep.ContainsKey(guid))
345 | {
346 | dicDep.Remove(guid);
347 | }
348 | }
349 | }
350 |
351 | if (assetModified && !lstChanged.Contains(guid))
352 | {
353 | lstChanged.Add(guid);
354 | }
355 |
356 | return assetModified;
357 | }
358 |
359 | public void DeleteAsset(string assetPath)
360 | {
361 | string guid = AssetDatabase.AssetPathToGUID (assetPath);
362 | List lstDep = null;
363 | List lstDepBy = null;
364 |
365 | dicDep.TryGetValue (guid, out lstDep);
366 | dicDepBy.TryGetValue (guid, out lstDepBy);
367 | if (!lstMoved.Contains(guid))
368 | {
369 | lstMoved.Add(guid);
370 | }
371 | for (int i=0; lstDep != null && i>();
398 | dicDep = new Dictionary> ();
399 | string[] allLines = File.ReadAllLines (configFilePath);
400 | for (int index = 0; allLines != null && index < allLines.Length; ++index)
401 | {
402 | string[] objectAndDep = allLines[index].Split(new char[]{':'}, System.StringSplitOptions.RemoveEmptyEntries);
403 | if(objectAndDep.Length == 2)
404 | {
405 | List lstDepBy = new List();
406 | string[] dependencies = objectAndDep[1].Split(new char[]{';'}, System.StringSplitOptions.RemoveEmptyEntries);
407 | if(dependencies != null)
408 | {
409 | lstDepBy.AddRange(dependencies);
410 | }
411 | dicDepBy[objectAndDep[0]] = lstDepBy;
412 |
413 | for(int i=0; dependencies != null && i lstDep = null;
416 | dicDep.TryGetValue(dependencies[i], out lstDep);
417 | if(null == lstDep)
418 | {
419 | lstDep = new List();
420 | dicDep.Add(dependencies[i], lstDep);
421 | }
422 | lstDep.Add(objectAndDep[0]);
423 | }
424 | }
425 | else if(objectAndDep.Length > 0)
426 | {
427 | File.Delete (configFilePath);
428 | bool option = false;
429 | if (PlayerPrefs.HasKey(usrOptionKey))
430 | {
431 | option = false;
432 | }
433 | else
434 | {
435 | option = EditorUtility.DisplayDialog ("Warning", "Dependency tool find the config file is broken. " +
436 | "Suggest you regenerate the config file." +
437 | "This may take a few minutes(depending on the assets num). You can ignore this and initialize it manual from Menu(Assets/DependencyTool/Initialize). " +
438 | "Generate Now?", "Generate", "Next time");
439 | }
440 | if (option)
441 | {
442 | PlayerPrefs.DeleteKey(usrOptionKey);
443 | PlayerPrefs.Save();
444 | ParseFromRepo();
445 | }
446 | else
447 | {
448 | PlayerPrefs.SetInt(usrOptionKey, 1);
449 | PlayerPrefs.Save();
450 | dicDepBy = new Dictionary>();
451 | dicDep = new Dictionary>();
452 | }
453 |
454 | Debug.LogError(string.Format("Config file is broken at line {0}, suggests rebuild it when needed or free", index+1));
455 | }
456 | }
457 | }
458 |
459 | private void Serialize()
460 | {
461 | if(string.IsNullOrEmpty(contentStr))
462 | {
463 | StringBuilder content = new StringBuilder();
464 |
465 | if (null == dicDepBy)
466 | {
467 | Debug.LogError("Need to Initialze First");
468 | return;
469 | }
470 | int num = 0;
471 | foreach (KeyValuePair> keyValue in dicDepBy)
472 | {
473 | num++;
474 | List lstDepBy = keyValue.Value;
475 | content.Append(keyValue.Key);
476 | content.Append(":");
477 | //EditorUtility.DisplayProgressBar("Dependencies Tool Initializing", num + "/" + dicDepBy.Count, (float)num / dicDepBy.Count);
478 | StringBuilder builder = new StringBuilder();
479 | for (int index = 0; lstDepBy != null && index < lstDepBy.Count; ++index)
480 | {
481 | builder.Append(lstDepBy[index]);
482 | builder.Append(";");
483 | }
484 | content.Append(builder);
485 | content.Append("\r\n");
486 | }
487 | //EditorUtility.ClearProgressBar();
488 |
489 | contentStr = content.ToString();
490 | }
491 | else
492 | {
493 | // move the deleted assets
494 | for(int i=0; i lstDepBy = null;
505 | addedBuilder.Append(":");
506 | if (dicDepBy.TryGetValue(lstAdded[i], out lstDepBy))
507 | {
508 | for (int index = 0; lstDepBy != null && index < lstDepBy.Count; ++index)
509 | {
510 | addedBuilder.Append(lstDepBy[index]);
511 | addedBuilder.Append(";");
512 | }
513 | }
514 | addedBuilder.Append("\r\n");
515 | contentStr += addedBuilder.ToString();
516 | }
517 | // modify the changes assets
518 | for(int i=0; i lstDepBy = null;
524 | replacementBuilder.Append(":");
525 | if(dicDepBy.TryGetValue(lstChanged[i], out lstDepBy))
526 | {
527 | for (int index = 0; lstDepBy != null && index < lstDepBy.Count; ++index)
528 | {
529 | replacementBuilder.Append(lstDepBy[index]);
530 | replacementBuilder.Append(";");
531 | }
532 | }
533 | replacementBuilder.Append("\r\n");
534 | contentStr = Regex.Replace(contentStr, patternBuilder.ToString(), replacementBuilder.ToString());
535 | }
536 | }
537 | lstAdded.Clear();
538 | lstMoved.Clear();
539 | lstChanged.Clear();
540 |
541 | using (FileStream fileStream = new FileStream(tmpConfigFilePath,
542 | File.Exists(tmpConfigFilePath) ? FileMode.Truncate : FileMode.OpenOrCreate))
543 | {
544 | byte[] bytes = System.Text.Encoding.Default.GetBytes(contentStr.ToString());
545 | fileStream.Write(bytes, 0, bytes.Length);
546 | fileStream.Close();
547 | fileStream.Dispose();
548 |
549 | if (File.Exists(configFilePath))
550 | {
551 | File.Delete(configFilePath);
552 | }
553 | File.Move(tmpConfigFilePath, configFilePath);
554 | }
555 | }
556 | }
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool/DependenciesByTool.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: 9c7dfec269a540744bac36703b7eacdb
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool/DependenciesTool.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UnityEditor;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 |
6 | public class DependenciesTool
7 | {
8 | [MenuItem("Assets/Select Dependencies Pro/All")]
9 | private static void SelectDependenciesAll()
10 | {
11 | _GetDependencies();
12 | }
13 |
14 | #if UNITY_5
15 | [MenuItem("Assets/Select Dependencies Pro/All Directly")]
16 | private static void SelectDirectlyDependenciesAll()
17 | {
18 | _GetDependencies (true);
19 | }
20 | #endif
21 |
22 | [MenuItem("Assets/Select Dependencies Pro/AnimationClip")]
23 | private static void SelectAnimationClipDependencies()
24 | {
25 | _GetDependencies();
26 | }
27 |
28 | [MenuItem("Assets/Select Dependencies Pro/AnimationContoller")]
29 | private static void SelectAnimationControllerDependencies()
30 | {
31 | _GetDependencies(".contorller");
32 | }
33 |
34 | [MenuItem("Assets/Select Dependencies Pro/AudioClip")]
35 | private static void SelectAudioDependencies()
36 | {
37 | _GetDependencies();
38 | }
39 |
40 | [MenuItem("Assets/Select Dependencies Pro/Font")]
41 | private static void SelectFontDependencies()
42 | {
43 | _GetDependencies();
44 | }
45 |
46 | [MenuItem("Assets/Select Dependencies Pro/Material")]
47 | private static void SelectMaterialDependencies()
48 | {
49 | _GetDependencies();
50 | }
51 |
52 | [MenuItem("Assets/Select Dependencies Pro/Mesh")]
53 | private static void SelectMeshDependencies()
54 | {
55 | _GetDependencies();
56 | }
57 |
58 |
59 | [MenuItem("Assets/Select Dependencies Pro/Model")]
60 | private static void SelectModelDependencies()
61 | {
62 | _GetDependencies(".fbx");
63 | }
64 |
65 | [MenuItem("Assets/Select Dependencies Pro/PhysicMaterial")]
66 | private static void SelectPhysicMaterialDependencies()
67 | {
68 | _GetDependencies();
69 | }
70 |
71 | [MenuItem("Assets/Select Dependencies Pro/Prefab")]
72 | private static void SelectPrefabDependencies()
73 | {
74 | _GetDependencies(".prefab");
75 | }
76 |
77 | [MenuItem("Assets/Select Dependencies Pro/Script")]
78 | private static void SelectScriptDependencies()
79 | {
80 | _GetDependencies(".cs");
81 | }
82 |
83 | [MenuItem("Assets/Select Dependencies Pro/Shader")]
84 | private static void SelectShaderDependencies()
85 | {
86 | _GetDependencies();
87 | }
88 |
89 | [MenuItem("Assets/Select Dependencies Pro/Texture")]
90 | private static void SelectTextureDependencies()
91 | {
92 | _GetDependencies();
93 | }
94 |
95 | [MenuItem("Assets/Select Dependencies Pro/Sprite")]
96 | private static void SelectSpriteDependencies()
97 | {
98 | _GetDependencies();
99 | }
100 |
101 | private static void _GetDependencies(bool directlyDepend = false) where T : UnityEngine.Object
102 | {
103 | string[] selections = Selection.assetGUIDs;
104 | List lstPathNames = new List();
105 | List assetPathDependenciesBy = new List();
106 | for (int i = 0; selections != null && i < selections.Length; ++i)
107 | {
108 | lstPathNames.Add(AssetDatabase.GUIDToAssetPath(selections[i]));
109 | }
110 | #if UNITY_5
111 | assetPathDependenciesBy.AddRange(AssetDatabase.GetDependencies(lstPathNames.ToArray(), !directlyDepend));
112 | #else
113 | assetPathDependenciesBy.AddRange(AssetDatabase.GetDependencies(lstPathNames.ToArray());
114 | #endif
115 | ShowSelectedObjectsTool.ShowSelectedObjectsInProjectBrowser(assetPathDependenciesBy);
116 | }
117 |
118 | private static void _GetDependencies(string type)
119 | {
120 | string[] selections = Selection.assetGUIDs;
121 | List lstPathNames = new List();
122 | List assetPathDependenciesBy = new List();
123 | for (int i = 0; selections != null && i < selections.Length; ++i)
124 | {
125 | lstPathNames.Add(AssetDatabase.GUIDToAssetPath(selections[i]));
126 | }
127 | assetPathDependenciesBy.AddRange(AssetDatabase.GetDependencies(lstPathNames.ToArray()));
128 | for (int i = assetPathDependenciesBy.Count - 1; i >= 0; --i)
129 | {
130 | if(!assetPathDependenciesBy[i].ToLower().EndsWith(type))
131 | {
132 | assetPathDependenciesBy.RemoveAt(i);
133 | }
134 | }
135 | ShowSelectedObjectsTool.ShowSelectedObjectsInProjectBrowser(assetPathDependenciesBy);
136 | }
137 | }
138 |
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool/DependenciesTool.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ab836083d5b866e42a10d5656fa3edc9
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool/ShowSelectedObjectsTool.cs:
--------------------------------------------------------------------------------
1 | using UnityEngine;
2 | using UnityEditor;
3 | using System.Collections;
4 | using System.Collections.Generic;
5 | using System;
6 | using System.Reflection;
7 |
8 | public class ShowSelectedObjectsTool
9 | {
10 | public static void ShowSelectedObjectsInProjectBrowser(List objectPaths) where T : UnityEngine.Object
11 | {
12 | List dependenciesByPaths = new List();
13 | if (objectPaths != null)
14 | {
15 | for (int i = 0; i < objectPaths.Count; ++i)
16 | {
17 | EditorUtility.DisplayProgressBar("Loading Dependencies", "loading...", (float)i / objectPaths.Count);
18 | UnityEngine.Object obj = AssetDatabase.LoadAssetAtPath(objectPaths[i], typeof(T));
19 | if(obj != null)
20 | {
21 | dependenciesByPaths.Add(obj);
22 | }
23 | }
24 | EditorUtility.ClearProgressBar();
25 | Selection.objects = dependenciesByPaths.ToArray();
26 | ShowSelectionInProjectHierarchy();
27 | }
28 | }
29 |
30 | private static void ShowSelectionInProjectHierarchy()
31 | {
32 | Type pbType = GetType("UnityEditor.ProjectBrowser");
33 | MethodInfo meth = pbType.GetMethod("ShowSelectedObjectsInLastInteractedProjectBrowser",
34 | BindingFlags.Public |
35 | BindingFlags.NonPublic |
36 | BindingFlags.Static);
37 | meth.Invoke(null, null);
38 | }
39 |
40 | private static Type GetType(string name)
41 | {
42 | Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
43 | for (int i = 0; assemblies != null && i < assemblies.Length; ++i)
44 | {
45 | Type type = assemblies[i].GetType(name);
46 | if (type != null)
47 | {
48 | return type;
49 | }
50 | }
51 | return null;
52 | }
53 | }
54 |
--------------------------------------------------------------------------------
/Assets/Editor/AssetsDependenciesTool/ShowSelectedObjectsTool.cs.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fe8e4a7e574389d4592a3f5cd7098b73
3 | MonoImporter:
4 | serializedVersion: 2
5 | defaultReferences: []
6 | executionOrder: 0
7 | icon: {instanceID: 0}
8 | userData:
9 |
--------------------------------------------------------------------------------
/Assets/Image 1.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/Assets/Image 1.prefab
--------------------------------------------------------------------------------
/Assets/Image 1.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: ff699e57d2a9979438ead20ca08d116c
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/Image.prefab:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/Assets/Image.prefab
--------------------------------------------------------------------------------
/Assets/Image.prefab.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: e16568dd8785d414eb0e202f24982b93
3 | NativeFormatImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/Assets/test.unity:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/Assets/test.unity
--------------------------------------------------------------------------------
/Assets/test.unity.meta:
--------------------------------------------------------------------------------
1 | fileFormatVersion: 2
2 | guid: fab9db3cbc2b46e459c327548c9c83f9
3 | DefaultImporter:
4 | userData:
5 |
--------------------------------------------------------------------------------
/ProjectSettings/AudioManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/AudioManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/DynamicsManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/DynamicsManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorBuildSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/EditorBuildSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/EditorSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/EditorSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/GraphicsSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/GraphicsSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/InputManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/InputManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/NavMeshLayers.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/NavMeshLayers.asset
--------------------------------------------------------------------------------
/ProjectSettings/NetworkManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/NetworkManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/Physics2DSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/Physics2DSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/ProjectSettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/ProjectSettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/QualitySettings.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/QualitySettings.asset
--------------------------------------------------------------------------------
/ProjectSettings/TagManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/TagManager.asset
--------------------------------------------------------------------------------
/ProjectSettings/TimeManager.asset:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/ProjectSettings/TimeManager.asset
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # UnityDependencyTools
2 | In Unity editor, you can get assets' dependency via context menu `Select Dependencies` conveniently.
3 | **BUT the opposite operation is quite difficult**, sometimes you need to search for guid in the entire repo. This is quite inconvenient and that's why I made this tool.
4 |
5 | UnityDependencyTool gives you the context menu `Select Dependencies By`, so you can trace every asset's dependencies forward and reversly.
6 |
7 | And even more, you can got one asset's directly dependencies via other context menus as you want.
8 |
9 | The context menu is as below:
10 |
11 | 
12 | 
13 |
14 | You can see the usage in the youtube video: [Link](https://www.youtube.com/watch?v=K83HxsnCHeI)
15 |
--------------------------------------------------------------------------------
/by.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/by.png
--------------------------------------------------------------------------------
/pro.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/tnqiang/UnityDependencyTools/087c2e414aaa0225a4f9b0760121c3a3c780dfbf/pro.png
--------------------------------------------------------------------------------