Пример #1
0
 protected override void OnUpdate()
 {
     ForEach((Transform transform) =>
     {
         GameObjectEntity.CopyAllComponentsToEntity(transform.gameObject, DstEntityManager, GetPrimaryEntity(transform));
     });
 }
Пример #2
0
    public void CreateECSEntity(NetworkObject pObj)
    {
        if (_entityManager == null ||
            pObj.CreateCode < 0 ||
            pObj.CreateCode >= _prefabEntityArchetypes.Length ||
            _prefabEntityArchetypes[pObj.CreateCode] == null)
        {
            return;
        }

        //If the NetworkObject implements IECSNetworkObject an Entity can be created and be associated with it.
        IECSNetworkObject ecsObj = pObj as IECSNetworkObject;

        if (ecsObj != null)
        {
            //Note: this is currently a hack since essential functions are being kept internal as of 08/02/2019
            Entity entity = _entityManager.CreateEntity();
            GameObjectEntity.CopyAllComponentsToEntity(_prefabEntityArchetypes[pObj.CreateCode], _entityManager, entity);

            //Associate the NetworkObject with the Entity
            ecsObj.AttachedEntity  = entity;
            ecsObj.AttachedManager = this;
            ecsObj.RegisterComponents();

            _entityManager.AddComponent <NetworkObjectComponent>(entity);
            _entityManager.SetComponentData <NetworkObjectComponent>(
                entity,
                new NetworkObjectComponent()
            {
                networkId = pObj.NetworkId,
                identity  = pObj.UniqueIdentity,
                isOwner   = pObj.IsOwner,
                isServer  = pObj.IsServer
            });
        }
    }