private static void CacheEntity <T>(T entity) where T : Entity { if (!Instance.refrencesDic.ContainsKey(entity.instanceId)) { Instance.refrencesDic.Add(entity.instanceId, entity); Instance.refrencesList.Add(entity); } else { HFLog.E(typeof(T).Name + entity.instanceId + "引用重复添加"); } }
public static void RemoveEntity <T>(T entity) where T : Entity { if (Instance.refrencesDic.ContainsKey(entity.instanceId)) { Instance.refrencesDic.Remove(entity.instanceId); Instance.refrencesList.Remove(entity); } else { HFLog.E(typeof(T).Name + entity.instanceId + "引用移除失败"); } }
/// <summary> /// 销毁BaseElement 重载方法 /// </summary> public virtual void Destroy() { if (IsDisposed) { HFLog.E("Entity 重复销毁 Id " + instanceId); return; } for (int i = components.Count - 1; i >= 0; i--) { Component Component = components[i]; components.RemoveAt(i); Component.OnDestroy(); } for (int i = childs.Count - 1; i >= 0; i--) { Entity child = childs[i]; childs.RemoveAt(i); child.Destroy(); } binder.Clear(); parent = null; foreach (var item in messageTypeSet) { NotificationCenter.Instance.RemoveObserver(this, item); } messageTypeSet.Clear(); IsNeedUpdate = false; IsNeedFixedUpdate = false; IsNeedLateUpdate = false; DestoryGameObject(); GameFactory.RemoveEntity(this); instanceId = 0; }
public void Refresh(List <T> dataList, Func <K> Create, Action <T, K> ViewRefresh) { if (dataList == null) { HFLog.E("dataList = null"); return; } if (dataList.Count > 20) { HFLog.C("视图层数量大于20 适用复用滚动列表实现"); } this.dataList = dataList; if (dataList.Count < viewList.Count) { for (int i = dataList.Count; i < viewList.Count; i++) { viewList[i].IsActive = false; } } for (int i = 0; i < dataList.Count; i++) { T data = dataList[i]; K k = null; if (i < viewList.Count) { k = viewList[i]; k.IsActive = true; } else { //生成Item列表并显示数据 k = Create(); viewList.Add(k); } ViewRefresh(data, k); } }
public void Send(NotificationMessage msg) { try { List <ObserverDelegate> list; if (messagePool.TryGetValue(msg.Key, out list)) { for (int i = 0; i < list.Count; i++) { ObserverDelegate o = list[i]; if (o.receiver != null && o.handler != null) { o.handler(msg); } } } } catch (Exception e) { HFLog.E(e); throw; } }
/// <summary> /// 转移到某个状态 /// </summary> /// <param name="stateName"></param> public async UniTaskVoid ChangeState <T>(object enterParams = null, object exitParams = null) where T : FSMState, new() { if (!locked) { locked = true; string key = typeof(T).Name; if (currentState != null) { await currentState.Exit(exitParams); } if (!stateDic.TryGetValue(key, out currentState)) { currentState = AddState <T>(); } await currentState.Enter(enterParams); locked = false; } else { HFLog.E("重复转换状态 " + typeof(T).Name); } }
/// <summary> /// 添加一个观察者 /// </summary> /// <param name="receiver"></param> /// <param name="msgID"></param> /// <param name="callback"></param> public void AddObserver(object receiver, ushort moduleId, int msgId, Action <NotificationMessage> callback) { if (receiver == null) { HFLog.E(" moduleID = " + moduleId + " msgID = " + msgId + " receiver 不能为空"); return; } if (callback == null) { HFLog.E(" moduleID = " + moduleId + " msgID = " + msgId + " callback 不能为空"); return; } ObserverDelegate o = new ObserverDelegate(receiver, moduleId, msgId, callback); List <ObserverDelegate> list; if (!messagePool.TryGetValue(o.Key, out list)) { list = new List <ObserverDelegate>(); messagePool.Add(o.Key, list); } list.Add(o); }
private void CatchException(object sender, UnhandledExceptionEventArgs e) { HFLog.E("未捕获异常 " + e.ExceptionObject); }
private void UniTaskCatchException(Exception e) { HFLog.E(e); }