Ejemplo n.º 1
0
        public static bool ParseLuaAsset(string url)
        {
            bool result = false;
            WWW  www    = AssetPool.GetWww(url);

            if (www != null)
            {
                try
                {
                    UnityEngine.Object[] array = www.assetBundle.LoadAll(typeof(TextAsset));
                    for (int i = 0; i < array.Length; i++)
                    {
                        UnityEngine.Object @object = array[i];
                        AssetPool.AddAsset(@object.name, @object, 999, true);
                    }
                    www.assetBundle.Unload(false);
                    result = true;
                }
                catch (Exception ex)
                {
                    string text = "资源解析失败 " + url + "\n" + ex.Message;
                    Pandora.Instance.ReportError(text, 10217582);
                    Logger.LogError(text);
                    LocalDirectoryHelper.DeleteAssetByUrl(url);
                }
                AssetPool.DisposeWww(url);
            }
            return(result);
        }
Ejemplo n.º 2
0
        public static bool ParseImageAsset(string url, bool isCacheInMemory)
        {
            bool result = false;
            WWW  www    = AssetPool.GetWww(url);

            if (www != null)
            {
                try
                {
                    Texture2D textureNonReadable = www.textureNonReadable;
                    textureNonReadable.name = url;
                    AssetPool.AddAsset(url, textureNonReadable, 0, isCacheInMemory);
                    result = true;
                }
                catch (Exception ex)
                {
                    string text = "资源解析失败: " + url + "\n" + ex.Message;
                    Pandora.Instance.ReportError(text, 10217582);
                    Logger.LogError(text);
                    LocalDirectoryHelper.DeleteAssetByUrl(url);
                }
                AssetPool.DisposeWww(url);
            }
            return(result);
        }
Ejemplo n.º 3
0
 public static List <string> DeleteZeroReferenceAsset()
 {
     AssetPool._deletedKeyList.Clear();
     AssetPool.DeleteZeroReferenceAsset(AssetPool._strongAssetDict);
     AssetPool.DeleteZeroReferenceAsset(AssetPool._weakAssetDict);
     return(AssetPool._deletedKeyList);
 }
Ejemplo n.º 4
0
        private static void OnLoadImage(string cacheUrl, Action <Texture2D> callback)
        {
            Texture2D obj = AssetPool.GetAsset(cacheUrl) as Texture2D;

            if (callback != null)
            {
                callback(obj);
            }
        }
Ejemplo n.º 5
0
        private static void OnLoadAssetBundle(string cacheUrl, Action <AssetBundle> callback)
        {
            AssetBundle obj = AssetPool.GetAsset(cacheUrl) as AssetBundle;

            if (callback != null)
            {
                callback(obj);
            }
        }
Ejemplo n.º 6
0
 protected override bool HandleLoadedContent(string url, WWW www)
 {
     if (Pandora.Instance.IsDebug)
     {
         Logger.Log("<color=#00ff00>资源从本地加载到内存成功</color>, url: " + url);
     }
     AssetPool.AddWww(url, www);
     return(AssetPool.ParseAsset(url, this._assetConfigDict[url]));
 }
Ejemplo n.º 7
0
 public static void ReleaseAsset(string key)
 {
     if (!AssetPool.IsInStrongDict(key))
     {
         return;
     }
     AssetPool.Asset asset = AssetPool._strongAssetDict[key];
     asset.ReferenceCount--;
 }
Ejemplo n.º 8
0
        public static bool ParseAssetBundle(string url)
        {
            WWW www = AssetPool.GetWww(url);

            if (www != null)
            {
                AssetPool.AddAsset(url, www.assetBundle, 0, false);
                AssetPool.DisposeWww(url);
            }
            return(true);
        }
Ejemplo n.º 9
0
 public static void ReleaseProgramAsset(RemoteConfig.AssetInfo assetInfo)
 {
     if (CacheManager.IsProgramAssetExists(assetInfo.name, assetInfo.md5))
     {
         string cachedProgramAssetUrl = CacheManager.GetCachedProgramAssetUrl(assetInfo.url);
         AssetPool.ReleaseAsset(cachedProgramAssetUrl);
     }
     else
     {
         AssetPool.ReleaseAsset(assetInfo.url);
     }
 }
Ejemplo n.º 10
0
 public static void ReleaseAsset(string url)
 {
     if (CacheManager.IsAssetExists(url))
     {
         string cachedAssetUrl = CacheManager.GetCachedAssetUrl(url);
         AssetPool.ReleaseAsset(cachedAssetUrl);
     }
     else
     {
         AssetPool.ReleaseAsset(url);
     }
 }
Ejemplo n.º 11
0
        private static void OnLoadPrefab(string cacheUrl, Action <GameObject> callback)
        {
            GameObject gameObject = AssetPool.GetAsset(cacheUrl) as GameObject;
            GameObject obj        = null;

            if (gameObject != null)
            {
                obj = (UnityEngine.Object.Instantiate(gameObject) as GameObject);
            }
            if (callback != null)
            {
                callback(obj);
            }
        }
Ejemplo n.º 12
0
 public static UnityEngine.Object GetAsset(string key)
 {
     if (AssetPool.IsInStrongDict(key))
     {
         AssetPool.Asset asset = AssetPool._strongAssetDict[key];
         asset.ReferenceCount++;
         return(asset.Object);
     }
     if (AssetPool.IsInWeakDict(key))
     {
         AssetPool.Asset asset2 = AssetPool._weakAssetDict[key];
         return(asset2.Object);
     }
     return(null);
 }
Ejemplo n.º 13
0
        public static byte[] GetLuaBytes(string name)
        {
            string key = name + ".lua";

            UnityEngine.Object @object = AssetPool.GetAsset(key);
            if (@object != null)
            {
                return((@object as TextAsset).bytes);
            }
            @object = AssetPool.FindLuaAsset(key);
            if (@object != null)
            {
                return((@object as TextAsset).bytes);
            }
            return(null);
        }
Ejemplo n.º 14
0
        public static void GetImage(string url, bool isCacheInMemory, Action <Texture2D> callback)
        {
            string cachedAssetUrl = CacheManager.GetCachedAssetUrl(url);

            if (AssetPool.HasAsset(cachedAssetUrl))
            {
                AssetManager.OnLoadImage(cachedAssetUrl, callback);
            }
            else if (CacheManager.IsAssetExists(url))
            {
                AssetManager.LoadImage(cachedAssetUrl, isCacheInMemory, callback);
            }
            else
            {
                CacheManager.LoadAsset(url, delegate(string pUrl)
                {
                    AssetManager.OnCacheLoadImage(pUrl, isCacheInMemory, callback);
                });
            }
        }
Ejemplo n.º 15
0
        public static void GetAssetBundle(string url, Action <AssetBundle> callback)
        {
            string cachedAssetUrl = CacheManager.GetCachedAssetUrl(url);

            if (AssetPool.HasAsset(cachedAssetUrl))
            {
                AssetManager.OnLoadAssetBundle(cachedAssetUrl, callback);
            }
            else if (CacheManager.IsAssetExists(url))
            {
                AssetManager.LoadAssetBundle(cachedAssetUrl, callback);
            }
            else
            {
                CacheManager.LoadAsset(url, delegate(string pUrl)
                {
                    AssetManager.OnCacheLoadAssetBundle(pUrl, callback);
                });
            }
        }
Ejemplo n.º 16
0
        public static void GetGameObject(string url, bool isCacheInMemory, Action <GameObject> callback)
        {
            string cachedAssetUrl = CacheManager.GetCachedAssetUrl(url);

            if (AssetPool.HasAsset(cachedAssetUrl))
            {
                AssetManager.OnLoadPrefab(cachedAssetUrl, callback);
            }
            else if (CacheManager.IsAssetExists(url))
            {
                AssetManager.LoadPrefab(cachedAssetUrl, isCacheInMemory, callback);
            }
            else
            {
                CacheManager.LoadAsset(url, delegate(string pUrl)
                {
                    AssetManager.LoadPrefab(pUrl, isCacheInMemory, callback);
                });
            }
        }
Ejemplo n.º 17
0
        public static bool ParseAsset(string url, AssetConfig config)
        {
            switch (config.type)
            {
            case AssetType.Lua:
                return(AssetPool.ParseLuaAsset(url));

            case AssetType.Prefab:
                return(AssetPool.ParsePrefabAsset(url, config.isCacheInMemory));

            case AssetType.Image:
                return(AssetPool.ParseImageAsset(url, config.isCacheInMemory));

            case AssetType.Assetbundle:
                return(AssetPool.ParseAssetBundle(url));

            default:
                return(false);
            }
        }
Ejemplo n.º 18
0
        public static void GetPanelGameObject(RemoteConfig.AssetInfo assetInfo, Action <GameObject> callback)
        {
            string cachedProgramAssetUrl = CacheManager.GetCachedProgramAssetUrl(assetInfo.url);

            if (AssetPool.HasAsset(cachedProgramAssetUrl))
            {
                AssetManager.OnLoadPrefab(cachedProgramAssetUrl, callback);
            }
            else if (CacheManager.IsProgramAssetExists(assetInfo.name, assetInfo.md5))
            {
                AssetManager.LoadProgramPrefab(assetInfo, true, callback);
            }
            else
            {
                CacheManager.DeleteUnmatchCacheFile(assetInfo.name);
                CacheManager.LoadAsset(assetInfo.url, delegate(string pUrl)
                {
                    AssetManager.LoadProgramPrefab(assetInfo, true, callback);
                });
            }
        }
Ejemplo n.º 19
0
        public static bool ParsePrefabAsset(string url, bool isCacheInMemory)
        {
            bool result = false;
            WWW  www    = AssetPool.GetWww(url);

            if (www != null)
            {
                try
                {
                    UnityEngine.Object[] array = new UnityEngine.Object[]
                    {
                        www.assetBundle.mainAsset
                    };
                    if (array.Length > 1)
                    {
                        throw new Exception("资源打包不符合规范,一个AssetBundle中只能有一个Prefab, " + url);
                    }
                    for (int i = 0; i < array.Length; i++)
                    {
                        UnityEngine.Object obj = array[i];
                        AssetPool.AddAsset(url, obj, 0, isCacheInMemory);
                    }
                    www.assetBundle.Unload(false);
                    result = true;
                }
                catch (Exception ex)
                {
                    string text = "资源解析失败: " + url + "\n" + ex.Message;
                    Pandora.Instance.ReportError(text, 10217582);
                    Logger.LogError(text);
                    LocalDirectoryHelper.DeleteAssetByUrl(url);
                }
                AssetPool.DisposeWww(url);
            }
            return(result);
        }
Ejemplo n.º 20
0
 public static Dictionary <string, int> GetAssetReferenceCountDict()
 {
     return(AssetPool.GetAssetReferenceCountDict());
 }
Ejemplo n.º 21
0
 public static void Clear()
 {
     AssetManager._assetLoader.Clear();
     CacheManager.Clear();
     AssetPool.Clear();
 }
Ejemplo n.º 22
0
        public static UnityEngine.Object GetAsset(string url)
        {
            string cachedAssetUrl = CacheManager.GetCachedAssetUrl(url);

            return(AssetPool.GetAsset(cachedAssetUrl));
        }
Ejemplo n.º 23
0
 public static bool HasAsset(string key)
 {
     return(AssetPool.IsInStrongDict(key) || AssetPool.IsInWeakDict(key));
 }