Ejemplo n.º 1
0
 public static void Remove(APAssetType category, string assetid)
 {
     if (HasAsset(category, assetid))
     {
         AssetsCache[(int)category].Remove(assetid);
     }
 }
Ejemplo n.º 2
0
        public static List <string> GetReferencesByType <T>(string assetPath, APAssetType type, string progressInfo, float startProgress, float endProcess, ref bool cancel) where T : APAsset
        {
            List <string> references = new List <string>();
            var           lookForSet = APCache.GetAssetsListByTypeFromCache <T>(type);

            string title    = "Find references";
            float  progress = 0;

            for (int i = 0; i < lookForSet.Count; i++)
            {
                var dependences = AssetDatabase.GetDependencies(new string[] { lookForSet[i].Path });
                if (dependences.Any(denpend => denpend.Equals(assetPath, StringComparison.CurrentCultureIgnoreCase)))
                {
                    references.Add(lookForSet[i].Path);
                }

                progress = startProgress + (endProcess - startProgress) * (i + 1) * 1f / lookForSet.Count;
                if (EditorUtility.DisplayCancelableProgressBar(title, progressInfo, progress))
                {
                    cancel = true;
                    break;
                }
                ;
            }

            return(references);
        }
Ejemplo n.º 3
0
        public static bool HasAsset(APAssetType category, string assetid)
        {
            if (HasCategory(category) && !string.IsNullOrEmpty(assetid))
            {
                return(AssetsCache[(int)category].ContainsKey(assetid));
            }

            return(false);
        }
Ejemplo n.º 4
0
 public static APAsset GetValue(APAssetType category, string assetid)
 {
     if (HasAsset(category, assetid))
     {
         return(AssetsCache[(int)category][assetid]);
     }
     else
     {
         return(null);
     }
 }
 public void UpdateObjectsIntoCache(APAssetType type, APAsset asset, Queue <APAsset> modifedAssets = null)
 {
     if (APCache.HasAsset(type, asset.Id))
     {
         APCache.SetValue(type, asset.Id, asset);
         if (modifedAssets != null)
         {
             modifedAssets.Enqueue(asset);
         }
     }
 }
Ejemplo n.º 6
0
 public static string GetAssetsLitJsonByTypeFromCache(APAssetType type)
 {
     if (HasCategory(type))
     {
         return(GetJsonFromList(AssetsCache[(int)type].Values));
     }
     else
     {
         return("[]");
     }
 }
Ejemplo n.º 7
0
        private static void LoadResourcesIntoCache(APAssetType type)
        {
            IList assets = null;
            Dictionary <string, APAsset> dict = new Dictionary <string, APAsset>();

            switch (type)
            {
            case APAssetType.Texture:
                assets = APResources.GetTextures();
                break;

            case APAssetType.MovieTexture:
                assets = APResources.GetMovies();
                break;
            }

            if (assets == null)
            {
                return;
            }

            foreach (var item in assets)
            {
                var asset = item as APAsset;
                if (asset == null && string.IsNullOrEmpty(asset.Id))
                {
                    continue;
                }

                Utility.UpdateJsonInAsset(asset);

                if (!dict.ContainsKey(asset.Id))
                {
                    dict.Add(asset.Id, asset);
                }
                else
                {
                    dict[asset.Id] = asset;
                }
            }

            int key = (int)type;

            if (AssetsCache.ContainsKey(key))
            {
                AssetsCache[key] = dict;
            }
            else
            {
                AssetsCache.Add(key, dict);
            }
        }
Ejemplo n.º 8
0
        private static string GenerateCSV <T>(string header, APAssetType type, Func <T, string> rowDataGenerator) where T : APAsset
        {
            var           dataSet = APCache.GetAssetsListByTypeFromCache <T>(type);
            StringBuilder sb      = new StringBuilder();

            sb.AppendLine(header);
            foreach (var item in dataSet)
            {
                sb.AppendLine(rowDataGenerator(item));
            }

            return(sb.ToString());
        }
Ejemplo n.º 9
0
        public static APAsset GetAPAssetByPath(APAssetType type, string guid)
        {
            switch (type)
            {
            case APAssetType.Texture:
                return(GetAPTextureFromAssetGuid(guid));

            case APAssetType.MovieTexture:
                return(GetAPMovieTextureFromAssetGuid(guid));

            default:
                return(null);
            }
        }
Ejemplo n.º 10
0
        public static List <T> GetResourcesListByType <T>(APAssetType type, Func <string, T> parseFunction) where T : class
        {
            var      textGuids = GetAssetGuidsByType(type);
            List <T> list      = new List <T>();

            for (int i = 0; i < textGuids.Length; i++)
            {
                T obj = parseFunction(textGuids[i]);
                if (obj != null)
                {
                    list.Add(obj);
                }
            }

            return(list);
        }
Ejemplo n.º 11
0
        private static List <string> GetReferences <T>(string assetPath, APAssetType type) where T : APAsset
        {
            List <string> references = new List <string>();
            var           lookForSet = APCache.GetAssetsListByTypeFromCache <T>(type);

            foreach (var asset in lookForSet)
            {
                var dependences = AssetDatabase.GetDependencies(new string[] { asset.Path });
                if (dependences.Any(denpend => denpend.Equals(assetPath, StringComparison.CurrentCultureIgnoreCase)))
                {
                    references.Add(asset.Path);
                }
            }

            return(references);
        }
Ejemplo n.º 12
0
        public static APAsset GetAPAssetByPath(APAssetType type, string assetid)
        {
            string guid   = Utility.GetGuidFromAssetId(assetid);
            string fileId = Utility.GetFileIdFromAssetId(assetid);

            switch (type)
            {
            case APAssetType.Font:
                return(GetAPFontFromAssetGuid(guid));

            case APAssetType.MovieTexture:
                return(GetAPMovieTextureFromAssetGuid(guid));

            case APAssetType.Texture:
                return(GetAPTextureFromAssetGuid(guid));

            case APAssetType.Model:
                return(GetAPModelFromAssetGuid(guid));

            case APAssetType.AudioClip:
                return(GetAPAudioFromAssetGuid(guid));

            case APAssetType.Material:
                return(GetAPMaterialFromAssetGuid(guid));

            case APAssetType.Shader:
                return(GetAPShaderFromAssetGuid(guid));

            case APAssetType.AnimationClip:
                return(GetAPAnimationFromAssetPath(guid, fileId));

            case APAssetType.Prefab:
                return(GetAPPrefabFromAssetGuid(guid));

            case APAssetType.StreamingAssets:
                return(GetStreamingAssetFile(AssetDatabase.GUIDToAssetPath(assetid)));

            case APAssetType.Script:
                return(GetCodeFile(AssetDatabase.GUIDToAssetPath(assetid)));

            case APAssetType.Others:
                return(GetOtherFile(AssetDatabase.GUIDToAssetPath(assetid)));

            default:
                return(null);
            }
        }
Ejemplo n.º 13
0
        public static List <T> GetAssetsListByTypeFromCache <T>(APAssetType type) where T : class
        {
            if (HasCategory(type))
            {
                List <T> data = new List <T>();
                foreach (var item in AssetsCache[(int)type].Values)
                {
                    data.Add(item as T);
                }

                return(data);
            }
            else
            {
                return(null);
            }
        }
        public void UpdateObjectsIntoCache(APAssetType type, string assetid, Queue <APAsset> modifedAssets = null)
        {
            APAsset asset = APResources.GetAPAssetByPath(type, assetid);

            if (APCache.HasAsset(type, assetid))
            {
                var previousAssets = APCache.GetValue(type, assetid);
                if (asset != null && previousAssets != null)
                {
                    asset.Used = previousAssets.Used;
                    APCache.SetValue(type, assetid, asset);
                    if (modifedAssets != null)
                    {
                        modifedAssets.Enqueue(asset);
                    }
                }
            }
        }
Ejemplo n.º 15
0
 public static void SetValue(APAssetType category, string assetid, APAsset value)
 {
     Utility.UpdateJsonInAsset(value);
     if (HasCategory(category))
     {
         if (AssetsCache[(int)category].ContainsKey(assetid))
         {
             AssetsCache[(int)category][assetid] = value;
         }
         else
         {
             AssetsCache[(int)category].Add(assetid, value);
         }
     }
     else
     {
         var assetDict = new Dictionary <string, APAsset>();
         assetDict.Add(assetid, value);
         AssetsCache.Add((int)category, assetDict);
     }
 }
Ejemplo n.º 16
0
 public static string[] GetAssetGuidsByType(APAssetType type)
 {
     return(AssetDatabase.FindAssets(string.Format("t:{0}", type.ToString())));
 }
Ejemplo n.º 17
0
        private static void LoadResourcesIntoCache(APAssetType type)
        {
            IList assets = null;
            Dictionary <string, APAsset> dict = new Dictionary <string, APAsset>();

            switch (type)
            {
            case APAssetType.Font:
                assets = APResources.GetFonts();
                break;

            case APAssetType.MovieTexture:
                assets = APResources.GetMovies();
                break;

            case APAssetType.Texture:
                assets = APResources.GetTextures();
                break;

            case APAssetType.Model:
                assets = APResources.GetModels();
                break;

            case APAssetType.AudioClip:
                assets = APResources.GetAudios();
                break;

            case APAssetType.Material:
                assets = APResources.GetMaterials();
                break;

            case APAssetType.Shader:
                assets = APResources.GetShaders();
                break;

            case APAssetType.AnimationClip:
                assets = APResources.GetAnimations();
                break;

            case APAssetType.Prefab:
                assets = APResources.GetPrefabs();
                break;

            case APAssetType.StreamingAssets:
                assets = APResources.GetStreamingAssets();
                break;

            case APAssetType.Script:
                assets = APResources.GetCodeFiles();
                break;

            case APAssetType.Blacklist:
                assets = blacklistStorage.GetAssets();
                break;

            case APAssetType.Others:
                assets = APResources.GetOthers();
                break;
            }

            if (assets == null)
            {
                return;
            }

            foreach (var item in assets)
            {
                var asset = item as APAsset;
                if (asset == null)
                {
                    break;
                }

                Utility.UpdateJsonInAsset(asset);

                if (!dict.ContainsKey(asset.Id))
                {
                    dict.Add(asset.Id, asset);
                }
                else
                {
                    dict[asset.Id] = asset;
                }
            }

            int key = (int)type;

            if (AssetsCache.ContainsKey(key))
            {
                AssetsCache[key] = dict;
            }
            else
            {
                AssetsCache.Add(key, dict);
            }
        }
Ejemplo n.º 18
0
 public static void Add(APAssetType category, string assetid, APAsset value)
 {
     Utility.UpdateJsonInAsset(value);
     SetValue(category, assetid, value);
 }
Ejemplo n.º 19
0
 public static bool HasCategory(APAssetType category)
 {
     return(AssetsCache.ContainsKey((int)category));
 }