Example #1
0
        private static void AppendUsageScene(Dictionary <string, FR2_Ref> dict, Object obj)
        {
            string path = AssetDatabase.GetAssetPath(obj);

            if (string.IsNullOrEmpty(path))
            {
                return;
            }

            string guid = AssetDatabase.AssetPathToGUID(path);

            if (string.IsNullOrEmpty(guid))
            {
                return;
            }

            if (dict.ContainsKey(guid))
            {
                return;
            }

            FR2_Asset asset = FR2_Cache.Api.Get(guid);

            if (asset == null)
            {
                return;
            }

            var r = new FR2_Ref(0, 1, asset, null);

            dict.Add(guid, r);
        }
Example #2
0
        internal static List <string> FindUsage(string[] listGUIDs)
        {
            if (!isReady)
            {
                return(null);
            }

            var refs = Api.FindAssets(listGUIDs, true);

            for (var i = 0; i < refs.Count; i++)
            {
                var tmp = FR2_Asset.FindUsage(refs[i]);

                for (var j = 0; j < tmp.Count; j++)
                {
                    var itm = tmp[j];
                    if (refs.Contains(itm))
                    {
                        continue;
                    }
                    refs.Add(itm);
                }
            }

            return(refs.Select(item => item.guid).ToList());
        }
Example #3
0
 internal void AddSymbols(FR2_Asset asset)
 {
     for (var j = 0; j < asset.ScriptSymbols.Count; j++)
     {
         AddSymbol(asset.ScriptSymbols[j], asset);
     }
 }
Example #4
0
        internal void RefreshAsset(FR2_Asset asset, bool force)
        {
            workCount++;

            if (force)
            {
                asset.MarkAsDirty();

                if ((asset.type == FR2_AssetType.FOLDER) && !asset.IsMissing)
                {
                    var dirs = Directory.GetDirectories(asset.assetPath, "*", SearchOption.AllDirectories);
                    //refresh children directories as well

                    for (var i = 0; i < dirs.Length; i++)
                    {
                        var guid  = AssetDatabase.AssetPathToGUID(dirs[i]);
                        var child = Api.Get(guid);
                        if (child == null)
                        {
                            continue;
                        }

                        workCount++;
                        child.MarkAsDirty();
                        queueLoadContent.Add(child);
                    }
                }
            }

            queueLoadContent.Add(asset);
        }
Example #5
0
        internal void AddAsset(string guid)
        {
            if (AssetMap.ContainsKey(guid))
            {
                Debug.LogWarning("guid already exist <" + guid + ">");
                return;
            }

            var first = AssetList.FirstOrDefault(item => item.guid == guid);

            if (first != null)
            {
                Debug.LogWarning("Should catch asset import ! " + first.assetPath);
                first.LoadAssetInfo();
                RefreshAsset(first, true);
                return;
            }

            var asset = new FR2_Asset(guid);

            asset.cacheStamp = cacheStamp;

            AssetList.Add(asset);
            AssetMap.Add(guid, asset);

            // Do not load content for FR2_Cache asset
            if (guid == FR2_Cache.CacheGUID)
            {
                return;
            }

            workCount++;
            queueLoadContent.Add(asset);
        }
Example #6
0
            private void ApplyFiter()
            {
                dirty = false;
                refs  = new Dictionary <string, FR2_Ref>();

                foreach (KeyValuePair <string, List <string> > item in FR2_Setting.IgnoreFiltered)
                {
                    foreach (string item2 in item.Value)
                    {
                        string guid = AssetDatabase.AssetPathToGUID(item2);
                        if (string.IsNullOrEmpty(guid))
                        {
                            continue;
                        }

                        FR2_Asset asset = FR2_Cache.Api.Get(guid, true);
                        var       r     = new FR2_Ref(0, 0, asset, null, item.Key);
                        refs.Add(guid, r);
                    }
                }

                groupIgnore.Reset
                (
                    refs.Values.ToList(),
                    rf => rf.asset != null ? rf.asset.guid : "",
                    GetGroup,
                    SortGroup
                );
            }
Example #7
0
        internal static List <FR2_Asset> FindUsage(FR2_Asset asset)
        {
            if (asset == null)
            {
                return(null);
            }

            var refs = FR2_Cache.Api.FindAssets(asset.UseGUIDs.ToArray(), true);

            if (asset.ScriptUsage != null)
            {
                for (var i = 0; i < asset.ScriptUsage.Count; i++)
                {
                    var symbolList = FR2_Cache.Api.FindAllSymbol(asset.ScriptUsage[i]);
                    if (symbolList.Contains(asset))
                    {
                        continue;
                    }

                    var symbol = symbolList[0];
                    if (symbol == null || refs.Contains(symbol))
                    {
                        continue;
                    }
                    refs.Add(symbol);
                }
            }

            return(refs);
        }
Example #8
0
        private void DrawGroup(Rect r, string label, int childCount)
        {
            // GUI.Label(r, label + " (" + childCount + ")", EditorStyles.boldLabel);
            FR2_Asset asset = dicIndex[label][0].asset;

            Texture tex  = AssetDatabase.GetCachedIcon(asset.assetPath);
            Rect    rect = r;

            if (tex != null)
            {
                rect.width = 16f;
                GUI.DrawTexture(rect, tex);
            }

            rect       = r;
            rect.xMin += 16f;
            GUI.Label(rect, asset.assetName, EditorStyles.boldLabel);

            rect       = r;
            rect.xMin += rect.width - 50f;
            GUI.Label(rect, FR2_Helper.GetfileSizeString(asset.fileSize), EditorStyles.miniLabel);

            rect       = r;
            rect.xMin += rect.width - 70f;
            GUI.Label(rect, childCount.ToString(), EditorStyles.miniLabel);

            rect       = r;
            rect.xMin += rect.width - 70f;
        }
Example #9
0
        public FR2_Ref(int index, int depth, FR2_Asset asset, FR2_Asset by)
        {
            this.index = index;
            this.depth = depth;

            this.asset = asset;
            type       = FR2_RefDrawer.AssetType.GetIndex(asset.extension);
            addBy      = by;
        }
Example #10
0
 internal void AsyncLoadContent(int idx, FR2_Asset asset)
 {
     asset.LoadContent(false);
     if (asset.ScriptSymbols.Count > 0)
     {
         AddSymbols(asset);
         //if (asset.assetName == "Script1.cs") Debug.Log(asset.assetName + " ---> " + asset.ScriptTokens.Count + ":" + asset.ScriptSymbols.Count);
     }
 }
Example #11
0
        internal void AsyncUsedBy(int idx, FR2_Asset asset)
        {
            if (AssetMap == null)
            {
                Check4Changes(!EditorApplication.isPlaying, false);
            }
            if (asset.IsFolder)
            {
                return;
            }

            for (var i = 0; i < asset.ScriptTokens.Count; i++)
            {
                var token = asset.ScriptTokens[i];
                var all   = FindAllSymbol(token);

                if (all == null)
                {
                    continue;
                }

                //Debug.Log(asset.assetName +  " :: Find <" + token + "> ---> " + all.Count);

                asset.ScriptUsage.Add(token); //definition found !

                for (var j = 0; j < all.Count; j++)
                {
                    // add to usage list
                    if (all[j].IsMissing || all[j].UsedByMap == null)
                    {
                        continue;
                    }

                    if (!all[j].UsedByMap.ContainsKey(asset.guid))
                    {
                        all[j].UsedByMap.Add(asset.guid, asset);
                    }
                }
            }

            for (var i = 0; i < asset.UseGUIDs.Count; i++)
            {
                FR2_Asset tAsset;
                if (AssetMap.TryGetValue(asset.UseGUIDs[i], out tAsset))
                {
                    if (tAsset == null || tAsset.UsedByMap == null)
                    {
                        continue;
                    }

                    if (!tAsset.UsedByMap.ContainsKey(asset.guid))
                    {
                        tAsset.UsedByMap.Add(asset.guid, asset);
                    }
                }
            }
        }
Example #12
0
        private static void Add(Dictionary <string, FR2_Ref> refs, FR2_Asset asset, int depth)
        {
            string targetId = asset.guid;

            if (!refs.ContainsKey(targetId))
            {
                refs.Add(targetId, new FR2_Ref(0, depth, asset, null));
            }
        }
Example #13
0
        internal void AppendUsedBy(Dictionary <string, FR2_Ref> result, bool deep)
        {
            // var list = Append(result, FR2_Asset.FindUsedByGUIDs(asset).ToArray());
            // if (!deep) return;

            // // Add next-level
            // for (var i = 0;i < list.Count;i ++)
            // {
            //  list[i].AppendUsedBy(result, true);
            // }

            Dictionary <string, FR2_Asset> h = asset.UsedByMap;
            List <FR2_Ref> list = deep ? new List <FR2_Ref>() : null;

            foreach (KeyValuePair <string, FR2_Asset> 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.AppendUsedBy(result, true);
            }
        }
Example #14
0
        internal void ReadFromProject(bool force)
        {
            var paths = AssetDatabase.GetAllAssetPaths().ToList();

            paths.RemoveAll(item => !item.StartsWith("Assets/"));
            var guids = paths.Select(item => AssetDatabase.AssetPathToGUID(item)).ToArray();

            cacheStamp++;

            // Check for new assets
            for (var i = 0; i < guids.Length; i++)
            {
                if (!FR2_Asset.IsValidGUID(guids[i]))
                {
                    continue;
                }

                FR2_Asset asset;

                if (AssetMap.TryGetValue(guids[i], out asset))
                {
                    asset.cacheStamp = cacheStamp;
                    continue;
                }

                ;

                // New asset
                AddAsset(guids[i]);
            }

            // Check for deleted assets
            for (var i = AssetList.Count - 1; i >= 0; i--)
            {
                if (AssetList[i].cacheStamp != cacheStamp)
                {
                    RemoveAsset(AssetList[i]);
                }
            }

            // Refresh definition list
            for (var i = 0; i < AssetList.Count; i++)
            {
                AddSymbols(AssetList[i]);
            }

            if (force)
            {
                timeStamp  = FR2_Unity.Epoch(DateTime.Now);
                workCount += AssetMap.Count;
                queueLoadContent.AddRange(AssetMap.Values.ToList());
            }
        }
Example #15
0
        public FR2_Ref(int index, int depth, FR2_Asset asset, FR2_Asset by)
        {
            this.index = index;
            this.depth = depth;

            this.asset = asset;
            if (asset != null)
            {
                type = AssetType.GetIndex(asset.extension);
            }

            addBy = by;
            // isSceneRef = false;
        }
Example #16
0
        internal void AppendUsage(Dictionary <string, FR2_Ref> result, bool deep)
        {
            var list = Append(result, FR2_Asset.FindUsageGUIDs(asset, true).ToArray());

            if (!deep)
            {
                return;
            }

            // Add next-level
            for (var i = 0; i < list.Count; i++)
            {
                list[i].AppendUsage(result, true);
            }
        }
Example #17
0
        // ----------------------------- STATIC  ---------------------------------------

        internal static int SortByExtension(FR2_Asset a1, FR2_Asset a2)
        {
            if (a1 == null)
            {
                return(-1);
            }
            if (a2 == null)
            {
                return(1);
            }

            var result = a1.extension.CompareTo(a2.extension);

            return(result == 0 ? a1.assetName.CompareTo(a2.assetName) : result);
        }
Example #18
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++)
            {
                string guid = guids[i];
                if (dict.ContainsKey(guid))
                {
                    continue;
                }

                FR2_Asset 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);
        }
Example #19
0
        internal void RemoveAsset(FR2_Asset asset)
        {
            AssetList.Remove(asset);

            // Deleted Asset : still in the map but not in the AssetList
            asset.state = FR2_AssetState.MISSING;

            for (var i = 0; i < asset.ScriptSymbols.Count; i++)
            {
                var s = asset.ScriptSymbols[i];
                var l = FindAllSymbol(s);
                if (l != null && l.Contains(asset))
                {
                    l.Remove(asset);
                }
            }
        }
Example #20
0
        //[MenuItem("Assets/FR2/Tools/Fix Model Import Material")]
        //public static void FixModelImportMaterial(){
        //	if (Selection.activeObject == null) return;
        //	CreatePrefabReplaceModel((GameObject)Selection.activeObject);
        //}

        //[MenuItem("GameObject/FR2/Paste Materials", false, 10)]
        //public static void PasteMaterials(){
        //	if (Selection.activeObject == null) return;

        //	var r = Selection.activeGameObject.GetComponent<Renderer>();
        //	Undo.RecordObject(r, "Replace Materials");
        //	r.materials = model_materials;
        //	EditorUtility.SetDirty(r);
        //}

        //[MenuItem("GameObject/FR2/Copy Materials", false, 10)]
        //public static void CopyMaterials(){
        //	if (Selection.activeObject == null) return;
        //	var r = Selection.activeGameObject.GetComponent<Renderer>();
        //	if (r == null) return;
        //	model_materials = r.sharedMaterials;
        //}

        //-------------------------- APIs ----------------------

        private static void SelectDependencies(bool includeMe)
        {
            List <FR2_Asset> list = FR2_Cache.Api.FindAssets(FR2_Unity.Selection_AssetGUIDs, false);
            var dict = new Dictionary <string, Object>();

            if (includeMe)
            {
                AddToDict(dict, list.ToArray());
            }

            for (var i = 0; i < list.Count; i++)
            {
                AddToDict(dict, FR2_Asset.FindUsage(list[i]).ToArray());
            }

            Selection.objects = dict.Values.ToArray();
        }
Example #21
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);
            }
        }
Example #22
0
        internal static List <string> FindUsageGUIDs(FR2_Asset asset, bool includeScriptSymbols)
        {
            var result = new HashSet <string>();

            if (asset == null)
            {
                Debug.LogWarning("Asset invalid : " + asset.assetName);
                return(result.ToList());
            }

            for (var i = 0; i < asset.UseGUIDs.Count; i++)
            {
                result.Add(asset.UseGUIDs[i]);
            }

            if (!includeScriptSymbols)
            {
                return(result.ToList());
            }

            if (asset.ScriptUsage != null)
            {
                for (var i = 0; i < asset.ScriptUsage.Count; i++)
                {
                    var symbolList = FR2_Cache.Api.FindAllSymbol(asset.ScriptUsage[i]);
                    if (symbolList.Contains(asset))
                    {
                        continue;
                    }

                    var symbol = symbolList[0];
                    if (symbol == null || result.Contains(symbol.guid))
                    {
                        continue;
                    }

                    result.Add(symbol.guid);
                }
            }

            return(result.ToList());
        }
Example #23
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);
        }
Example #24
0
        private static void FindRefInScene()
        {
            refs = new Dictionary <string, FR2_Ref>();
            for (var i = 0; i < cacheAssetGuids.Length; i++)
            {
                FR2_Asset asset = FR2_Cache.Api.Get(cacheAssetGuids[i]);
                if (asset == null)
                {
                    continue;
                }

                Add(refs, asset, 0);

                ApplyFilter(refs, asset);
            }

            if (onFindRefInSceneComplete != null)
            {
                onFindRefInSceneComplete(refs);
            }

            FR2_SceneCache.onReady -= FindRefInScene;
            //    UnityEngine.Debug.Log("Time find ref in scene " + watch.ElapsedMilliseconds);
        }
Example #25
0
        internal void AddSymbol(string symbol, FR2_Asset asset)
        {
            List <FR2_Asset> list;

            if (ScriptMap == null)
            {
                return;
            }

            var arr = symbol.Split('.');
            var id  = arr[arr.Length - 1];

            if (!ScriptMap.TryGetValue(id, out list))
            {
                list = new List <FR2_Asset>();
                ScriptMap.Add(id, list);
            }
            else if (list.Contains(asset))
            {
                return;
            }

            list.Add(asset);
        }
Example #26
0
 public FR2_Ref(int index, int depth, FR2_Asset asset, FR2_Asset by, string group) : this(index, depth, asset,
                                                                                          by)
 {
     this.group = group;
     // isSceneRef = false;
 }
Example #27
0
        private static void OnPostprocessAllAssets(string[] importedAssets, string[] deletedAssets, string[] movedAssets,
                                                   string[] movedFromAssetPaths)
        {
            if (EditorApplication.isUpdating || EditorApplication.isPlaying)
            {
                return;
            }
            //Debug.Log("OnPostProcessAllAssets : "+ FR2_Cache.Api.isReady + ":" + importedAssets.Length + ":" + deletedAssets.Length + ":" + movedAssets.Length + ":" + movedFromAssetPaths.Length);

            if (!FR2_Cache.isReady)
            {
#if FR2_DEBUG
                Debug.Log("Not ready, will refresh anyway !");
#endif
                return;
            }

            for (var i = 0; i < importedAssets.Length; i++)
            {
                if (importedAssets[i] == FR2_Cache.CachePath)
                {
                    continue;
                }

                var guid = AssetDatabase.AssetPathToGUID(importedAssets[i]);
                if (!FR2_Asset.IsValidGUID(guid))
                {
                    continue;
                }
                if (FR2_Cache.Api.AssetMap.ContainsKey(guid))
                {
                    FR2_Cache.Api.RefreshAsset(guid, false);

#if FR2_DEBUG
                    Debug.Log("Changed : " + importedAssets[i]);
#endif

                    continue;
                }

                FR2_Cache.Api.AddAsset(guid);
#if FR2_DEBUG
                Debug.Log("New : " + importedAssets[i]);
#endif
            }

            for (var i = 0; i < deletedAssets.Length; i++)
            {
                var guid = AssetDatabase.AssetPathToGUID(deletedAssets[i]);
                FR2_Cache.Api.RemoveAsset(guid);

#if FR2_DEBUG
                Debug.Log("Deleted : " + deletedAssets[i]);
#endif
            }

            for (var i = 0; i < movedAssets.Length; i++)
            {
                var guid  = AssetDatabase.AssetPathToGUID(movedAssets[i]);
                var asset = FR2_Cache.Api.Get(guid);
                if (asset != null)
                {
                    asset.LoadAssetInfo();
                }
            }

#if FR2_DEBUG
            Debug.Log("Changes :: " + importedAssets.Length + ":" + FR2_Cache.Api.workCount);
#endif

            if (FR2_Cache.Api.workCount > 0)
            {
                FR2_Cache.Api.Check4Usage();
            }
        }
Example #28
0
 public FR2_DuplicateAsset(FR2_Asset asset)
 {
     this.asset = asset;
 }
Example #29
0
 internal static List <string> FindUsedByGUIDs(FR2_Asset asset)
 {
     return(asset.UsedByMap.Keys.ToList());
 }
Example #30
0
 internal static List <FR2_Asset> FindUsedBy(FR2_Asset asset)
 {
     return(asset.UsedByMap.Values.ToList());
 }