//注意name的大小写 public static List <M_ZLEvent> SelByFlag(EventT type, string name) { List <M_ZLEvent> list = ZLEventList.Where(p => p.MyType == type && p.Name.Equals(name)).ToList(); RemoveByList(list); return(list); }
/// <summary> /// 取出符合条件的事件,并移除事件 /// </summary> public static List <M_ZLEvent> SelByFlag(EventT type) { List <M_ZLEvent> list = ZLEventList.Where(p => p.MyType == type).ToList(); RemoveByList(list); return(list); }
private void Awake() { StopTimerEvent = StopTimer; ShowTimerEvent = ShowTimer; StartDecreasingTimerEvent = StartDecreasingTimer; StartIncreasingTimerEvent = StartIncreasingTimer; DeactivateEvent = Deactivate; }
public Asset(string assetName, Type type, string bundlePath, bool isFromBundle, EventT <Asset> callBack) { this._assetValue = null; this.IsDone = false; this.AssetName = assetName; this.AssetType = eAssetType.None; this.ValueType = type; this.BundlePathKey = bundlePath; this.OnAssetLoaded_CallbackOnce = callBack; this.IsFromBundle = isFromBundle; }
public void OnceT() { var counter = 0; EventHandler <EventArgs> handler = delegate { counter++; }; handler.Once(h => EventT += h, h => EventT -= h); EventT.Fire(this, EventArgs.Empty); Assert.Equal(1, counter); EventT.Fire(this, EventArgs.Empty); Assert.Equal(1, counter); }
public void FireFires() { var fired = false; var args = new EventArgs(); EventT += ((sender, aargs) => { Assert.Same(this, sender); Assert.Same(args, aargs); fired = true; }); Assert.True(EventT.Fire(this, args)); Assert.True(fired); }
/// <summary> /// PS,即便不存在,也能返回Asset,只是内容为空 /// </summary> /// <param name="pathAndassetName">路径大小写敏感</param> /// <param name="assetType"></param> /// <param name="warning">如果不存在,是否Log</param> /// <returns></returns> public Asset LoadAssetAsync(string pathAndassetName, eAssetType assetType, EventT <Asset> loadedCallBack = null, bool warning = true) { pathAndassetName = CheckAssetPath(pathAndassetName); #if UNITY_EDITOR if (!Application.isPlaying) { CommonLog.Error("非运行模式下,请勿调用AssetManager"); return(new Asset(pathAndassetName, assetType, null, false)); } if (pathAndassetName.Contains(@"\")) { CommonLog.Error("路径{0}格式错误,请使用/替换\\", pathAndassetName); return(null); } #endif //CommonLog.Log($ "加载类型为:{0}的资源:{1}", assetType, assetName); string bundlePath = this.GetBundlePath(pathAndassetName, assetType); Asset asset = this.CheckAssetInDicCache(assetType, bundlePath); if (asset != null) { if (loadedCallBack != null) { if (asset.IsDone) { loadedCallBack(asset); } else { //asset.OnAssetLoaded_CallbackOnce += loadedCallBack; asset.OnAssetLoaded_CallBacks.Add(loadedCallBack); } } return(asset); } string bundlename; bool isFromBundle = AssetBundleManager.Instance.CheckIsInBundle(pathAndassetName, out bundlename); asset = new Asset(pathAndassetName, assetType, bundlePath, isFromBundle, loadedCallBack); this.AddAssetData(bundlePath, assetType, asset); if (USED_AB_MODE) { //var task = GameTaskManager.Instance.CreateTask(this.LoadAssetFromResourcesAsync(asset, warning, assetType)); } else { LoadAssetFromDatabase(asset, warning, assetType); } return(asset); }
private void Awake() { IDeactivated[] deactivateds = transform.parent.GetComponentsInChildren <IDeactivated>(); for (int i = 0; i < deactivateds.Length; ++i) { OnDeactivate += deactivateds[i].Deactivate; } DeactivateEvent = OnDeactivate; SetInGameTextNowEvent = SetInGameTextNow; GetBarDialogEvent = GetBarDialog; GetBaseNewsEvent = GetBaseNews; GetBaseGoalsEvent = GetBaseGoals; GetNamesEvent = GetNames; InGameTexts = new TextInGame[InGameTextAssets.Length]; for (int i = 0; i < InGameTextAssets.Length; ++i) { LoadXML(InGameTextAssets[i], out InGameTexts[i]); } Dialogs = new TextDialog[DialogsTextAssets.Length]; for (int i = 0; i < DialogsTextAssets.Length; ++i) { LoadXML(DialogsTextAssets[i], out Dialogs[i]); } LoadXML(NamesTextAsset, out Names); LoadXML(BarDialogTextAsset, out BarDialog); TextBaseNews BaseNews; LoadXML(BaseNewsTextAsset, out BaseNews); News = UnboxNews(BaseNews); TextBaseGoals BaseGoals; LoadXML(BaseGoalsTextAsset, out BaseGoals); Goals = UnboxGoals(BaseGoals); GetDialogEvent = GetDialog; goalName = BaseGoals.goalname; goalcollectionName = BaseGoals.collectionname; GameDialogs.Names = Names; }
public void SetAssetValue(UnityEngine.Object val) { this._assetValue = val; CommonLog.Log(MAuthor.HSQ, $"资源{this.AssetName}加载完成"); IsDone = true; if (OnAssetLoaded_CallbackOnce != null) { this.OnAssetLoaded_CallbackOnce.Invoke(this); OnAssetLoaded_CallbackOnce = null; } if (OnAssetLoaded_CallBacks != null) { for (int i = 0; i < OnAssetLoaded_CallBacks.Count; i++) { OnAssetLoaded_CallBacks[i].Invoke(this); } OnAssetLoaded_CallBacks.Clear(); } }
public void TriggerEvent <T> (EventId evtId, T p0) { int eventId = (int)evtId; if (!_dicEvents.ContainsKey(eventId)) { return; } else { EventT <T> uEvent = _dicEvents[eventId] as EventT <T>; if (uEvent != null) { uEvent.Invoke(p0); } else { Debug.LogError(string.Format("## Event Trigger need Type {0}", _dicEvents[eventId].GetType())); } } }
public void RemoveEventListener <T> (EventId evtId, UnityAction <T> listener) { int eventId = (int)evtId; if (!_dicEvents.ContainsKey(eventId)) { return; } else { EventT <T> uEvent = _dicEvents[eventId] as EventT <T>; if (uEvent != null) { uEvent.RemoveListener(listener); } else { LogTypeError(eventId, listener, EventSystemDefine.dicHandleType[1]); } } }
public void OnceTWhenHandlerFails() { var counter = 0; EventHandler <EventArgs> handler = delegate { if (++counter == 1) { throw new ApplicationException(); } }; handler.Once(h => EventT += h, h => EventT -= h); try { EventT.Fire(this, EventArgs.Empty); } catch (ApplicationException) { } Assert.Equal(1, counter); EventT.Fire(this, EventArgs.Empty); Assert.Equal(1, counter); }
public void AddEventListener <T> (EventId evtId, UnityAction <T> listener) { int eventId = (int)evtId; if (!_dicEvents.ContainsKey(eventId)) { EventT <T> newEvent = new EventT <T>(); newEvent.AddListener(listener); _dicEvents[eventId] = newEvent; } else { EventT <T> uEvent = _dicEvents[eventId] as EventT <T>; if (uEvent != null) { uEvent.AddListener(listener); } else { LogTypeError(eventId, listener, EventSystemDefine.dicHandleType[0]); } } }
protected void Regist(EventT t, Action <EventData> cb) { dic.Add(t, cb); }
protected virtual void Regist(EventT t, Action <EventData> d) { dic.Add(t, d); }
public Asset LoadAssetAsync(AssetRef assetRef, eAssetType assetType, EventT <Asset> loadedCallBack = null, bool warning = true) { return(LoadAssetAsync(assetRef.AssetPath, assetType, loadedCallBack, warning)); }
public void FireReturnsFalseWhenNotFired() { Assert.False(EventT.Fire(this, EventArgs.Empty)); }
public void FireFailsWithNullArgs() { Assert.Throws <ArgumentNullException>(() => EventT.Fire(new object(), null)); }
public void FireFailsWithNullSender() { Assert.Throws <ArgumentNullException>(() => EventT.Fire(null, EventArgs.Empty)); }