//检测实体是否处理符合条件 public bool CheckEntity(Entity entity) { //是否需要检测 bool check = true; //需要监听的组件列表 List <BaseCom> listenComs = new List <BaseCom>(); //实体关闭 if (entity.IsEnable == false) { check = false; } else { for (int i = 0; i < ListenComs.Count; i++) { string typeName = ListenComs[i].FullName; BaseCom com = entity.GetCom(typeName); //没有这个组件直接返回(因为组件没有删除,只有激活于禁用) if (com == null) { return(false); } else { //组件被禁用了 if (com.IsActive == false) { check = false; break; } else { listenComs.Add(com); } } } } int entityId = entity.GetHashCode(); //需要检测 if (check) { if (!IdHandleComsDict.ContainsKey(entityId)) { IdHandleComsDict.Add(entityId, listenComs); OnAddCheckComs(IdHandleComsDict[entityId]); } } else { if (IdHandleComsDict.ContainsKey(entityId)) { OnRemoveCheckComs(IdHandleComsDict[entityId]); IdHandleComsDict.Remove(entityId); } } return(check); }
protected static T GetCom <T>(BaseCom baseCom) where T : BaseCom { return(baseCom as T); }