Ejemplo n.º 1
0
 public AsyncResourceRequest(string url, PoolUnitCacheTag cacheTag, Action <Object> callback, Action <AsnycLoadRequestBase> reportManager)
 {
     this.url           = url;
     this.cacheTag      = cacheTag;
     this.reportManager = reportManager;
     this.callback      = callback;
     loader             = LoadResourceAsync(url);
 }
Ejemplo n.º 2
0
 public AsyncAssetBundleRequest(string url, string assetName, PoolUnitCacheTag cacheTag, Action <Object> callback, Action <AsnycLoadRequestBase> reportManager)
 {
     this.url           = url;
     this.cacheTag      = cacheTag;
     this.reportManager = reportManager;
     this.callback      = callback;
     loader             = LoadAssetBundleAsync(url, assetName);
 }
Ejemplo n.º 3
0
 public void SetData(string index, object data, PoolUnitCacheTag cacheTag = PoolUnitCacheTag.CacheUntilClean)
 {
     if (dataPool.ContainsKey(index))
     {
         dataPool[index] = new PoolUnit <object>(data, cacheTag);
     }
     else
     {
         dataPool.Add(index, new PoolUnit <object>(data, cacheTag));
     }
 }
Ejemplo n.º 4
0
        public T GetResource <T>(string url, PoolUnitCacheTag cacheTag) where T : Object
        {
            if (assetPool.ContainsKey(url))
            {
                return(assetPool[url].Storage as T);
            }

            var asset = Resources.Load <T>(url);

            AddAssetPoolUnit(url, cacheTag, asset);

            return(asset as T);
        }
Ejemplo n.º 5
0
        public void GetAssetBundleAsync(string url, string assetName, PoolUnitCacheTag cacheTag, Action <Object> callback)
        {
            if (assetPool.ContainsKey(url))
            {
                callback(assetPool[url].Storage);
            }
            else
            {
                if (asyncLoadRequests.ContainsKey(url))
                {
                    return;
                }

                var request = new AsyncAssetBundleRequest(url, assetName, cacheTag, callback, ReportLoadRequestResult);
                asyncLoadRequests.Add(url, request);
                StartCoroutine(request.Loader);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// Add unit into asset pool.
        /// </summary>
        private void AddAssetPoolUnit(string url, PoolUnitCacheTag cacheTag, Object asset)
        {
            if (cacheTag == PoolUnitCacheTag.DontCache)
            {
                return;
            }

            if (url == "")
            {
                throw new InvalidOperationException("AddAssetPoolUnit - url is empty");
            }

            if (asset == null)
            {
                throw new NullReferenceException("AddAssetPoolUnit - asset is null");
            }

            assetPool.Add(url, new PoolUnit <Object>(asset, cacheTag));
        }
Ejemplo n.º 7
0
        public T GetAssetBundle <T>(string url, string assetName, PoolUnitCacheTag cacheTag) where T : Object
        {
            if (assetPool.ContainsKey(url))
            {
                return(assetPool[url].Storage as T);
            }

            var assetBundle = AssetBundle.LoadFromFile(url);

            if (assetBundle == null)
            {
                throw new NullReferenceException("Load asset bundle failed : " + url);
            }

            var asset = assetBundle.LoadAsset(assetName);

            AddAssetPoolUnit(url, cacheTag, asset);
            assetBundle.Unload(false);

            return(asset as T);
        }
Ejemplo n.º 8
0
 public void GetResourceAsync <T>(string url, PoolUnitCacheTag cacheTag, Action <Object> callback) where T : Object
 {
     //var request = Resources.LoadAsync<T>(url);
 }
Ejemplo n.º 9
0
 public PoolUnit(T storage, PoolUnitCacheTag cacheTag)
 {
     this.storage  = storage;
     this.cacheTag = cacheTag;
 }