public Dir FindOrCreate(string path, bool mightBeFile = true) { int i = path.IndexOf('/'); if (i > -1) { Dir dir = FindOrCreate(path.Substring(0, i), false); return(dir.FindOrCreate(path.Substring(i + 1), true)); } // if the name is at the end of a path and contains a "." // we assume it is a file (unless it is "." by itself) if (mightBeFile && path != "." && path.Contains(".")) { Files.Add(path); return(this); } Dir child; if (Dirs.ContainsKey(path)) { child = Dirs[path]; } else { child = new Dir(path); Dirs.Add(path, child); } return(child); }
static Dir FindDependencies() { string[] allScenes = AssetDatabase.FindAssets("t:Scene"); string[] allPaths = new string[allScenes.Length]; int curSceneIndex = 0; // Find and store the path to every scene foreach (string guid in allScenes) { string path = AssetDatabase.GUIDToAssetPath(guid); allPaths[curSceneIndex] = path; ++curSceneIndex; } // Find all asset dependencies of every scene recursively string[] dependencies = AssetDatabase.GetDependencies(allPaths, true); // Build a folder hierarchy string for every asset dependency StringBuilder dependenciesString = new StringBuilder(); dependenciesString.AppendLine(); Dir root = new Dir(""); foreach (string dependency in dependencies) { root.FindOrCreate(dependency); } return(root); }
public Dir FindOrCreate(string path) { int i = path.IndexOf('/'); if (i > -1) { Dir dir = FindOrCreate(path.Substring(0, i)); return(dir.FindOrCreate(path.Substring(i + 1))); } // if the path contains a "." it is a file, unless it is "." by itself if (path != "." && path.Contains(".")) { Files.Add(path); return(this); } Dir child; if (Dirs.ContainsKey(path)) { child = Dirs[path]; } else { child = new Dir(path); Dirs.Add(path, child); } return(child); }