Beispiel #1
0
 public override List <string> GetChildren(string path)
 {
     if (Childrens.ContainsKey(path))
     {
         return(Childrens[path]);
     }
     return(AssetDatabase.GetDependencies(path, false).ToList());
 }
Beispiel #2
0
        public override void Load()
        {
            EditorUtility.DisplayCancelableProgressBar("Hold on", "", 0);
            AssetDatabase.SaveAssets();
            string[]         allAsset     = AssetDatabase.GetAllAssetPaths();
            HashSet <string> removedPaths = new HashSet <string>(LastUpdateTimes.Keys);

            removedPaths.ExceptWith(allAsset);
            Debug.Log(removedPaths.Count);
            foreach (var path in removedPaths)
            {
                if (Childrens.ContainsKey(path))
                {
                    foreach (var p in Childrens[path])
                    {
                        if (Parents.ContainsKey(p))
                        {
                            Parents[p].Remove(path);
                        }
                    }
                    Childrens.Remove(path);
                }
                if (Parents.ContainsKey(path))
                {
                    foreach (var p in Parents[path])
                    {
                        if (Childrens.ContainsKey(p))
                        {
                            Childrens[p].Remove(path);
                        }
                    }
                    Parents.Remove(path);
                }
                LastUpdateTimes.Remove(path);
            }
            int count = allAsset.Length;

            for (int i = 0; i < count; i++)
            {
                if (i % 100 == 0)
                {
                    if (EditorUtility.DisplayCancelableProgressBar("Hold on", "GetDependencies " + i + "/" + count, (float)i / count))
                    {
                        EditorUtility.ClearProgressBar();
                        return;
                    }
                }
                string p    = allAsset[i];
                var    time = File.GetLastWriteTime(p);
                if (!LastUpdateTimes.ContainsKey(p) || LastUpdateTimes[p] < time)
                {
                    if (Childrens.ContainsKey(p))
                    {
                        foreach (var ps in Childrens[p])
                        {
                            if (Parents.ContainsKey(ps))
                            {
                                Parents[ps].Remove(p);
                            }
                        }
                    }
                    var dp = AssetDatabase.GetDependencies(p, false);
                    Childrens[p] = new UStringList();
                    Childrens[p].AddRange(dp);
                    Childrens[p].Remove(p);
                    foreach (var d in dp)
                    {
                        if (d == p)
                        {
                            continue;
                        }
                        if (!Parents.ContainsKey(d))
                        {
                            Parents.Add(d, new UStringList());
                        }
                        Parents[d].Remove(p);
                        Parents[d].Add(p);
                    }
                    LastUpdateTimes[p] = time;
                }
            }
            EditorUtility.SetDirty(this);
            AssetDatabase.SaveAssets();
            EditorUtility.ClearProgressBar();
        }