示例#1
0
        // --------------------- STATIC UTILS -----------------------

        internal static Dictionary <string, FR2_Ref> FindRefs(string[] guids, bool usageOrUsedBy, bool addFolder)
        {
            var dict = new Dictionary <string, FR2_Ref>();
            var list = new List <FR2_Ref>();

            for (var i = 0; i < guids.Length; i++)
            {
                var guid = guids[i];
                if (dict.ContainsKey(guid))
                {
                    continue;
                }

                var asset = FR2_Cache.Api.Get(guid);
                if (asset == null)
                {
                    continue;
                }

                var r = new FR2_Ref(i, 0, asset, null);
                if (!asset.IsFolder || addFolder)
                {
                    dict.Add(guid, r);
                }
                list.Add(r);
            }

            for (var i = 0; i < list.Count; i++)
            {
                if (usageOrUsedBy)
                {
                    list[i].AppendUsage(dict, true);
                }
                else
                {
                    list[i].AppendUsedBy(dict, true);
                }
            }

            //var result = dict.Values.ToList();
            //result.Sort((item1, item2)=>{
            //	return item1.index.CompareTo(item2.index);
            //});

            return(dict);
        }
示例#2
0
        internal void AppendUsage(Dictionary <string, FR2_Ref> result, bool deep)
        {
            Dictionary <string, HashSet <int> > h = asset.UseGUIDs;
            List <FR2_Ref> list = deep ? new List <FR2_Ref>() : null;

            foreach (KeyValuePair <string, HashSet <int> > kvp in h)
            {
                string guid = kvp.Key;
                if (result.ContainsKey(guid))
                {
                    continue;
                }

                FR2_Asset child = FR2_Cache.Api.Get(guid);
                if (child == null)
                {
                    continue;
                }

                if (child.IsMissing)
                {
                    continue;
                }

                var r = new FR2_Ref(result.Count, depth + 1, child, asset);
                if (!asset.IsFolder)
                {
                    result.Add(guid, r);
                }

                if (deep)
                {
                    list.Add(r);
                }
            }

            if (!deep)
            {
                return;
            }

            foreach (FR2_Ref item in list)
            {
                item.AppendUsage(result, true);
            }
        }
示例#3
0
        private string GetGroup(FR2_Ref rf)
        {
            // Debug.Log(Lable + "  " + FR2_Setting.GroupMode);
            if (FR2_Setting.GroupMode == Mode.None)
            {
                return(string.Empty);
            }

            if (rf.depth == 0)
            {
                return("Selection");
            }

            FR2_SceneRef sr = null;

            if (rf.isSceneRef)
            {
                sr = rf as FR2_SceneRef;
                if (sr == null)
                {
                    return(string.Empty);
                }
            }

            switch (FR2_Setting.GroupMode)
            {
            case Mode.Extension: return(rf.isSceneRef ? sr.targetType : rf.asset.extension);

            case Mode.Type:
            {
                return(rf.isSceneRef ? sr.targetType : AssetType.FILTERS[rf.type].name);
            }

            case Mode.Folder: return(rf.isSceneRef ? sr.scenePath : rf.asset.assetFolder);

            case Mode.Dependency:
            {
                return(rf.depth == 1 ? "Direct Usage" : "Indirect Usage");
            }
            }

            return(string.Empty);
        }
示例#4
0
        // public FR2_Ref(int depth, UnityEngine.Object target)
        // {
        //  this.component = target;
        //  this.depth = depth;
        //  // isSceneRef = true;
        // }
        internal List <FR2_Ref> Append(Dictionary <string, FR2_Ref> dict, params string[] guidList)
        {
            var result = new List <FR2_Ref>();

            if (FR2_Cache.Api.disabled)
            {
                return(result);
            }

            if (!FR2_Cache.isReady)
            {
                Debug.LogWarning("Cache not yet ready! Please wait!");
                return(result);
            }

            //filter to remove items that already in dictionary
            for (var i = 0; i < guidList.Length; i++)
            {
                string guid = guidList[i];
                if (dict.ContainsKey(guid))
                {
                    continue;
                }

                FR2_Asset child = FR2_Cache.Api.Get(guid);
                if (child == null)
                {
                    continue;
                }

                var r = new FR2_Ref(dict.Count, depth + 1, child, asset);
                if (!asset.IsFolder)
                {
                    dict.Add(guid, r);
                }

                result.Add(r);
            }

            return(result);
        }
示例#5
0
        public FR2_RefDrawer Reset(string[] assetGUIDs, bool isUsage)
        {
            //Debug.Log("Reset :: " + assetGUIDs.Length + "\n" + string.Join("\n", assetGUIDs));

            if (isUsage)
            {
                refs = FR2_Ref.FindUsage(assetGUIDs);
            }
            else
            {
                refs = FR2_Ref.FindUsedBy(assetGUIDs);
            }

            //RefreshFolders();

            // Remove folders && items in assetGUIDs
            //var map = new Dictionary<string, int>();
            //for (var i = 0;i < assetGUIDs.Length; i++)
            //{
            //	map.Add(assetGUIDs[i], i);
            //}

            //for (var i = refs.Count-1; i>=0; i--)
            //{
            //	var a = refs[i].asset;
            //	if (!a.IsFolder) continue; // && !map.ContainsKey(refs[i].asset.guid)
            //	refs.RemoveAt(i); //Remove folders and items in Selection
            //}

            dirty = true;
            if (list != null)
            {
                list.Clear();
            }

            return(this);
        }
示例#6
0
        private void ApplyFilter()
        {
            dirty = false;

            if (refs == null)
            {
                return;
            }

            if (list == null)
            {
                list = new List <FR2_Ref>();
            }
            else
            {
                list.Clear();
            }

            int minScore = searchTerm.Length;

            string term1 = searchTerm;

            if (!caseSensitive)
            {
                term1 = term1.ToLower();
            }

            string term2 = term1.Replace(" ", string.Empty);

            excludeCount = 0;

            foreach (KeyValuePair <string, FR2_Ref> item in refs)
            {
                FR2_Ref r = item.Value;

                if (r.depth == 0 && !FR2_Setting.ShowSelection)
                {
                    continue;
                }

                if (FR2_Setting.IsTypeExcluded(r.type))
                {
                    excludeCount++;
                    continue;                     //skip this one
                }

                if (!showSearch || string.IsNullOrEmpty(searchTerm))
                {
                    r.matchingScore = 0;
                    list.Add(r);
                    continue;
                }

                //calculate matching score
                string name1 = r.isSceneRef ? (r as FR2_SceneRef).sceneFullPath : r.asset.assetName;
                if (!caseSensitive)
                {
                    name1 = name1.ToLower();
                }

                string name2 = name1.Replace(" ", string.Empty);

                int score1 = FR2_Unity.StringMatch(term1, name1);
                int score2 = FR2_Unity.StringMatch(term2, name2);

                r.matchingScore = Mathf.Max(score1, score2);
                if (r.matchingScore > minScore)
                {
                    list.Add(r);
                }
            }

            RefreshSort();
        }
示例#7
0
        public FR2_RefDrawer Reset(GameObject[] objs, bool findDept, bool findPrefabInAsset)
        {
            refs = FR2_Ref.FindUsageScene(objs, findDept);

            var guidss = new List <string>();
            Dictionary <GameObject, HashSet <string> > dependent = FR2_SceneCache.Api.prefabDependencies;

            foreach (GameObject gameObject in objs)
            {
                HashSet <string> hash;
                if (!dependent.TryGetValue(gameObject, out hash))
                {
                    continue;
                }

                foreach (string guid in hash)
                {
                    guidss.Add(guid);
                }
            }

            Dictionary <string, FR2_Ref> usageRefs1 = FR2_Ref.FindUsage(guidss.ToArray());

            foreach (KeyValuePair <string, FR2_Ref> kvp in usageRefs1)
            {
                if (refs.ContainsKey(kvp.Key))
                {
                    continue;
                }

                if (guidss.Contains(kvp.Key))
                {
                    kvp.Value.depth = 1;
                }

                refs.Add(kvp.Key, kvp.Value);
            }


            if (findPrefabInAsset)
            {
                var guids = new List <string>();
                for (var i = 0; i < objs.Length; i++)
                {
                    string guid = FR2_Unity.GetPrefabParent(objs[i]);
                    if (string.IsNullOrEmpty(guid))
                    {
                        continue;
                    }

                    guids.Add(guid);
                }

                Dictionary <string, FR2_Ref> usageRefs = FR2_Ref.FindUsage(guids.ToArray());
                foreach (KeyValuePair <string, FR2_Ref> kvp in usageRefs)
                {
                    if (refs.ContainsKey(kvp.Key))
                    {
                        continue;
                    }

                    if (guids.Contains(kvp.Key))
                    {
                        kvp.Value.depth = 1;
                    }

                    refs.Add(kvp.Key, kvp.Value);
                }
            }

            dirty = true;
            if (list != null)
            {
                list.Clear();
            }

            return(this);
        }
示例#8
0
 private string GetGroup(FR2_Ref rf)
 {
     return(rf.group);
 }
示例#9
0
 private string GetGroup(FR2_Ref rf)
 {
     return(rf.index.ToString());
 }
示例#10
0
        // void OnActive
        private void RefreshView(CBParams assetList)
        {
            cacheAssetList = assetList;
            dirty          = false;
            list           = new List <FR2_Ref>();
            refs           = new Dictionary <string, FR2_Ref>();
            dicIndex       = new Dictionary <string, List <FR2_Ref> >();
            if (assetList == null)
            {
                return;
            }

            int    minScore = searchTerm.Length;
            string term1    = searchTerm;

            if (!caseSensitive)
            {
                term1 = term1.ToLower();
            }

            string term2 = term1.Replace(" ", string.Empty);

            excludeCount = 0;

            for (var i = 0; i < assetList.Count; i++)
            {
                var lst = new List <FR2_Ref>();
                for (var j = 0; j < assetList[i].Count; j++)
                {
                    string guid = AssetDatabase.AssetPathToGUID(assetList[i][j]);
                    if (string.IsNullOrEmpty(guid))
                    {
                        continue;
                    }

                    if (refs.ContainsKey(guid))
                    {
                        continue;
                    }

                    FR2_Asset asset = FR2_Cache.Api.Get(guid);
                    if (asset == null)
                    {
                        continue;
                    }

                    var fr2 = new FR2_Ref(i, 0, asset, null);

                    if (FR2_Setting.IsTypeExcluded(fr2.type))
                    {
                        excludeCount++;
                        continue;                         //skip this one
                    }

                    if (string.IsNullOrEmpty(searchTerm))
                    {
                        fr2.matchingScore = 0;
                        list.Add(fr2);
                        lst.Add(fr2);
                        refs.Add(guid, fr2);
                        continue;
                    }

                    //calculate matching score
                    string name1 = fr2.asset.assetName;
                    if (!caseSensitive)
                    {
                        name1 = name1.ToLower();
                    }

                    string name2 = name1.Replace(" ", string.Empty);

                    int score1 = FR2_Unity.StringMatch(term1, name1);
                    int score2 = FR2_Unity.StringMatch(term2, name2);

                    fr2.matchingScore = Mathf.Max(score1, score2);
                    if (fr2.matchingScore > minScore)
                    {
                        list.Add(fr2);
                        lst.Add(fr2);
                        refs.Add(guid, fr2);
                    }
                }

                dicIndex.Add(i.ToString(), lst);
            }

            ResetGroup();
        }
示例#11
0
        public void RefreshView()
        {
            var scenes = new HashSet <string>();

            // string[] scenes = new string[sceneCount];
            foreach (EditorBuildSettingsScene scene in EditorBuildSettings.scenes)
            {
                if (scene == null)
                {
                    continue;
                }

                if (scene.enabled == false)
                {
                    continue;
                }

                string sce = AssetDatabase.AssetPathToGUID(scene.path);

                if (scenes.Contains(sce))
                {
                    continue;
                }

                scenes.Add(sce);
            }

            refs = FR2_Ref.FindUsage(scenes.ToArray());

            foreach (string VARIABLE in scenes)
            {
                FR2_Ref asset = null;
                if (!refs.TryGetValue(VARIABLE, out asset))
                {
                    continue;
                }


                asset.depth = 1;
            }

            List <FR2_Asset> list = FR2_Cache.Api.AssetList;
            int count             = list.Count;

            for (var i = 0; i < count; i++)
            {
                FR2_Asset item = list[i];
                if (item.inEditor)
                {
                    continue;
                }

                if (item.inPlugins)
                {
                    if (item.type == FR2_AssetType.SCENE)
                    {
                        continue;
                    }
                }

                if (item.inResources || item.inStreamingAsset || item.inPlugins)
                {
                    if (refs.ContainsKey(item.guid))
                    {
                        continue;
                    }

                    refs.Add(item.guid, new FR2_Ref(0, 1, item, null));
                }
            }

            drawer.SetRefs(refs);
            dirty = false;
        }