Exemple #1
0
        public static object GetCach(string key)
        {
            if (string.IsNullOrWhiteSpace(key))
            {
                return(null);
            }

            try
            {
                rwLock.EnterReadLock();
                KeyValuePair <string, CachItem> kv = CachPool.FirstOrDefault(c => c.Key == key);

                CachItem item = kv.Value;
                if (item == null)
                {
                    return(null);
                }

                if (kv.Value.CachTime < DateTime.Now)
                {
                    //CachPool.Remove(key);
                    return(null);
                }

                return(kv.Value.CachObj);
            }
            finally
            {
                rwLock.ExitReadLock();
            }
        }
Exemple #2
0
 static void recyle(CachItem item)
 {
     mCach.Remove(item.mKey);
     item.mKey    = null;
     item.mRef    = 0;
     item.mReside = ResideType.None;
     mPool.Add(item);
 }
Exemple #3
0
 static void traceUnload(CachItem rl)
 {
     if (rl.mKey != traceAsset)
     {
         return;
     }
     Debug.Log("unload reside=" + rl.mReside + " ref=" + rl.mRef);
 }
Exemple #4
0
 public static ResLoad get(string path, ResideType reside = ResideType.None, int v = 0)
 {
                 #if CHECK_PATH
     checkPathCase(path);
                 #endif
     CachItem it = CachItem.getFromCach(path, reside);
     it.mVer = v;
     return(new ResLoad(it));
 }
Exemple #5
0
            internal static void clearByPath(string path)
            {
                CachItem item = null;

                if (mCach.TryGetValue(path, out item))
                {
                    item.release(true);
                }
            }
Exemple #6
0
 //----------------
 ResLoad(CachItem ci)
 {
     mItem     = ci;
     mUniqueID = mItem.mUniqueID;
     if (mItem.mReside == ResideType.Ref)
     {
         ++mItem.mRef;
     }
 }
Exemple #7
0
 public ResLoad(ResLoad rl)
 {
     mItem     = rl.mItem;
     mUniqueID = mItem.mUniqueID;
     if (mItem.mReside == ResideType.Ref)
     {
         ++mItem.mRef;
     }
 }
Exemple #8
0
 public static ResLoad get(string path, string tag, int v = 0)
 {
                 #if CHECK_PATH
     checkPathCase(path);
                 #endif
     CachItem it = CachItem.getFromCach(path, ResideType.InGame);
     it.mVer = v;
     it.mTag = tag;
     return(new ResLoad(it));
 }
Exemple #9
0
            internal static void addAssetRef(string key)
            {
                CachItem item = null;

                if (mCach.TryGetValue(key, out item))
                {
                    if (item.mReside != ResideType.Ref)
                    {
                        return;
                    }
                    ++item.mRef;
                }
            }
Exemple #10
0
            internal static void decAssetRef(string key)
            {
                CachItem item = null;

                if (mCach.TryGetValue(key, out item))
                {
                    if (item.mReside != ResideType.Ref)
                    {
                        return;
                    }
                    item.release();
                }
            }
Exemple #11
0
            internal static List <string> getCachAssets()
            {
                List <string>         ls = new List <string> ();
                IDictionaryEnumerator e  = mCach.GetEnumerator();

                while (e.MoveNext())
                {
                    CachItem it = e.Value as CachItem;
                    ls.Add(it.mKey + ":" + it.mReside + ":" + it.mRef);
                }
                ls.Sort(delegate(string x, string y){
                    return(x.CompareTo(y));
                });
                return(ls);
            }
Exemple #12
0
 public void release()
 {
     if (mItem == null)
     {
         return;
     }
     if (mUniqueID != mItem.mUniqueID)
     {
         return;
     }
     mItem.release();
     mItem   = null;
     mParam1 = null;
     mParam2 = null;
     mParam3 = null;
 }
Exemple #13
0
            //--------------
            #region cach管理
            internal static CachItem getFromCach(string key, ResideType reside)
            {
                CachItem item = null;

                if (mCach.TryGetValue(key, out item))
                {
                    if (item.mReside != ResideType.Ref && item.mReside < reside)
                    {
                        item.mReside = reside;
                    }
                    item.mTime = Time.realtimeSinceStartup;
                }
                else
                {
                    if (mPool.Count > 0)
                    {
                        item = mPool[0];
                        mPool.RemoveAt(0);
                    }
                    else
                    {
                        item = new CachItem();
                    }

                    item.mKey      = key;
                    item.mReside   = reside;
                    item.mRef      = 0;
                    item.mVer      = 0;
                    item.mIsPrefab = false;
                    item.mIsAB     = false;
                    item.mCallData = null;
                    item.mTag      = null;

                    if (item.mReside != ResideType.None)
                    {
                        item.mTime        = Time.realtimeSinceStartup;
                        mCach [item.mKey] = item;
                    }
                }
                item.mUniqueID = ++uniqueID;
                                #if UNITY_EDITOR
                traceLoad(item);
                                #endif
                return(item);
            }
Exemple #14
0
            internal static void clearByReside(ResideType riside)
            {
                ArrayList             ls = new ArrayList();
                IDictionaryEnumerator e  = mCach.GetEnumerator();

                while (e.MoveNext())
                {
                    CachItem it = e.Value as CachItem;
                    if (it.mReside == riside)
                    {
                        ls.Add(it);
                    }
                }
                for (int i = 0, max = ls.Count; i < max; ++i)
                {
                    CachItem it = ls[i] as CachItem;
                    it.release(true);
                }
            }
Exemple #15
0
            internal static void clearByTag(string tag)
            {
                ArrayList             ls = new ArrayList();
                IDictionaryEnumerator e  = mCach.GetEnumerator();

                while (e.MoveNext())
                {
                    CachItem it = e.Value as CachItem;
                    if (tag == it.mTag)
                    {
                        ls.Add(it);
                    }
                }
                for (int i = 0, max = ls.Count; i < max; ++i)
                {
                    CachItem it = ls[i] as CachItem;
                    it.release(true);
                }
            }
Exemple #16
0
 void loadDepends()
 {
     //图片应该都打成依赖包,这样就可以使用引用计数管理
     mDepends = mManifest.GetDirectDependencies(mKey + ext);
     for (int i = 0, max = mDepends.Length; i < max; ++i)
     {
         mDepends[i] = mDepends[i].Remove(mDepends[i].Length - 5);
         CachItem ci = CachItem.getFromCach(mDepends[i], ResideType.Ref);
         ++ci.mRef;
         if (null == ci.assetBundle())
         {
             Log.e("load ab failed path=" + mKey, Log.Tag.RES);
         }
         //有的assetbundle是全局预加载的使用的非ref模式,如shader
         if (ci.mReside != ResideType.Ref)
         {
             mDepends[i] = null;
         }
     }
 }
Exemple #17
0
            internal static void clearCach()
            {            //清除cach,忽略所有引用,注意存在引用计数的资源
                IDictionaryEnumerator e = mCach.GetEnumerator();

                while (e.MoveNext())
                {
                    CachItem it = e.Value as CachItem;
                    //避免ab被unload(true)导致当前显示的资源丢失
                    it.mReside = ResideType.None;
                    it.innerRelease();
                }
                mCach.Clear();
                //解除引用计数关系
                AssetRef[] ars = Resources.FindObjectsOfTypeAll <AssetRef> ();
                for (int i = 0, max = ars.Length; i < max; ++i)
                {
                    if (ars[i].hasDepends())
                    {
                        ars [i].setDepends(null);
                    }
                }
            }
Exemple #18
0
 public static List <string> getCachAssets()
 {
     return(CachItem.getCachAssets());
 }
Exemple #19
0
 public static void setTraceAsset(string path)
 {
     CachItem.setTraceAsset(path);
 }
Exemple #20
0
 public static void clearByTag(string tag)
 {
     CachItem.clearByTag(tag);
 }
Exemple #21
0
 public static void clearReside(ResideType riside)
 {
     CachItem.clearByReside(riside);
 }
Exemple #22
0
 public static void clearByPath(string path)
 {
     CachItem.clearByPath(path);
 }
Exemple #23
0
 internal static void addAssetRef(string path)
 {
     CachItem.addAssetRef(path);
 }
Exemple #24
0
 public static void clearCach()
 {
     CachItem.clearCach();
 }
Exemple #25
0
 public static bool isInCach(string path)
 {
     return(CachItem.isInCach(path));
 }
Exemple #26
0
 internal static void decAssetRef(string path)
 {
     CachItem.decAssetRef(path);
 }