Ejemplo n.º 1
0
        public override void UnloadUnusedAssets()
        {
            List <int> assetsNotAlive = new List <int>();

            foreach (var item in m_Cache)
            {
                CResource res = item.Value;
                LogUtility.Log("[CResources.UnloadUnusedAssets]{0}  {1}", item.Value.Location.InternalId, item.Value.IsAlive);
                if (res.IsAlive == false)
                {
                    IResourceLocation location = res.Location;
                    if (location.HasDependencies)
                    {
                        for (int i = 0; i < location.Dependencies.Count; i++)
                        {
                            CResources.Release <object>(location.Dependencies[i], null);
                        }
                    }
                    assetsNotAlive.Add(item.Key);
                }
            }
            for (int i = 0; i < assetsNotAlive.Count; i++)
            {
                m_Cache.Remove(assetsNotAlive[i]);
            }
        }
Ejemplo n.º 2
0
        public override TObject Provide <TObject>(IResourceLocation location)
        {
            TObject result = null;
            int     key    = location.GetHashCode();

            if (m_Cache.ContainsKey(key))
            {
                CResource res = m_Cache[key];
                if (res.IsAlive)
                {
                    result = res.Retain().Content as TObject;

                    LogUtility.Log(location.InternalId + " " + location.ProviderId + " " + result);
                    return(result);
                }
                else
                {
                    LogUtility.LogError(location.InternalId + "  not alive");
                    m_Cache.Remove(key);
                }
            }

            result = m_Provider.Provide <TObject>(location);
            m_Cache.Add(key, new CResource(result, location).Retain());

            LogUtility.Log(location.InternalId + " " + location.ProviderId + " " + result);
            return(result);
        }
Ejemplo n.º 3
0
 internal static CResource LoadAsync <TObject>(IResourceLocation location) where TObject : class
 {
     try
     {
         IResourceProvider provider = GetResourceProvider <TObject>(location);
         CResource         result   = provider.ProvideAsync <TObject>(location);
         m_LoadRecorder.RecordResource(location, result);
         return(result);
     }
     catch (CResourcesException e)
     {
         LogUtility.LogError(e.Message);
     }
     return(null);
 }
Ejemplo n.º 4
0
        public override bool Release(IResourceLocation location, object asset)
        {
            int key = location.GetHashCode();

            if (m_Cache.ContainsKey(key))
            {
                CResource res = m_Cache[key];
                res.Release();
                if (res.m_RefCount == 0)
                {
                    m_Cache.Remove(key);
                    m_Provider.Release(location, res.Content);
                    return(true);
                }
            }
            return(false);
        }