public void ShouldHookedToEventHandler_WhenSubscriberSubscribeToSubject() { var del = new ListenDelegate(_currencyUnitOfWork.JPNSubscriber.Listen); // Delegate of JPN Subscriber _app.SubscribeUnsubscribeByCMD(TargetSubject.CNYSubj.ToUpper(), _currencyUnitOfWork.JPNSubscriber, true); // JPN Subscriber Subscribe To CNY Subject. Assert.True(_currencyUnitOfWork.CNYPublisher.IsDelegateHooked(del)); // Assert That delegate is hooked... }
public IURLLoader asynLoad(string url, ListenDelegate dele, bool autoDelete, bool errNotify) { url = url.Trim(); if ("" == url || false == url.EndsWith(".u3d")) { throw new Exception("AsynResourceMgr -> ansynLoad() -> url[" + url + "] is empty or not end with .u3d"); } // if (!_URLLoaders.ContainsKey(url)) { URLLoader lo = new URLLoader(); lo.url = url; if (fileVers.ContainsKey(url)) { lo.fileVersion = fileVers[url]; } lo.fullUrl = fullUrl(url, lo.fileVersion); _URLLoaders.Add(url, lo); // Debug.Log("=============== url: "+url+" verson: "+lo.fileVersion+" ============="); } URLLoader loader = _URLLoaders[url] as URLLoader; // add listener loader.addListener(dele, errNotify); // auto delete if (loader.autoDelete == true) { loader.autoDelete = autoDelete; } if (_delayAutoDelete) { loader.preventAutoDelete = true; } URLLoaderState state = loader.state; if (state == URLLoaderState.unload) { putinWaitingList(loader); fullDownload(); } else if (state == URLLoaderState.waiting || state == URLLoaderState.loading) { //nothing } else if (state == URLLoaderState.loaded || state == URLLoaderState.error) { //enter to notify list, next update to notify user _notifyList.Add(loader); } return(loader); }
public void ShouldHookedOnceToEventHandler_EvenWhenSubscriberTriesToSubscribeMoreThanOnce() { var del = new ListenDelegate(_currencyUnitOfWork.JPNSubscriber.Listen); // Delegate of JPN Subscriber _app.SubscribeUnsubscribeByCMD(TargetSubject.CNYSubj.ToUpper(), _currencyUnitOfWork.JPNSubscriber, true); // JPN Subscriber Subscribe To CNY Subject. // Subscribe twice _app.SubscribeUnsubscribeByCMD(TargetSubject.CNYSubj.ToUpper(), _currencyUnitOfWork.JPNSubscriber, true); // JPN Subscriber Subscribe To CNY Subject. Assert.True(_currencyUnitOfWork.CNYPublisher.IsDelegateHookedOnce(del)); // Assert That delegate is hooked only once... }
//添加单词监听事件 public void AddOnceListener(string className, ListenDelegate cb) { ListenDelegate method; if (onceDic.TryGetValue(className, out method)) { method += cb; } else { onceDic[className] = cb; } }
//添加监听事件 public void AddListener(string className, ListenDelegate cb) { Debug.Log("增加方法" + className + ":" + cb.ToString()); ListenDelegate method; if (eventDic.TryGetValue(className, out method)) { method += cb; } else { eventDic[className] = cb; } }
//删除监听事件 public void DelListener(string className, ListenDelegate cb) { Debug.Log("删除方法" + className + ":" + cb.ToString()); ListenDelegate method; if (eventDic.ContainsKey(className)) { method = eventDic[className]; method -= cb; if (method == null) { eventDic.Remove(className); } } }
public int removeDelegate(string url, ListenDelegate dele) { if (!_URLLoaders.ContainsKey(url)) { return(0); } URLLoader loader = _URLLoaders[url] as URLLoader; int count = loader.removeListener(dele); //no listener, auto delete, in waiting list. Destroy immediately, Avoid to download! if (loader.listeners.Count == 0 && loader.isAutoDelete() && loader.state == URLLoaderState.waiting) { destroyLoader(loader, false, false); } return(count); }
public IURLLoader asynLoad(string url, ListenDelegate dele, bool autoDelete) { return(asynLoad(url, dele, autoDelete, false)); }
public IURLLoader asynLoad(string url, ListenDelegate dele) { return(asynLoad(url, dele, true, false)); }