private T GetCachedInstance <T>(int key) where T : Object
        {
            List <InstanceInfo> list;

            if (!mCachedInstances.TryGetValue(key, out list))
            {
                return(null);
            }
            T ret = null;

            while (0 < list.Count)
            {
                InstanceInfo instance = list[0];
                list.RemoveAt(0);
                if (instance.obj != null && !instance.obj.Equals(null))
                {
                    List <InstanceInfo> usingList = GetUsingInstanceList(key);
                    usingList.Add(instance);
                    ret = instance.obj as T;
                    break;
                }
                Debug.LogErrorFormat("[ResourcesHolder] GetCachedInstance() Object instance of '{0}' is destroyed unexpectedly",
                                     HashString.GetString(key));
            }
            if (list.Count <= 0)
            {
                mCachedInstances.Remove(key);
                cached_instance_list.Enqueue(list);
            }
            return(ret);
        }
        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);
        }
        private void OnLoaded2(LoadingData loadingData, Object obj)
        {
            int  key  = loadingData.key;
            bool flag = mLoadings.Remove(key);

            loadingData.Clear();
            cached_loading_lists.Enqueue(loadingData);
            if (!flag)
            {
                Debug.LogErrorFormat("[ResourcesHolder] in OnLoaded() No callbacks found for '{0}' !",
                                     HashString.GetString(key));
            }
        }
        private void OnLoaded1(LoadingData loadingData, Object obj, int count)
        {
            if (obj == null)
            {
                Debug.LogErrorFormat("[ResourcesHolder] Fail to load file '{0}' !", HashString.GetString(loadingData.key));
                return;
            }
            ResourcesData data = CreateResourcesData(loadingData.type, obj);

            data.refCount = count;
            mLoaded.Add(loadingData.key, data);
            mResourcesToPath.Add(GetResourcesKey(loadingData.type, obj), loadingData.key);
        }
        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);
        }
        private T GetInstanceSyncInternal <T>(string folder, string file, bool actived, bool initTrans, Vector3 position, Quaternion rotation) where T : Object
        {
            if (string.IsNullOrEmpty(file))
            {
                return(null);
            }
            int key = HashString.ComputeHash(folder, file);
            T   obj = GetCachedInstance <T>(key);

            if (obj == null)
            {
                Type type   = typeof(T);
                T    prefab = GetResourcesInternalSync <T>(folder, file, type);
                if (prefab == null)
                {
                    return(null);
                }
                obj = initTrans && prefab is GameObject?
                      Object.Instantiate(prefab, position, rotation) : Object.Instantiate(prefab);

                OnInstanceCreated(key, type, obj);
            }
            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);
                }
            }
            return(obj);
        }
        private T GetResourcesInternalSync <T>(string folder, string file, Type type) where T : Object
        {
            if (string.IsNullOrEmpty(file))
            {
                return(null);
            }
            if (type == null)
            {
                return(null);
            }
            int           key = HashString.ComputeHash(folder, file);
            ResourcesData data;

            if (!mLoaded.TryGetValue(key, out data))
            {
                return(null);
            }
            data.refCount++;
            T target = data.obj as T;

            return(target);
        }
        private bool ReleaseResourcesInternal(Type type, Object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            int key;

            if (!mResourcesToPath.TryGetValue(GetResourcesKey(type, obj), out key))
            {
                Debug.LogWarningFormat("[ResourcesHolder] ReleaseResourcesInternal() resource '{0}' not managed !", obj);
                return(false);
            }
            ResourcesData data;

            if (!mLoaded.TryGetValue(key, out data))
            {
                Debug.LogWarningFormat("[ResourcesHolder] ReleaseResourcesInternal() resource '{0}' not managed !", HashString.GetString(key));
                return(false);
            }
            data.refCount--;
            return(true);
        }