Example #1
0
    private void AddCacheMap(ResourceAssetCache cache)
    {
        if (cache == null || cache.Target == null || cache.TargetType == null)
        {
            return;
        }

        string fileName = cache.FileName;

        if (string.IsNullOrEmpty(fileName))
        {
            return;
        }

        System.Type resType = cache.TargetType;
        CacheKey    key     = CreateCacheKey(fileName, resType);

        if (m_CacheMap.ContainsKey(key))
        {
            if (m_CacheMap[key] != cache)
            {
                //AssetCache oldCache = m_CacheMap[key];
                m_CacheMap[key] = cache;
                Debug.LogErrorFormat("[AddCacheMap] CacheMap {0} exists!", fileName);
            }

            return;
        }

        m_CacheMap.Add(key, cache);
    }
Example #2
0
    internal void OnCacheDestroy(ResourceAssetCache cache)
    {
        if (cache == null)
        {
            return;
        }

        if (cache.TargetType == null)
        {
            return;
        }

        string fileName = cache.FileName;

        if (string.IsNullOrEmpty(fileName))
        {
            return;
        }

        System.Type resType = cache.TargetType;
        CacheKey    key     = CreateCacheKey(fileName, resType);

        if (m_CacheMap.ContainsKey(key))
        {
            m_CacheMap.Remove(key);
        }
    }
Example #3
0
    private static ResourceAssetCache GetPool(UnityEngine.Object target)
    {
        InitPool();
        ResourceAssetCache ret = m_Pool.GetObject();

        ret.mTarget = target;
        return(ret);
    }
Example #4
0
 private static void InPool(ResourceAssetCache cache)
 {
     if (cache == null)
     {
         return;
     }
     InitPool();
     m_Pool.Store(cache);
 }
Example #5
0
    private static ResourceAssetCache GetPool(UnityEngine.Object target, string fileName)
    {
        InitPool();
        ResourceAssetCache ret = m_Pool.GetObject();

        ret.mTarget   = target;
        ret.mFileName = fileName;
        ret.CheckGameObject();
        return(ret);
    }
Example #6
0
    public override AssetCache CreateCache(UnityEngine.Object orgObj, string fileName, System.Type orgType)
    {
        if (orgObj == null)
        {
            return(null);
        }

        ResourceAssetCache cache = ResourceAssetCache.Create(orgObj, fileName, orgType);

        return(cache);
    }
Example #7
0
    public static ResourceAssetCache Create(UnityEngine.Object target, string fileName, System.Type targetType)
    {
        ResourceAssetCache ret;

        if (m_PoolUsed)
        {
            ret = GetPool(target, fileName, targetType);
        }
        else
        {
            ret = new ResourceAssetCache(target, fileName, targetType);
        }
        return(ret);
    }
Example #8
0
    private void AddCacheMap(AssetCache cache)
    {
        if (cache == null)
        {
            return;
        }
        ResourceAssetCache resCache = cache as ResourceAssetCache;

        if (resCache == null)
        {
            return;
        }
        AddCacheMap(resCache);
    }
Example #9
0
    public static ResourceAssetCache Create(UnityEngine.Object target)
    {
        ResourceAssetCache ret;

        if (m_PoolUsed)
        {
            ret = GetPool(target);
        }
        else
        {
            ret = new ResourceAssetCache(target);
        }
        return(ret);
    }
Example #10
0
    private T FindCache <T>(string fileName) where T : UnityEngine.Object
    {
        AssetCache cache = FindCache(fileName, typeof(T));

        if (cache == null)
        {
            return(null);
        }

        ResourceAssetCache resCache = cache as ResourceAssetCache;

        if (resCache == null)
        {
            return(null);
        }

        return(resCache.Target as T);
    }
Example #11
0
    public override Sprite[] LoadSprites(string fileName)
    {
        if (string.IsNullOrEmpty(fileName))
        {
            return(null);
        }

        Texture tex = LoadObject <Texture>(fileName, ResourceCacheType.rctTemp);

        if (tex == null)
        {
            return(null);
        }
        AssetCache cache = AssetCacheManager.Instance.FindOrgObjCache(tex);

        if (cache == null)
        {
            return(null);
        }

        ResourceAssetCache resCache = cache as ResourceAssetCache;

        if (resCache == null)
        {
            return(null);
        }

        if (!IsResLoaderFileName(ref fileName))
        {
            return(null);
        }

        Sprite[] ret = Resources.LoadAll <Sprite>(fileName);

        if (ret == null || ret.Length <= 0)
        {
            return(null);
        }

        AddRefSprites(resCache, ret, ResourceCacheType.rctRefAdd);

        return(ret);
    }
Example #12
0
    private void AddRefSprites(ResourceAssetCache cache, Sprite[] sprites, ResourceCacheType cacheType)
    {
        if (cache == null || sprites == null || sprites.Length <= 0)
        {
            return;
        }

        if (cacheType != ResourceCacheType.rctNone)
        {
            if (cacheType == ResourceCacheType.rctRefAdd)
            {
                AssetCacheManager.Instance._AddOrUpdateUsedList(cache, sprites.Length);
            }

            for (int i = 0; i < sprites.Length; ++i)
            {
                AssetCacheManager.Instance._OnLoadObject(sprites[i], cache);
            }
        }
    }
Example #13
0
    // changed is return true
    bool UpdateAssetRefMap()
    {
        bool ret = false;
        // used list
        var list = AssetCacheManager.Instance.UsedCacheList;

        if (list.Count != mUsedAssetRefMap.Count)
        {
            ret = true;
        }

        HashSet <string> hash       = new HashSet <string> ();
        HashSet <string> removeHash = new HashSet <string> ();

        var node = list.First;

        while (node != null)
        {
            AssetCache cache = node.Value;
            if (cache != null)
            {
                AssetBundleCache bundleCache = cache as AssetBundleCache;
                if ((bundleCache != null) && (bundleCache.Target != null))
                {
                    string key = GetBundleKey(bundleCache.Target.FileName);
                    hash.Add(key);
                    if (mUsedAssetRefMap.ContainsKey(key))
                    {
                        if (mUsedAssetRefMap[key] != cache.RefCount)
                        {
                            mUsedAssetRefMap[key] = cache.RefCount;
                            ret = true;
                        }
                    }
                    else
                    {
                        mUsedAssetRefMap.Add(key, cache.RefCount);
                        ret = true;
                    }
                }
                else
                {
                    ResourceAssetCache resCache = cache as ResourceAssetCache;
                    if ((resCache != null) && (resCache.Target != null))
                    {
                        string key = StringHelper.Format("Res:{0}", resCache.Target.name);
                        hash.Add(key);
                        if (mUsedAssetRefMap.ContainsKey(key))
                        {
                            if (mUsedAssetRefMap[key] != cache.RefCount)
                            {
                                mUsedAssetRefMap[key] = cache.RefCount;
                                ret = true;
                            }
                        }
                        else
                        {
                            mUsedAssetRefMap.Add(key, cache.RefCount);
                            ret = true;
                        }
                    }
                }
            }
            node = node.Next;
        }

        var iter = mUsedAssetRefMap.GetEnumerator();

        while (iter.MoveNext())
        {
            string key = iter.Current.Key;
            if (!hash.Contains(key))
            {
                removeHash.Add(key);
            }
        }
        iter.Dispose();

        var removeIter = removeHash.GetEnumerator();

        while (removeIter.MoveNext())
        {
            mUsedAssetRefMap.Remove(removeIter.Current);
        }
        removeIter.Dispose();
        hash.Clear();
        removeHash.Clear();

        // not used list
        list = AssetCacheManager.Instance.NotUsedCacheList;

        if (list.Count != mNotUsedAssetRefMap.Count)
        {
            ret = true;
        }

        node = list.First;
        while (node != null)
        {
            AssetCache cache = node.Value;
            if (cache != null)
            {
                AssetBundleCache bundleCache = cache as AssetBundleCache;
                if ((bundleCache != null) && (bundleCache.Target != null))
                {
                    string key = GetBundleKey(bundleCache.Target.FileName);
                    hash.Add(key);
                    if (mNotUsedAssetRefMap.ContainsKey(key))
                    {
                        if (mNotUsedAssetRefMap[key] != cache.RefCount)
                        {
                            mNotUsedAssetRefMap[key] = cache.RefCount;
                            ret = true;
                        }
                    }
                    else
                    {
                        mNotUsedAssetRefMap.Add(key, cache.RefCount);
                        ret = true;
                    }
                }
                else
                {
                    ResourceAssetCache resCache = cache as ResourceAssetCache;
                    if ((resCache != null) && (resCache.Target != null))
                    {
                        string key = StringHelper.Format("Res:{0}", resCache.Target.name);
                        hash.Add(key);
                        if (mNotUsedAssetRefMap.ContainsKey(key))
                        {
                            if (mNotUsedAssetRefMap[key] != cache.RefCount)
                            {
                                mNotUsedAssetRefMap[key] = cache.RefCount;
                                ret = true;
                            }
                        }
                        else
                        {
                            mNotUsedAssetRefMap.Add(key, cache.RefCount);
                            ret = true;
                        }
                    }
                }
            }
            node = node.Next;
        }

        iter = mNotUsedAssetRefMap.GetEnumerator();
        while (iter.MoveNext())
        {
            string key = iter.Current.Key;
            if (!hash.Contains(key))
            {
                removeHash.Add(key);
            }
        }
        iter.Dispose();

        removeIter = removeHash.GetEnumerator();
        while (removeIter.MoveNext())
        {
            mNotUsedAssetRefMap.Remove(removeIter.Current);
        }
        removeIter.Dispose();

        hash.Clear();
        removeHash.Clear();

        return(ret);
    }
Example #14
0
    void RefMapUpdate()
    {
        if (!Application.isPlaying)
        {
            return;
        }

        float curTime = Time.unscaledTime;

        m_IsUPdateData = curTime - m_LastUpdateTime > 0.25f;

        if (m_IsUPdateData)
        {
            m_LastUpdateTime = curTime;
        }

        if (m_IsUPdateData)
        {
            bool isChg = UpdateAssetRefMap();

            int cnt = TimerMgr.Instance.TimerPoolCount;
            if (cnt != m_LastTimeCnt)
            {
                m_LastTimeCnt = cnt;
                isChg         = true;
            }

            cnt = ResourceAssetCache.GetPoolCount();
            if (cnt != m_LastResCacheCnt)
            {
                m_LastResCacheCnt = cnt;
                isChg             = true;
            }

            cnt = AssetBundleCache.GetPoolCount();
            if (cnt != m_LastBundleCacheCnt)
            {
                m_LastBundleCacheCnt = cnt;
                isChg = true;
            }

#if UNITY_5_3 || UNITY_5_4 || UNITY_5_5 || UNITY_5_6 || UNITY_2018 || UNITY_2019
            cnt = BundleCreateAsyncTask.GetPoolCount();
            if (cnt != m_LastBundleCreateCnt)
            {
                m_LastBundleCreateCnt = cnt;
                isChg = true;
            }
                        #endif

            cnt = WWWFileLoadTask.GetPoolCount();
            if (cnt != m_LastWWWCreateCnt)
            {
                m_LastWWWCreateCnt = cnt;
                isChg = true;
            }

            cnt = HttpHelper.RunCount;
            if (cnt != m_LastRunHttpCnt)
            {
                m_LastRunHttpCnt = cnt;
                isChg            = true;
            }

            cnt = HttpHelper.PoolCount;
            if (cnt != m_LastHttpPoolCnt)
            {
                m_LastHttpPoolCnt = cnt;
                isChg             = true;
            }

            if (isChg)
            {
                this.Repaint();
            }
        }
    }
Example #15
0
    public override bool LoadSpritesAsync(string fileName, Action <float, bool, UnityEngine.Object[]> onProcess, int priority = 0)
    {
        return(LoadObjectAsync <Texture>(fileName, ResourceCacheType.rctRefAdd, priority,
                                         delegate(float process, bool isDone, Texture obj) {
            if (isDone)
            {
                if (obj == null)
                {
                    if (onProcess != null)
                    {
                        onProcess(process, isDone, null);
                    }
                    return;
                }

                AssetCache cache = AssetCacheManager.Instance.FindOrgObjCache(obj);
                if (cache == null)
                {
                    if (onProcess != null)
                    {
                        onProcess(process, isDone, null);
                    }
                    return;
                }

                ResourceMgr.Instance.DestroyObject(obj);

                ResourceAssetCache resCache = cache as ResourceAssetCache;
                if (resCache == null)
                {
                    if (onProcess != null)
                    {
                        onProcess(process, isDone, null);
                    }
                    return;
                }

                if (!IsResLoaderFileName(ref fileName))
                {
                    if (onProcess != null)
                    {
                        onProcess(process, isDone, null);
                    }
                    return;
                }
                Sprite[] ret = Resources.LoadAll <Sprite>(fileName);

                if (ret == null || ret.Length <= 0)
                {
                    if (onProcess != null)
                    {
                        onProcess(process, isDone, null);
                    }
                    return;
                }

                AddRefSprites(resCache, ret, ResourceCacheType.rctRefAdd);

                if (onProcess != null)
                {
                    onProcess(process, isDone, ret);
                }

                return;
            }

            if (onProcess != null)
            {
                onProcess(process, isDone, null);
            }
        }
                                         ));
    }