Пример #1
0
    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);
    }
Пример #2
0
    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;
    }
Пример #4
0
    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);
        }
    }
Пример #5
0
    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);
        }
    }
Пример #6
0
    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);
    }
Пример #7
0
    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();
    }
Пример #8
0
    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);
    }
Пример #9
0
    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);
    }
Пример #10
0
    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);
    }
Пример #11
0
 public void SetComponentType(ECSDefine.ComponentType componentType)
 {
     synchroValueRspStructure.componentType = componentType;
 }
Пример #12
0
 public void SetComponentType(ECSDefine.ComponentType componentType)
 {
     this.componentType = componentType;
 }
Пример #13
0
 public bool IsHingeComponentType(ECSDefine.ComponentType componentType)
 {
     return(ECSInstanceDefine.RequireComponentType2ExecuteSystem.ContainsKey(componentType));
 }
Пример #14
0
 public override void Init()
 {
     ComponentId   = -1;
     ComponentType = ECSDefine.ComponentType.Base;
 }
Пример #15
0
 public void DeleteComponent(BaseComponent component)
 {
     ECSDefine.ComponentType componentType = component.GetComponentType();
     componentOperation.DeleteOperationObject((int)componentType, component);
 }