public void OnEntityComponentChange(EntityBase entity, string compName, ComponentBase component) { //Debug.Log("OnEntityComponentChange"); List <ECSGroup> oldSystems; if (!entityToGroupDic.TryGetValue(entity, out oldSystems)) { oldSystems = new List <ECSGroup>(); entityToGroupDic.Add(entity, oldSystems); } List <ECSGroup> newGroupList = GetEntitySuportGroup(entity); entityToGroupDic[entity] = newGroupList; for (int i = 0; i < newGroupList.Count; i++) { ECSGroup sys = newGroupList[i]; if (!oldSystems.Contains(sys)) { List <EntityBase> list = groupToEntityDic[sys]; if (list == null) { list = new List <EntityBase>(); } list.Add(entity); } } for (int i = 0; i < oldSystems.Count; i++) { ECSGroup sys = oldSystems[i]; if (!newGroupList.Contains(sys)) { List <EntityBase> list = groupToEntityDic[sys]; if (list == null) { list = new List <EntityBase>(); } list.Remove(entity); } } }
private bool AddGroup(int key, string[] filters) { if (filters == null || filters.Length == 0) { Debug.LogError("AddGroup 失败,参数不能为空!"); return(false); } if (allGroupDic.ContainsKey(key)) { Debug.LogError("AddGroup 失败,名字重复!"); return(false); } ECSGroup group = new ECSGroup(key, filters, world); allGroupDic.Add(key, group); allGroupList.Add(group); List <EntityBase> newListEntity = new List <EntityBase>(); List <EntityBase> listEntity = new List <EntityBase>(entityToGroupDic.Keys); for (int i = 0; i < listEntity.Count; i++) { EntityBase entity = listEntity[i]; //List<ECSGroup> newGroupList = GetEntitySuportGroup(entity); bool isContains = true; for (int j = 0; j < filters.Length; j++) { if (!entity.GetExistComp(filters[j])) { isContains = false; } } if (isContains) { newListEntity.Add(entity); entityToGroupDic[entity].Add(group); } } groupToEntityDic.Add(group, newListEntity); return(true); }
public bool AddGroup(string name, string[] componentFilter) { if (string.IsNullOrEmpty(name) || componentFilter == null || componentFilter.Length == 0) { Debug.LogError("AddGroup 失败,参数不能为空!"); return(false); } if (allGroupDic.ContainsKey(name)) { Debug.LogError("AddGroup 失败,名字重复!"); return(false); } ECSGroup group = new ECSGroup(name, componentFilter); allGroupDic.Add(name, group); List <EntityBase> newListEntity = new List <EntityBase>(); List <EntityBase> listEntity = new List <EntityBase>(entityToGroupDic.Keys); for (int i = 0; i < listEntity.Count; i++) { EntityBase entity = listEntity[i]; //List<ECSGroup> newGroupList = GetEntitySuportGroup(entity); bool isContains = true; for (int j = 0; j < componentFilter.Length; j++) { if (!entity.CompDict.ContainsKey(componentFilter[j])) { isContains = false; } } if (isContains) { newListEntity.Add(entity); entityToGroupDic[entity].Add(group); } } groupToEntityDic.Add(group, newListEntity); return(true); }
public ECSGroupManager(WorldBase world) { this.world = world; for (int i = 0; i < world.m_systemList.Count; i++) { SystemBase system = world.m_systemList[i]; if (system.Filter.Length == 0) { continue; } int key = StringArrayToInt(system.Filter); if (allGroupDic.ContainsKey(key)) { //Debug.Log("System :"+ system.GetType().FullName+ " Filter :" + string.Join(",", system.Filter) + " Dic :"+string.Join(",",allGroupDic[key].Components)); continue; } ECSGroup group = new ECSGroup(key, system.Filter, world); allGroupDic.Add(key, group); allGroupList.Add(group); groupToEntityDic.Add(group, new List <EntityBase>()); } for (int i = 0; i < world.m_recordList.Count; i++) { RecordSystemBase system = world.m_recordList[i]; if (system.Filter.Length == 0) { continue; } int key = StringArrayToInt(system.Filter); if (allGroupDic.ContainsKey(key)) { //Debug.Log("System :" + system.GetType().FullName + " Filter :" + string.Join(",", system.Filter) + " Dic :" + string.Join(",", allGroupDic[key].Components)); continue; } ECSGroup group = new ECSGroup(key, system.Filter, world); allGroupDic.Add(key, group); allGroupList.Add(group); groupToEntityDic.Add(group, new List <EntityBase>()); } }
public ECSGroupManager(WorldBase world) { //this.world = world; for (int i = 0; i < world.m_systemList.Count; i++) { SystemBase system = world.m_systemList[i]; string name = system.GetType().FullName; ECSGroup group = new ECSGroup(name, system.Filter); allGroupDic.Add(name, group); groupToEntityDic.Add(group, new List <EntityBase>()); } for (int i = 0; i < world.m_recordList.Count; i++) { RecordSystemBase system = world.m_recordList[i]; string name = system.GetType().FullName; ECSGroup group = new ECSGroup(name, system.Filter); allGroupDic.Add(name, group); groupToEntityDic.Add(group, new List <EntityBase>()); } }