protected override void OnUpdate()
        {
            var childrenBuffer = GetBufferFromEntity <Child>(true);

            Entities.With(canvasQuery).ForEach((Entity entity, CanvasSortOrder s0, DynamicBuffer <Child> b0) => {
                // Clear the list so that we can build a render hierarchy.
                batchedEntityList.Clear();

                var renderBatchEntity = PostUpdateCommands.CreateEntity(renderBatchArchetype);
                PostUpdateCommands.SetComponent(renderBatchEntity, new RenderGroupID {
                    Value = s0.Value
                });
                var buffer = PostUpdateCommands.AddBuffer <RenderElement>(renderBatchEntity);

                RecurseChildren(in b0, in childrenBuffer);

                buffer.ResizeUninitialized(batchedEntityList.Count);

                for (int i = 0; i < buffer.Length; i++)
                {
                    buffer[i] = new RenderElement {
                        Value = batchedEntityList[i]
                    };
                }

                PostUpdateCommands.RemoveComponent <DirtyTag>(entity);
            });
        }
예제 #2
0
 protected override void OnUpdate()
 {
     Entities.With(player).ForEach((Entity entity, Animator anim) => {
         PostUpdateCommands.RemoveComponent <DodgeUp>(entity);
         anim.SetTrigger("DodgeUp");
     });
 }
예제 #3
0
    protected override void OnUpdate()
    {
        Entities.ForEach((Entity unitEntity, ref HasTarget hasTarget, ref Translation translation, ref LocalToWorld localToWorld) =>
        {
            if (World.DefaultGameObjectInjectionWorld.EntityManager.Exists(hasTarget.TargetEntity))
            {
                Translation targetTranslation =
                    World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <Translation>(
                        hasTarget.TargetEntity);
                LocalToWorld targetLocalToWorld =
                    World.DefaultGameObjectInjectionWorld.EntityManager.GetComponentData <LocalToWorld>(
                        hasTarget.TargetEntity);

                float3 targetDirection = math.normalize(targetTranslation.Value - translation.Value);
                float moveSpeed        = 10f;
                translation.Value     += targetDirection * moveSpeed * Time.DeltaTime;


                // If are Unit if close to the target, destroy it
                if (math.distance(translation.Value, targetTranslation.Value) < .2f)
                {
                    PostUpdateCommands.DestroyEntity(hasTarget.TargetEntity);
                    PostUpdateCommands.RemoveComponent(unitEntity, typeof(HasTarget));
                }
            }
            else
            {
                PostUpdateCommands.RemoveComponent(unitEntity, typeof(HasTarget));
            }
        });
    }
예제 #4
0
        protected override void OnUpdate()
        {
            Entities.WithNone <State>().ForEach((Entity entity, ref RegistryAsset registryAsset) =>
            {
                GameDebug.Log(World, Part.ShowLifetime, "Initializing PartOwner:{0}", entity);

                var registry      = PartRegistry.GetPartRegistry(World, registryAsset.Value);
                var categoryCount = registry.Value.GetCategoryCount();

                var buffer = PostUpdateCommands.AddBuffer <PartElement>(entity);
                for (int i = 0; i < categoryCount; i++)
                {
                    buffer.Add(PartElement.Default);
                }

                PostUpdateCommands.AddComponent(entity, State.Default);
            });

            Entities.WithNone <InputState>().ForEach((Entity entity, ref State state) =>
            {
                GameDebug.Log(World, Part.ShowLifetime, "Deinitializing PartOwner:{0}", entity);

                var partBuffer = EntityManager.GetBuffer <PartElement>(entity);
                for (int i = 0; i < partBuffer.Length; i++)
                {
                    if (partBuffer[i].PartEntity != Entity.Null)
                    {
                        PostUpdateCommands.DestroyEntity(partBuffer[i].PartEntity);
                        GameDebug.Log(Part.ShowLifetime, "   destroying part:{0}", partBuffer[i].PartEntity);
                    }
                }
                PostUpdateCommands.RemoveComponent <State>(entity);
                PostUpdateCommands.RemoveComponent <PartElement>(entity);
            });
        }
    private void NetworkManager_OnDisconnect()
    {
        ComponentGroup group = GetComponentGroup(ComponentType.Create <NetworkSyncState>(), ComponentType.Create <NetworkSync>());
        ComponentDataArray <NetworkSyncState> networkSyncStateComponents = group.GetComponentDataArray <NetworkSyncState>();
        ComponentDataArray <NetworkSync>      networkSyncComponents      = group.GetComponentDataArray <NetworkSync>();
        EntityArray entities = group.GetEntityArray();

        for (int i = 0; i < entities.Length; i++)
        {
            Entity entity = entities[i];
            PostUpdateCommands.RemoveComponent <NetworkSyncState>(entity);
            if (networkSyncStateComponents[i].actorId != networkManager.LocalPlayerID && networkSyncComponents[i].authority != Authority.Scene)
            {
                PostUpdateCommands.DestroyEntity(entity);
                if (EntityManager.HasComponent <Transform>(entity))
                {
                    gameObjectsToDestroy.Add(EntityManager.GetComponentObject <Transform>(entity).gameObject);
                }
            }
            else if (EntityManager.HasComponent <NetworktAuthority>(entity))
            {
                PostUpdateCommands.RemoveComponent <NetworktAuthority>(entity);
            }
            for (int j = 0; j < RemoveComponentOnDestroyEntityMethods.Count; j++)
            {
                RemoveComponentOnDestroyEntityMethods[j].Invoke(this, entity);
            }
        }
    }
예제 #6
0
    protected override void OnUpdate()
    {
        for (var i = 0; i < Group.abilityControllers.Length; i++)
        {
            var abilityCtrl = Group.abilityControllers[i];
            if (abilityCtrl.abilityEntities == null)
            {
                continue;
            }

            var abilityCtrlEntity = Group.entities[i];

            var predicted = EntityManager.HasComponent <ServerEntity>(abilityCtrlEntity);
            for (var j = 0; j < abilityCtrl.abilityEntities.Length; j++)
            {
                var ability = abilityCtrl.abilityEntities[j];
                if (ability == Entity.Null)
                {
                    continue;
                }

                if (EntityManager.HasComponent <ServerEntity>(ability) != predicted)
                {
                    if (predicted)
                    {
                        PostUpdateCommands.AddComponent(ability, new ServerEntity());
                    }
                    else
                    {
                        PostUpdateCommands.RemoveComponent <ServerEntity>(ability);
                    }
                }
            }
        }
    }
        protected override void OnUpdate()
        {
            for (var i = 0; i < addedEntitiesData.Length; i++)
            {
                var entity          = addedEntitiesData.Entities[i];
                var spatialEntityId = addedEntitiesData.SpatialEntityIds[i].EntityId;
                var gameObject      = gameObjectCreator.OnEntityCreated(new SpatialOSEntity(entity, EntityManager));
                PostUpdateCommands.AddComponent(entity, new InitializedEntitySystemState {
                    EntityId = spatialEntityId
                });
                if (gameObject == null)
                {
                    continue;
                }

                linkerSystem.Linker.LinkGameObjectToEntity(gameObject, entity, viewCommandBuffer);
                entityToGameObjects.Add(entity, gameObject);
            }

            for (var i = 0; i < removedEntitiesData.Length; i++)
            {
                var entity          = removedEntitiesData.Entities[i];
                var spatialEntityId = EntityManager.GetComponentData <InitializedEntitySystemState>(entity).EntityId;
                if (entityToGameObjects.TryGetValue(entity, out var gameObject))
                {
                    linkerSystem.Linker.UnlinkGameObjectFromEntity(gameObject, entity, viewCommandBuffer);
                }

                gameObjectCreator.OnEntityRemoved(spatialEntityId, gameObject);
                entityToGameObjects.Remove(entity);
                PostUpdateCommands.RemoveComponent <InitializedEntitySystemState>(entity);
            }

            viewCommandBuffer.FlushBuffer();
        }
예제 #8
0
    protected override void OnUpdate()
    {
        var isShooting = Input.GetMouseButton(0);

        if (isShooting)
        {
            Entities.WithAllReadOnly <PlayerMarker, AimingMarker>().WithNone <Shooting>().ForEach((Entity entity, ref Gun gun) =>
            {
                PostUpdateCommands.AddComponent(entity, new Shooting {
                    Gun = gun
                });
            });

            Entities.WithAllReadOnly <PlayerMarker, Shooting>().WithNone <AimingMarker>().ForEach((Entity entity) =>
            {
                PostUpdateCommands.RemoveComponent <Shooting>(entity);
            });
        }
        else
        {
            Entities.WithAllReadOnly <PlayerMarker, Shooting>().ForEach((Entity entity) =>
            {
                PostUpdateCommands.RemoveComponent <Shooting>(entity);
            });
        }
    }
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity entity, ref InitialDeploy deploy, ref Translation translation, ref Rotation rotation) =>
            {
                float3 randomPosition = new float3(m_Random.NextFloat(-k_Width, k_Width), 0f, m_Random.NextFloat(-k_Height, k_Height));

                float zOffset = 6f;
                if (deploy.FleetID == 1)
                {
                    zOffset = -zOffset;
                }
                else
                {
                    rotation.Value = math.mul(rotation.Value, quaternion.AxisAngle(math.up(), math.radians(180f)));
                }

                randomPosition.z = (randomPosition.z * 0.1f) + zOffset;

                float3 startingPosition = randomPosition;
                startingPosition.z     += zOffset;

                translation.Value = startingPosition;

                PostUpdateCommands.AddComponent(entity, new DeployToPosition()
                {
                    Position = randomPosition, ShouldStop = true
                });
                PostUpdateCommands.RemoveComponent <InitialDeploy>(entity);
            });
        }
예제 #10
0
        /// <summary>
        /// Updates all new entity positions after scene loading
        /// </summary>
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity e, ref IsNewEntity newEntity, ref Translation t) =>
            {
                switch (newEntity.translationType)
                {
                case TranslationType.Position:
                    t.Value.x = newEntity.pos.x;
                    t.Value.y = newEntity.pos.y;
                    break;

                case TranslationType.Offset:
                    t.Value.x += newEntity.offset.x;
                    t.Value.y += newEntity.offset.y;
                    break;

                case TranslationType.PositionAndOffset:
                    t.Value.x  = newEntity.pos.x;
                    t.Value.y  = newEntity.pos.y;
                    t.Value.x += newEntity.offset.x;
                    t.Value.y += newEntity.offset.y;
                    break;

                case TranslationType.None:
                    break;

                default:
                    break;
                }
                Debug.Log("POSITION: " + t.Value);

                PostUpdateCommands.RemoveComponent <IsNewEntity>(e);
            });
        }
예제 #11
0
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity entity, ref StartClickingEventComp startClickingEvent) =>
            {
                if (!startClickingEvent.HasWaitedOneFrameBeforeRemoval)
                {
                    startClickingEvent.HasWaitedOneFrameBeforeRemoval = true;
                }
                else
                {
                    PostUpdateCommands.RemoveComponent(entity, typeof(StartClickingEventComp));
                }
            });

            Entities.ForEach((Entity entity, ref StopClickingEventComp stopClickingEvent) =>
            {
                if (!stopClickingEvent.HasWaitedOneFrameBeforeRemoval)
                {
                    stopClickingEvent.HasWaitedOneFrameBeforeRemoval = true;
                }
                else
                {
                    PostUpdateCommands.RemoveComponent(entity, typeof(StopClickingEventComp));
                }
            });
        }
예제 #12
0
    protected override void OnUpdate()
    {
        Entities.ForEach((Entity unitEntity, ref HasTarget hasTarget, ref Translation translation) => {
            if (World.Active.EntityManager.Exists(hasTarget.targetEntity))
            {
                Translation targetTranslation = World.Active.EntityManager.GetComponentData <Translation>(hasTarget.targetEntity);

                float3 targetDir   = math.normalize(targetTranslation.Value - translation.Value);
                float moveSpeed    = 5f;
                translation.Value += targetDir * moveSpeed * Time.deltaTime;

                if (math.distance(translation.Value, targetTranslation.Value) < .2f)
                {
                    // Close to target, destroy it
                    PostUpdateCommands.DestroyEntity(hasTarget.targetEntity);
                    PostUpdateCommands.RemoveComponent(unitEntity, typeof(HasTarget));
                }
            }
            else
            {
                // Target Entity already destroyed
                PostUpdateCommands.RemoveComponent(unitEntity, typeof(HasTarget));
            }
        });
    }
예제 #13
0
        protected override void OnUpdate()
        {
            Entities.With(_dealDamageQuery).ForEach((Entity entity, ref DealDamage dealDamage, ref Health health) =>
            {
                health.value -= dealDamage.damage;
                PostUpdateCommands.RemoveComponent <DealDamage>(entity);

                if (HasSingleton <AllowTimeFade>() == false)
                {
                    PostUpdateCommands.CreateEntity(EntityManager.CreateArchetype(ComponentType.ReadWrite <AllowTimeFade>()));
                }
            });

            if (HasSingleton <AllowTimeFade>())
            {
                Entities.WithAll <TimeFadeValue, TimeFadeClock>().ForEach((TimeFadeValue timeFadeValue, ref TimeFadeClock timeFadeClock) =>
                {
                    var curve = timeFadeValue.value;
                    UnityEngine.Time.timeScale = curve.Evaluate(timeFadeClock.time);
                    if (timeFadeClock.time > curve[curve.length - 1].time)
                    {
                        timeFadeClock.time = curve[0].time;
                        PostUpdateCommands.DestroyEntity(GetSingletonEntity <TimeFadeValue>());
                    }

                    timeFadeClock.time += UnityEngine.Time.unscaledDeltaTime;
                });
            }
        }
예제 #14
0
    protected override void OnUpdate()
    {
        EntityManager entityManager = World.DefaultGameObjectInjectionWorld.EntityManager;

        float deltaTime = Time.DeltaTime;

        Entities.ForEach((Entity playerEntity, ref Translation playerTranslation, ref SpeedData speedData, ref PlayerTag playerTag, ref HasTarget hasTarget) =>
        {
            if (CameraFollow.instance.playerEntity == Entity.Null)
            {
                CameraFollow.instance.playerEntity = playerEntity;
            }

            if (entityManager.Exists(hasTarget.targetEntity))
            {
                Translation targetTranslation = entityManager.GetComponentData <Translation>(hasTarget.targetEntity);
                float3 targetDir         = math.normalize(targetTranslation.Value - playerTranslation.Value);
                playerTranslation.Value += targetDir * speedData.speed * deltaTime;

                if (math.distance(playerTranslation.Value, targetTranslation.Value) < .2f)
                {
                    // Close to target, destroy it
                    PostUpdateCommands.DestroyEntity(hasTarget.targetEntity);
                    PostUpdateCommands.RemoveComponent(playerEntity, typeof(HasTarget));
                }
            }
            else
            {
                // Target Entity already destroyed
                PostUpdateCommands.RemoveComponent(playerEntity, typeof(HasTarget));
            }
        });
    }
예제 #15
0
    protected override void OnUpdate()
    {
        int2 gridSize = new int2(WorldManager.MapWorld.regionSize, WorldManager.MapWorld.regionSize);

        NativeList <JobHandle> jobHandles = new NativeList <JobHandle>(Allocator.Temp);

        Entities.ForEach((Entity entity, DynamicBuffer <PathfindingRoute> pathRoute, ref PathfindingParams pathfindingParams) => {
            List <MapGrowth> mapGrowths        = WorldManager.MapWorld.GetMapGrowths(pathfindingParams.growthCode);
            NativeArray <int2> targetLocations = new NativeArray <int2>(GetAllTargetsFromGrowth(mapGrowths), Allocator.TempJob);

            PathFinderJob pathfinderJob = new PathFinderJob {
                pathfindingType = pathfindingParams.pathfindingType,
                positionStart   = pathfindingParams.startPosition,
                positionEnd     = pathfindingParams.endPosition,
                gridSize        = gridSize,
                entity          = entity,
                routeFollow     = GetComponentDataFromEntity <PathfindingRouteFollow>(),
                pathRoute       = pathRoute,
                pathNodes       = WorldManager.PathNodesNA,
                targets         = targetLocations
            };

            jobHandles.Add(pathfinderJob.Schedule());

            PostUpdateCommands.RemoveComponent <PathfindingParams>(entity);
        });

        JobHandle.CompleteAll(jobHandles);
    }
    private void MoveSelected(int2 coord, EntityManager entityManager)
    {
        var entities = _selectedQuery.ToEntityArray(Allocator.TempJob);

        for (var index = 0; index < entities.Length; index++)
        {
            Entity entity = entities[index];

            if (entityManager.HasComponent <Path>(entity))
            {
                PostUpdateCommands.RemoveComponent <Path>(entity);
            }

            if (!entityManager.HasComponent <MoveTo>(entity))
            {
                PostUpdateCommands.AddComponent <MoveTo>(entity);
            }

            PostUpdateCommands.SetComponent(entity, new MoveTo
            {
                Coord = coord
            });
        }

        entities.Dispose();
    }
예제 #17
0
 protected override void OnUpdate()
 {
     actionQueue = GetEntityQuery(typeof(Action), typeof(Move), typeof(BoardPosition));
     if (actionQueue.CalculateLength() == 1)
     {
         cellQueue = GetEntityQuery(cellQuery);
         var actor = actionQueue.ToEntityArray(Allocator.TempJob);
         PostUpdateCommands.RemoveComponent <UnitAnimation>(actor[0]);
         var position    = actionQueue.ToComponentDataArray <BoardPosition>(Allocator.TempJob);
         var move        = actionQueue.ToComponentDataArray <Move>(Allocator.TempJob);
         var cells       = cellQueue.ToComponentDataArray <Cell>(Allocator.TempJob);
         var entityCells = cellQueue.ToEntityArray(Allocator.TempJob);
         for (int i = 0; i < cells.Length; i++)
         {
             if (MovePatterns.chooseType(move[0].index, position[0].cell, cells[i].number))
             {
                 PostUpdateCommands.AddComponent(entityCells[i], new AvailableCell()
                 {
                 });
             }
             if (EntityManager.HasComponent <Water>(entityCells[i]) && EntityManager.HasComponent <FishTail>(actor[0]))
             {
                 PostUpdateCommands.AddComponent(entityCells[i], new AvailableCell()
                 {
                 });
             }
         }
         position.Dispose();
         move.Dispose();
         cells.Dispose();
         actor.Dispose();
         entityCells.Dispose();
     }
 }
예제 #18
0
        protected override void OnUpdate()
        {
            // Initialize
            Entities.WithNone <Initialized>().WithAll <Base>().ForEach((Entity entity, ref RigDefinitionSetup rigDefSetup) =>
            {
                // TODO (mogensh) make this an option. If we remap content to another rigentity we dont want to update rig here
                RigEntityBuilder.SetupRigEntity(entity, EntityManager, rigDefSetup.Value);
                if (EntityManager.HasComponent <SkinnedMeshRenderer>(entity))
                {
                    var animatedSkinMatricesArray = EntityManager.AddBuffer <AnimatedLocalToRig>(entity);
                    animatedSkinMatricesArray.ResizeUninitialized(rigDefSetup.Value.Value.Skeleton.BoneCount);
                }

                EntityManager.SetSharedComponentData(entity, new SharedRigDefinition {
                    Value = rigDefSetup.Value
                });

                PostUpdateCommands.AddComponent(entity, new Initialized());
            });

            // Deinitialize
            Entities.WithNone <Base>().WithAll <Initialized>().ForEach((Entity entity) =>
            {
                PostUpdateCommands.RemoveComponent <Initialized>(entity);
            });
        }
예제 #19
0
    private void RemovedEntities()
    {
        EntityArray entities = removedSyncEntities.entities;
        ComponentDataArray <NetworkSyncState> networkSyncs = removedSyncEntities.networkSyncStateComponents;

        for (int i = 0; i < entities.Length; i++)
        {
            NetworkSyncState component = new NetworkSyncState()
            {
                actorId   = networkManager.LocalPlayerID,
                networkId = networkManager.GetNetworkId(),
            };
            PostUpdateCommands.RemoveComponent <NetworkSyncState>(entities[i]);
            for (int j = 0; j < RemoveComponentOnDestroyEntityMethods.Count; j++)
            {
                RemoveComponentOnDestroyEntityMethods[j].Invoke(this, entities[i]);
            }

            NetworkSyncEntity networkSyncEntity = new NetworkSyncEntity {
                ActorId   = component.actorId,
                NetworkId = component.networkId,
            };
            ownNetworkSendMessageUtility.RemoveEntity(networkSyncEntity);
            AllNetworkSendMessageUtility.RemoveEntity(networkSyncEntity);
        }
    }
    protected override void OnUpdate()
    {
        Entities.WithAll <PlayerComponent>().ForEach((Entity id) => { }); // weirdness

        // remove token
        Entities.WithAll <ReadyToHandleFlag>().ForEach((Entity id) =>
        {
            PostUpdateCommands.RemoveComponent <ReadyToHandleFlag>(id);
        });
        // query for waiting
        var waiting = Entities.WithAll <AwaitActionFlag>().ToEntityQuery().CalculateEntityCount();

        // if 0 waiting hand out tokens, refresh awaiting
        if (waiting == 0)
        {
            Entities.WithAll <ActorComponent>().ForEach((Entity id) =>
            {
                PostUpdateCommands.AddComponent <ReadyToHandleFlag>(id);
            });

            Entities.WithAll <PlayerComponent>().ForEach((Entity id) =>
            {
                PostUpdateCommands.AddComponent <AwaitActionFlag>(id);
            });
        }
    }
예제 #21
0
        protected override void OnUpdate()
        {
            var b_entity   = boost.GetEntityArray();
            var b_timer    = boost.GetComponentDataArray <Boosting>();
            var b_cooldown = boost.GetComponentDataArray <BoostCooldown>();

            for (int i = 0; i < boost.CalculateLength(); i++)
            {
                if (b_timer[i].Value > 0)
                {
                    continue;
                }

                PostUpdateCommands.RemoveComponent <Boosting>(b_entity[i]);
                PostUpdateCommands.AddComponent <BoostEnd>(
                    b_entity[i],
                    new BoostEnd {
                    Value = b_cooldown[i].Value
                }
                    );


                /* ----------------- DEVELOPER SETTINGS - REMOVE ME -------------------- */
                if (Bootstrap.DeveloperSettings.DebugBoostState)
                {
                    Debug.Log($"<color=green>{this.GetType()}</color> BoostEnd");
                }
                /* ----------------- DEVELOPER SETTINGS - REMOVE ME -------------------- */
            }
        }
예제 #22
0
        protected override void OnUpdate()
        {
            Entities.ForEach((Entity e, ref FlyDirection direction, ref TouchpadInputCapture tic, ref InteractionThumbPosition itp, ref BaseInputCapture bic, ref ControllersInteractionType cit) =>
            {
                // If user just started to press/touch the thumbstick
                if (InteractionChecker.IsInteractingTouchpad(bic, cit, itp, tic, true, false))
                {
                    direction.FlightDirection = tic.ThumbPosition.y;

                    if (!EntityManager.HasComponent(e, typeof(IsFlying)))
                    {
                        PostUpdateCommands.AddComponent(e, new IsFlying());
                    }
                    if (EntityManager.HasComponent(e, typeof(IsDecelerating)))
                    {
                        PostUpdateCommands.RemoveComponent <IsDecelerating>(e);
                    }
                }
                else if (EntityManager.HasComponent(e, typeof(IsFlying)))
                {
                    PostUpdateCommands.RemoveComponent <IsFlying>(e);
                    PostUpdateCommands.AddComponent(e, new IsDecelerating());
                }
            });
        }
예제 #23
0
    protected override void OnUpdate()
    {
        float dt       = Time.deltaTime;
        var   settings = Bootstrap.Settings;

        for (int i = 0; i < timerData.Length; i++)
        {
            var timer = timerData.Timer[i];

            timer.CurrentTime += dt;

            if (timer.CurrentTime >= timer.Duration)
            {
                if (timer.DeleteOnEnd)
                {
                    PostUpdateCommands.DestroyEntity(timerData.Entities[i]);
                }
                else
                {
                    PostUpdateCommands.RemoveComponent <TimerComponent>(timerData.Entities[i]);
                }
            }
            timerData.Timer[i] = timer;
        }
    }
예제 #24
0
        protected override void OnUpdate()
        {
            Profiler.BeginSample("CreateActivationManagerAndReaderWriterStore");
            for (var i = 0; i < addedEntitiesData.Length; i++)
            {
                var entity = addedEntitiesData.Entities[i];
                CreateActivationManagerAndReaderWriterStore(entity);
                PostUpdateCommands.AddComponent(entity, new HasActivationManagerSystemState());
            }

            Profiler.EndSample();

            Profiler.BeginSample("RemoveActivationManagerAndReaderWriterStore");
            for (var i = 0; i < removedEntitiesData.Length; i++)
            {
                var entity = removedEntitiesData.Entities[i];
                RemoveActivationManagerAndReaderWriterStore(entity);
                PostUpdateCommands.RemoveComponent <HasActivationManagerSystemState>(entity);
            }

            Profiler.EndSample();

            Profiler.BeginSample("UpdateMonoBehaviours");
            UpdateMonoBehaviours();
            Profiler.EndSample();
        }
    private void NetworkManager_OnMasterClientChanged(int oldMasterClientId, int newMasterClientId)
    {
        if (networkManager.LocalPlayerID == oldMasterClientId)
        {
            ComponentGroup group    = GetComponentGroup(ComponentType.Create <NetworkSyncState>(), ComponentType.Create <NetworkSync>(), ComponentType.Create <NetworktAuthority>());
            EntityArray    entities = group.GetEntityArray();
            ComponentDataArray <NetworkSync> networkSync = group.GetComponentDataArray <NetworkSync>();
            for (int i = 0; i < entities.Length; i++)
            {
                if (networkSync[i].authority != Authority.Client)
                {
                    PostUpdateCommands.RemoveComponent <NetworktAuthority>(entities[i]);
                }
            }
        }

        if (networkManager.LocalPlayerID == newMasterClientId)
        {
            ComponentGroup group = GetComponentGroup(ComponentType.Create <NetworkSyncState>(), ComponentType.Create <NetworkSync>(), ComponentType.Subtractive <NetworktAuthority>());
            ComponentDataArray <NetworkSync> networkSync = group.GetComponentDataArray <NetworkSync>();
            EntityArray entities = group.GetEntityArray();
            for (int i = 0; i < entities.Length; i++)
            {
                if (networkSync[i].authority != Authority.Client)
                {
                    PostUpdateCommands.AddComponent(entities[i], new NetworktAuthority());
                }
            }
        }
    }
    protected override void OnUpdate()
    {
        var dT = Time.deltaTime;

        for (int i = 0; i < m_Data.Length; i++)
        {
            var gameObject = m_Data.GameObject[i];
            var dead       = m_Data.Dead[i];
            var e          = m_Data.Entities[i];
            if (EntityManager.HasComponent <TargetableComponent>(e))
            {
                PostUpdateCommands.RemoveComponent <TargetableComponent>(e);
            }
            dead.Timer -= dT;
            gameObject.transform.Rotate(75 * dT, 0, 0);
            if (dead.Timer <= 0)
            {
                PostUpdateCommands.AddComponent(e, new Destroy());
            }
            else
            {
                EntityManager.SetComponentData <DeadComponent>(e, dead);
            }
        }
    }
예제 #27
0
        protected override void OnUpdate()
        {
            float time = Time.deltaTime;
            var   em   = World.Active.EntityManager;

            Entities.WithAll <NPCTag>().ForEach((Entity npc, ref Translation tr, ref HasTarget hasTarget, ref SpeedComponent speed) =>
            {
                if (!em.Exists(hasTarget.Target))
                {
                    PostUpdateCommands.RemoveComponent(npc, typeof(HasTarget));
                    return;
                }
                float3 targetPosition =
                    em.GetComponentData <Translation>(hasTarget.Target).Value;

                float3 direction = targetPosition - tr.Value;
                float3 move      = math.normalize(direction) * speed.Speed * time;
                if (math.length(move) >= math.length(direction))
                {
                    tr.Value = targetPosition;
                    PostUpdateCommands.RemoveComponent(npc, typeof(HasTarget));
                    PostUpdateCommands.DestroyEntity(hasTarget.Target);
                }
                else
                {
                    tr.Value += move;
                }
            });
        }
예제 #28
0
 private void RemoveIfHasPrefab(Entity entity)
 {
     if (EntityManager.HasComponent <Prefab>(entity))
     {
         PostUpdateCommands.RemoveComponent <Prefab>(entity);
     }
 }
예제 #29
0
        protected override void OnUpdate()
        {
            var entityType = GetArchetypeChunkEntityType();

            var createEntityType     = GetArchetypeChunkComponentType <WorldCommands.CreateEntity.CommandResponses>();
            var deleteEntityType     = GetArchetypeChunkComponentType <WorldCommands.DeleteEntity.CommandResponses>();
            var reserveEntityIdsType =
                GetArchetypeChunkComponentType <WorldCommands.ReserveEntityIds.CommandResponses>();
            var entityQueryType = GetArchetypeChunkComponentType <WorldCommands.EntityQuery.CommandResponses>();

            var chunkArray = worldCommandResponseGroup.CreateArchetypeChunkArray(Allocator.TempJob);

            foreach (var chunk in chunkArray)
            {
                var entityArray = chunk.GetNativeArray(entityType);

                if (chunk.Has(createEntityType))
                {
                    var responseArray = chunk.GetNativeArray(createEntityType);
                    for (var i = 0; i < entityArray.Length; i++)
                    {
                        WorldCommands.CreateEntity.ResponsesProvider.Free(responseArray[i].Handle);
                        PostUpdateCommands.RemoveComponent <WorldCommands.CreateEntity.CommandResponses>(entityArray[i]);
                    }
                }

                if (chunk.Has(deleteEntityType))
                {
                    var responseArray = chunk.GetNativeArray(deleteEntityType);
                    for (var i = 0; i < entityArray.Length; i++)
                    {
                        WorldCommands.DeleteEntity.ResponsesProvider.Free(responseArray[i].Handle);
                        PostUpdateCommands.RemoveComponent <WorldCommands.DeleteEntity.CommandResponses>(entityArray[i]);
                    }
                }

                if (chunk.Has(reserveEntityIdsType))
                {
                    var responseArray = chunk.GetNativeArray(reserveEntityIdsType);
                    for (var i = 0; i < entityArray.Length; i++)
                    {
                        WorldCommands.ReserveEntityIds.ResponsesProvider.Free(responseArray[i].Handle);
                        PostUpdateCommands.RemoveComponent <WorldCommands.ReserveEntityIds.CommandResponses>(
                            entityArray[i]);
                    }
                }

                if (chunk.Has(entityQueryType))
                {
                    var responseArray = chunk.GetNativeArray(entityQueryType);
                    for (var i = 0; i < entityArray.Length; i++)
                    {
                        WorldCommands.EntityQuery.ResponsesProvider.Free(responseArray[i].Handle);
                        PostUpdateCommands.RemoveComponent <WorldCommands.EntityQuery.CommandResponses>(entityArray[i]);
                    }
                }
            }

            chunkArray.Dispose();
        }
예제 #30
0
    protected override void OnUpdate()
    {
        for (int i = 0; i < data.Length; ++i)
        {
            int currentHealth = data.healths[i].value;
            int dame          = data.damages[i].value;
            int newHealth     = currentHealth - dame;

            if (newHealth <= 0)
            {
                PostUpdateCommands.AddComponent(data.entities[i], new Dead()
                {
                    value = 0
                });
                GameUI.Instance.OnKillEnemy();
                continue;
            }

            ParticleSystem hitParticle = data.gameObjects[i].GetComponentInChildren <ParticleSystem>();
            hitParticle.transform.position = data.damages[i].hitPoint;
            hitParticle.Play();

            data.healths[i] = new Health()
            {
                value = newHealth
            };
            PostUpdateCommands.RemoveComponent <Damage>(data.entities[i]);
        }
    }