public void Clear() { for (int i = 0, imax = mCallbacks.Count; i < imax; i++) { CallbackHolderBase.Cache(mCallbacks[i]); } mCallbacks.Clear(); }
public void AddCallback(CallbackHolderBase callback) { if (callback == null) { return; } mCallbacks.Add(callback); }
private void OnLoaded(Object obj) { int count = mCallbacks.Count; onPreCallbacks(this, obj, count); for (int i = 0; i < count; i++) { CallbackHolderBase callback = mCallbacks[i]; callback.OnLoaded(obj); CallbackHolderBase.Cache(callback); } mCallbacks.Clear(); onPostCallbacks(this, obj); }
public static void Cache(CallbackHolderBase ins) { if (ins == null) { return; } Queue <CallbackHolderBase> queue; if (instances.TryGetValue(ins.mType, out queue)) { queue.Enqueue(ins); } else { queue = new Queue <CallbackHolderBase>(); queue.Enqueue(ins); instances.Add(ins.mType, queue); } }
private static int InsertHolder(CallbackHolderBase holder) { int idx; lock (CallbackTable.locker) { if (CallbackTable.freeIndexes.Count == 0) { idx = CallbackTable.holders.Count; CallbackTable.holders.Add(holder); } else { idx = CallbackTable.freeIndexes.Pop(); CallbackTable.holders[idx] = holder; } } return(idx); }
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); }