Exemple #1
0
        /// <summary>
        /// 获得基类
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <param name="iType"></param>
        /// <param name="bUserUse"></param>
        /// <returns></returns>
        public static T GetBase <T>(int iType, bool bUserUse = false) where T : Spirit, new()
        {
            //#if UNITY_EDITOR || UNITY_DEBUG
            if (!mStore.ContainsKey(iType))
            {
                Debug.LogError("ResStore error :  Cannot find resource type " + iType);
                return(null);
            }
            //#endif

            ResContainer arrContainer = mStore[iType];
            RES_Struct   res          = arrContainer.GetNewRes();

            res.bUserUse = bUserUse;
            res.bUsed    = true;

            if (!res.bAddComponented)
            {
                res.com = (T)res.obj.GetComponent <T>();
                if (!res.com)
                {
                    res.com = (T)res.obj.AddComponent <T>();
                }
                res.com.iInstanceType = iType;
                res.com.iInstanceId   = res.iInstanceId;
                res.bAddComponented   = true;
                return((T)res.com);
            }
            else
            {
                return((T)res.obj.GetComponent <T>());
            }
        }
Exemple #2
0
        /// <summary>
        /// 获得对象(需要手动删除)
        /// </summary>
        /// <param name="iType"></param>
        /// <returns></returns>
        public static GameObject Get(int iType)
        {
            ResContainer arrContainer = mStore[iType];
            RES_Struct   res          = arrContainer.GetNewRes();

            res.bUserUse = true;
            res.bUsed    = true;
            return(res.obj);
        }
Exemple #3
0
        public RES_Struct GetNewRes()
        {
            RES_Struct res = null;

            GetUnUseRes(ref res);
            if (null == res)
            {
                res = AddObject(((RES_Struct)list[0]).obj, true);
            }
            return(res);
        }
Exemple #4
0
 public void  GetUnUseRes(ref RES_Struct res)
 {
     for (int i = 1; i < list.Count; i++)
     {
         RES_Struct resn = (RES_Struct)list[i];
         if (!resn.bUsed && !resn.bUserUse)
         {
             res = resn;
             return;
         }
     }
 }
Exemple #5
0
 public void Recycle(int iId)
 {
     for (int i = 1; i < list.Count; i++)
     {
         RES_Struct res = (RES_Struct)list[i];
         if (res.iInstanceId == iId)
         {
             SetUnUse(ref res);
             return;
         }
     }
 }
Exemple #6
0
 public void Clear()
 {
     for (int i = 1; i < list.Count; i++)
     {
         RES_Struct res = (RES_Struct)list[i];
         if (!res.bUsed && !res.bUserUse)
         {
             MonoBehaviour.Destroy(((RES_Struct)list[i]).obj);
             list.RemoveAt(i);
             i--;
         }
     }
 }
Exemple #7
0
 public void Remove(int iId, bool bRemoveUserUse = false)
 {
     for (int i = 1; i < list.Count; i++)
     {
         RES_Struct res = (RES_Struct)list[i];
         if (res.iInstanceId == iId && bRemoveUserUse)
         {
             GameObject.Destroy(res.obj);
             list.RemoveAt(i);
             return;
         }
     }
 }
Exemple #8
0
        public RES_Struct AddObject(GameObject obj, bool bInstantiate = false)
        {
            RES_Struct rl = new RES_Struct();

            rl.obj      = bInstantiate ? MonoBehaviour.Instantiate(obj) as GameObject : obj;
            rl.obj.name = obj.name;
            rl.obj.SetActive(false);
            rl.bUsed           = false;
            rl.bAddComponented = false;
            rl.iInstanceId     = ResStore.NEW_ID;
            list.Add(rl);
            return(rl);
        }
Exemple #9
0
        public void RemoveAll(bool bRemoveUserUse = false)
        {
            int iBegin = 1;

            for (int i = list.Count - 1; i >= iBegin; i--)
            {
                RES_Struct res = (RES_Struct)list[i];
                if (bRemoveUserUse || !res.bUserUse)
                {
                    MonoBehaviour.Destroy(res.obj);
                    list.RemoveAt(i);
                }
            }
        }
Exemple #10
0
 public void SetUnUse(ref RES_Struct res)
 {
     res.bUsed = false;
     res.obj.SetActive(false);
 }