Esempio n. 1
0
        public bool Release(TypedAssetContentKey <T> content)
        {
            bool result = false;

            if (cache.TryGetValue(content.Key, out var value))
            {
                if (value.RefCount <= 0)
                {
                    Log.LogErrorFormatted(this, "Releasing a key '{0}' with refcount <= 0!", content.Key);
                }
                value.RefCount--;
                List <UnityEngine.Object> arg = new List <UnityEngine.Object>();
                if (value.Value is ICacheableContent && (UnityEngine.Object)value.Value != (UnityEngine.Object)null)
                {
                    arg = releaseSubCacheReferences(value.Value as ICacheableContent);
                }
                if (value.RefCount <= 0)
                {
                    if (!object.ReferenceEquals(value.Value, null) && (UnityEngine.Object)value.Value == (UnityEngine.Object)null)
                    {
                        Log.LogErrorFormatted(this, "Releasing asset '{0}': Value is a destroyed object!", content);
                    }
                    releaseDelegate.InvokeSafe(value.Value, arg);
                    value.Value = null;
                    cache.Remove(content.Key);
                    result = true;
                }
            }
            else
            {
                Log.LogErrorFormatted(this, "Could not release key '{0}' because it was not in the cache!", content.Key);
            }
            return(result);
        }
Esempio n. 2
0
        public static AssetRequest <TAsset> LoadAsync <TAsset>(TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class
        {
            if (key == null)
            {
                throw new InvalidOperationException("Content system cannot load a null key");
            }
            string key2 = key.Expand(args);

            return(LoadAsync <TAsset>(key2));
        }
Esempio n. 3
0
 public IEnumerator Acquire(TypedAssetContentKey <T> content, Action <T> onAcquired)
 {
     if (Content.ContainsKey(content.Key))
     {
         if (cache.TryGetValue(content.Key, out var item))
         {
             if ((UnityEngine.Object)item.Value == (UnityEngine.Object)null)
             {
             }
             item.RefCount++;
             while ((UnityEngine.Object)item.Value == (UnityEngine.Object)null && item.RefCount > 0)
             {
                 yield return(null);
             }
         }
         else
         {
             item = new Item();
             cache.Add(content.Key, item);
             item.RefCount = 1;
             AssetRequest <T> assetRequest = Content.LoadAsync(content);
             while (!assetRequest.Finished)
             {
                 yield return(null);
             }
             if (item.RefCount <= 0)
             {
                 releaseDelegate.InvokeSafe(assetRequest.Asset, new List <UnityEngine.Object>());
                 onAcquired(null);
                 yield break;
             }
             item.Value = assetRequest.Asset;
             if (object.ReferenceEquals(item.Value, null))
             {
                 Log.LogErrorFormatted(this, "Acquiring asset '{0}' from Content system returned a null!", content);
             }
             else if ((UnityEngine.Object)item.Value == (UnityEngine.Object)null)
             {
                 Log.LogErrorFormatted(this, "Acquiring asset '{0}' from Content system returned a destroyed object!", content);
             }
         }
         onAcquired(item.Value);
         if (item.Value is ICacheableContent && (UnityEngine.Object)item.Value != (UnityEngine.Object)null)
         {
             addSubCacheReferences(item.Value as ICacheableContent);
         }
     }
     else
     {
         Log.LogErrorFormatted(this, "Asset with key '{0}' does not exist in this content version!", content.Key);
         onAcquired(null);
     }
 }
Esempio n. 4
0
        public static bool TryLoadImmediate <TAsset>(out TAsset result, TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class
        {
            string key2 = key.Expand(args);

            if (ContainsKey(key2))
            {
                result = LoadImmediate <TAsset>(key2);
                return(true);
            }
            result = null;
            return(false);
        }
Esempio n. 5
0
        public static bool Unload <TAsset>(TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class
        {
            string key2 = key.Expand(args);

            return(Service.Get <Content>().unload <TAsset>(key2, unloadAllObjects: false));
        }
Esempio n. 6
0
        public static TAsset LoadImmediate <TAsset>(TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class
        {
            string key2 = key.Expand(args);

            return(LoadImmediate <TAsset>(key2));
        }
Esempio n. 7
0
        public static bool TryLoadAsync <TAsset>(out AssetRequest <TAsset> result, AssetLoadedHandler <TAsset> handler, TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class
        {
            string key2 = key.Expand(args);

            if (ContainsKey(key2))
            {
                result = LoadAsync(key2, handler);
                return(true);
            }
            result = null;
            return(false);
        }
Esempio n. 8
0
        public static AssetRequest <TAsset> LoadAsync <TAsset>(AssetLoadedHandler <TAsset> handler, TypedAssetContentKey <TAsset> key, params string[] args) where TAsset : class
        {
            string key2 = key.Expand(args);

            return(LoadAsync(key2, handler));
        }