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); }
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); }