Esempio n. 1
0
        /// <summary>
        /// 请求资源,使用后记得还回Recycle
        /// </summary>
        /// <typeparam name="T"></typeparam>
        /// <returns></returns>
        public T GetAsset <T>() where T : UObject
        {
            Init <T>();

            UObject obj = null;

            if (rt == ResourceType.Multi)
            {
                if (unactiveCopies.Count > 0)
                {
                    obj = unactiveCopies.Pop();
                    if (obj == null)
                    {
                        return(GetAsset <T>());//防止已经被外部Destroy
                    }
                    activeCopies.Add(obj);
                    try
                    {
                        GameObject unactiveObj = (obj as GameObject);
                        unactiveObj.transform.SetParent(null);
                    }catch (Exception e)
                    {
                        DebugUtil.LogError(this.source.name + ":" + e.ToString());
                    }
                }
                else
                {
                    obj = UObject.Instantiate(source);
                    activeCopies.Add(obj);
                    obj.name = obj.name.Replace("(Clone)", "");
#if UNITY_EDITOR
                    AddDestroyNotify(obj as GameObject);
                    resetShader(obj as GameObject);
#endif
                }
#if UNITY_EDITOR
                AddUseCount(obj as GameObject);
#endif
            }
            else if (rt == ResourceType.Single)
            {
                RefCount++;
                obj = source;
            }
            if (obj != null)
            {
                CheckIdle();
                if (parent != null)
                {
                    parent.CheckIdle();
                }
                return(obj as T);
            }
            return(null);
        }