public override void OnLoaded(Object obj)
            {
                OnResourcesLoadedDelegate <T> callback = mCallback;

                mCallback = null;
                if (callback != null)
                {
                    try { callback(obj as T); } catch (Exception e) { Debug.LogException(e); }
                }
            }
        private void GetResourcesInternal <T>(string folder, string file, Type type, OnResourcesLoadedDelegate <T> callback) where T : Object
        {
            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            if (type == null)
            {
                return;
            }
            if (callback == null)
            {
                return;
            }
            int           key = HashString.ComputeHash(folder, file);
            ResourcesData data;

            if (mLoaded.TryGetValue(key, out data))
            {
                data.refCount++;
                T target = data.obj as T;
                try {
                    callback(target);
                } catch (Exception e) {
                    Debug.LogException(e);
                }
                return;
            }
            LoadingData callbacks;
            bool        isLoading = GetLoadDelegateList(key, out callbacks);

            callbacks.AddCallback(CallbackHolderBase.Get <T>().SetCallback(callback));
            if (isLoading)
            {
                return;
            }
            callbacks.key  = key;
            callbacks.type = type;
            string path = folder == null ? file : (folder + file);

            async_loader.Load(path, type, callbacks.onLoaded);
        }
 public void GetInstance <T>(string folder, string file, bool actived, Vector3 position, Quaternion rotation, OnResourcesLoadedDelegate <T> callback) where T : Object
 {
     GetInstanceInternal(folder, file, typeof(T), actived, true, position, rotation, callback);
 }
 public override void Clear()
 {
     callback = null;
 }
 public InstanceLoadingData() : base(typeof(T))
 {
     mOnLoaded = OnResourcesLoaded;
 }
        private InstanceLoadingData <T> GetInstanceLoadingData <T>(int key, Type type, bool actived, bool initTrans,
                                                                   Vector3 position, Quaternion rotation, OnResourcesLoadedDelegate <T> callback) where T : Object
        {
            InstanceLoadingData <T> ret = null;
            Type t = typeof(T);
            Queue <InstanceLoadingDataBase> queue;

            if (mCachedInstanceLoadingDatas.TryGetValue(t, out queue) && queue.Count > 0)
            {
                ret = queue.Dequeue() as InstanceLoadingData <T>;
            }
            if (ret == null)
            {
                ret = new InstanceLoadingData <T>();
                if (mOnInstanceCreated == null)
                {
                    mOnInstanceCreated = OnInstanceCreated;
                }
                ret.onInstanceCreated = mOnInstanceCreated;
                if (mCacheInstanceLoadingData == null)
                {
                    mCacheInstanceLoadingData = CacheInstanceLoadingData;
                }
                ret.onFinished = mCacheInstanceLoadingData;
            }
            ret.key       = key;
            ret.type      = type;
            ret.actived   = actived;
            ret.initTrans = initTrans;
            ret.position  = position;
            ret.rotation  = rotation;
            ret.callback  = callback;
            return(ret);
        }
 public void GetInstance <T>(string path, Vector3 position, Quaternion rotation, OnResourcesLoadedDelegate <T> callback) where T : Object
 {
     GetInstanceInternal(null, path, typeof(T), true, true, position, rotation, callback);
 }
 public void GetInstance <T>(string folder, string file, bool actived, OnResourcesLoadedDelegate <T> callback) where T : Object
 {
     GetInstanceInternal(folder, file, typeof(T), actived, false, Vector3.zero, Quaternion.identity, callback);
 }
        private void GetInstanceInternal <T>(string folder, string file, Type type, bool actived, bool initTrans, Vector3 position, Quaternion rotation, OnResourcesLoadedDelegate <T> callback) where T : Object
        {
            if (string.IsNullOrEmpty(file))
            {
                return;
            }
            int key = HashString.ComputeHash(folder, file);
            T   obj = GetCachedInstance <T>(key);

            if (obj != null)
            {
                GameObject go = obj as GameObject;
                if (go != null)
                {
                    go.SetActive(false);
                    Transform t = go.transform;
                    t.SetParent(null, true);
                    if (initTrans)
                    {
                        t.position = position;
                        t.rotation = rotation;
                    }
                    if (actived)
                    {
                        go.SetActive(true);
                    }
                }
                try { callback(obj); } catch (Exception e) { Debug.LogException(e); }
                return;
            }
            InstanceLoadingData <T> data = GetInstanceLoadingData <T>(key, type, actived, initTrans, position, rotation, callback);

            GetResourcesInternal <T>(folder, file, type, data.onLoaded);
        }
 public void GetInstance <T>(string path, OnResourcesLoadedDelegate <T> callback) where T : Object
 {
     GetInstanceInternal(null, path, typeof(T), true, false, Vector3.zero, Quaternion.identity, callback);
 }
 public void GetInstance(string path, Type type, bool actived, Vector3 position, Quaternion rotation, OnResourcesLoadedDelegate <Object> callback)
 {
     GetInstanceInternal(null, path, type, actived, true, position, rotation, callback);
 }
 public void GetInstance(string path, Type type, bool actived, OnResourcesLoadedDelegate <Object> callback)
 {
     GetInstanceInternal(null, path, type, actived, false, Vector3.zero, Quaternion.identity, callback);
 }
示例#13
0
 public void GetResources(string path, Type type, OnResourcesLoadedDelegate <Object> callback)
 {
     GetResourcesInternal(null, path, type, callback);
 }
示例#14
0
 public CallbackHolder <T> SetCallback(OnResourcesLoadedDelegate <T> callback)
 {
     mCallback = callback; return(this);
 }
示例#15
0
 public void GetResources <T>(string folder, string file, OnResourcesLoadedDelegate <T> callback) where T : Object
 {
     GetResourcesInternal(folder, file, typeof(T), callback);
 }
示例#16
0
 public void GetResources <T>(string path, OnResourcesLoadedDelegate <T> callback) where T : Object
 {
     GetResourcesInternal(null, path, typeof(T), callback);
 }