public BaseComponent CopyComponent(BaseComponent resComponent) { if (resComponent == null) { return(null); } int entityId = resComponent.GetEntityId(); int componentId = resComponent.GetComponentId(); ECSDefine.ComponentType componentType = resComponent.GetComponentType(); BaseComponent.ComponentExpandData componentExpandData = resComponent.GetComponentExpandData(); int newComponentId = copyComponentIdDistributionChunk.Pop(); OperationObject operationObject = componentOperation.CreateOperationObject((int)componentType, newComponentId); if (operationObject == null) { Debug.LogError($"[ECSModule] CopyComponent Fail. componentType:{Enum.GetName(typeof(ECSDefine.ComponentType), componentType)}"); return(null); } BaseComponent newComponent = operationObject as BaseComponent; newComponent.SetGlobalUnionId(GlobalUnionId); newComponent.SetEntityId(entityId); newComponent.SetComponentId(componentId); newComponent.SetComponentType(componentType); newComponent.SetComponentExpandData(componentExpandData.Copy()); return(newComponent); }
public BaseComponent GetComponentByComponentType(ECSDefine.ComponentType componentType, int id = -1) { BaseComponent component = null; List <BaseComponent> componentCollection; if (componentDict.TryGetValue(componentType, out componentCollection)) { if (componentCollection.Count == 1) { component = componentCollection[0]; } else if (componentCollection.Count > 1) { for (int index = 0; index < componentCollection.Count; index++) { if (componentCollection[index].GetComponentId() == id) { component = componentCollection[index]; break; } } } } return(component); }
public BaseComponent RequireComponentControl(BaseComponent component) { ECSDefine.ComponentType componentType = component.GetComponentType(); if (synchronizationUnit.IsHingeComponentType(componentType)) { synchronizationUnit.RequireSynchroValueRep(component.GetEntityId(),component.GetComponentId(), component.GetComponentType()); component = ecsUnit.CopyComponent(component); } return component; }
public void RemoveComponent(BaseComponent component) { ECSDefine.ComponentType componentType = component.GetComponentType(); componentList.Remove(component); List <BaseComponent> componentCollection; if (componentDict.TryGetValue(componentType, out componentCollection)) { componentCollection.Remove(component); } }
public void AddNeedComponentInfo(ECSDefine.ComponentType componentType, int componentId = -1) { ComponentInfo componentInfo = ExecuteSystemUnit.PopSystemComponentInfo(); if (componentInfo != null) { componentInfo.ComponentId = componentId; componentInfo.ComponentType = componentType; componentInfoList.Add(componentInfo); } }
public void AddComponent(BaseComponent component) { ECSDefine.ComponentType componentType = component.GetComponentType(); componentList.Add(component); List <BaseComponent> componentCollection; if (!componentDict.TryGetValue(componentType, out componentCollection)) { componentCollection = new List <BaseComponent>(); componentDict.Add(componentType, componentCollection); } componentCollection.Add(component); }
public void ExecuteCacheSynchroValueRsp() { for (int index = 0; index < synchroValueRspList.Count; index++) { SynchroValueRsp synchroValueRsp = synchroValueRspList[index]; ECSDefine.ComponentType componentType = synchroValueRsp.GetComponentType(); ECSDefine.SynchroValueRspSystemType synchroValueRspSystemType; if (!ECSInstanceDefine.RequireComponentType2ExecuteSystem.TryGetValue(componentType, out synchroValueRspSystemType)) { Debug.LogError($"[SynchronizationUnit] ExecuteCacheSynchroValueRsp Fail. {Enum.GetName(typeof(ECSDefine.ComponentType), componentType)}"); continue; } SynchroValueRsp.SynchroValueRspStructure synchroValueRspStructure = synchroValueRsp.GetSynchroValueRspStructure(); executeSystemUnit.ExecuteSynchroValueRspSystem(synchroValueRspSystemType, synchroValueRspStructure); } synchroValueRspList.Clear(); }
public BaseComponent CreateComponent(int entityId, ECSDefine.ComponentType componentType, int componentId) { OperationObject operationObject = componentOperation.CreateOperationObject((int)componentType, componentId); if (operationObject == null) { Debug.LogError($"[ECSModule] CreateComponent Fail. componentType:{Enum.GetName(typeof(ECSDefine.ComponentType), componentType)}"); return(null); } BaseComponent component = operationObject as BaseComponent; component.SetGlobalUnionId(GlobalUnionId); component.SetEntityId(entityId); component.SetComponentId(componentId); component.SetComponentType(componentType); component.FillInExpandData(); return(component); }
private SynchroValueRsp SynchroValueRepToSynchroValueRsp(SynchroValueRep synchroValueRep) { int synchroValueRepId = synchroValueRep.GetSynchroValueRepId(); int synchroValueRspId = synchroValueRepId + 1; OperationObject operationObject = SynchroValueRspOperation.CreateOperationObject((int)ECSDefine.SynchronizationValueType.Response, synchroValueRspId); if (operationObject == null) { Debug.LogError("[SynchronizationUnit] SynchroValueRepToSynchroValueRsp Fail. Create SynchroValueRsp Fail"); return(null); } int entityId = synchroValueRep.GetEntityId(); int componentId = synchroValueRep.GetComponentId(); ECSDefine.ComponentType componentType = synchroValueRep.GetComponentType(); SynchroValueRsp synchroValueRsp = operationObject as SynchroValueRsp; synchroValueRsp.SetSynchroValueRspId(synchroValueRspId); synchroValueRsp.SetComponentId(componentId); synchroValueRsp.SetComponentType(componentType); synchroValueRep.SetEntityId(entityId); BaseEntity entity = ecsUnit.GetEntity(entityId); if (entity == null) { synchroValueRsp.SetIsEntityAlive(true); BaseComponent component = entity.GetComponentByComponentId(componentId); synchroValueRsp.SetIsComponentAlive(component != null); } else { synchroValueRsp.SetIsEntityAlive(false); synchroValueRsp.SetIsComponentAlive(false); } return(synchroValueRsp); }
public void RequireSynchroValueRep(int entityId, int componentId, ECSDefine.ComponentType componentType) { int reqId = synchroValueIdDistributionChunk.Pop(); ECSDefine.SynchronizationValueType synchronizationValueType = ECSDefine.SynchronizationValueType.Require; OperationObject operationObject = SynchroValueRepOperation.CreateOperationObject((int)synchronizationValueType, reqId); if (operationObject == null) { Debug.LogError($"[SynchronizationUnit] RequireComponent Fail. SynchroValueRep is nil. synchronizationValueType:{Enum.GetName(typeof(ECSDefine.SynchronizationValueType), synchronizationValueType)}"); return; } SynchroValueRep synchroValueRep = operationObject as SynchroValueRep; synchroValueRep.SetSynchroValueRepId(reqId); synchroValueRep.SetEntityId(entityId); synchroValueRep.SetComponentId(componentId); synchroValueRep.SetComponentType(componentType); synchroValueRepList.Add(synchroValueRep); }
public void SetComponentType(ECSDefine.ComponentType componentType) { synchroValueRspStructure.componentType = componentType; }
public void SetComponentType(ECSDefine.ComponentType componentType) { this.componentType = componentType; }
public bool IsHingeComponentType(ECSDefine.ComponentType componentType) { return(ECSInstanceDefine.RequireComponentType2ExecuteSystem.ContainsKey(componentType)); }
public override void Init() { ComponentId = -1; ComponentType = ECSDefine.ComponentType.Base; }
public void DeleteComponent(BaseComponent component) { ECSDefine.ComponentType componentType = component.GetComponentType(); componentOperation.DeleteOperationObject((int)componentType, component); }