Beispiel #1
0
        /// <summary>
        /// this is where the actual logic of the job is held and carried out, such as the example spawning the game objects
        /// </summary>
        /// <param name="entity">the entity that needs the job done</param>
        /// <param name="index"> the index of the job itself</param>
        /// <param name="testEntity">the component matching the first entity type specified</param>
        /// <param name="location">the component matching the second entity type specified</param>
        public void Execute(Entity entity, int index, [ReadOnly] ref TestEntity testEntity, [ReadOnly] ref LocalToWorld location)
        {
            SpawnerPos = location.Position;
            for (var x = 0; x < testEntity.CountX; x++)
            {
                for (var y = 0; y < testEntity.CountY; y++)
                {
                    for (var z = 0; z < testEntity.CountZ; z++)
                    {
                        var instance = CommandBuffer.Instantiate(index, testEntity.PrefabObject);


                        // Place the instantiated in a grid with some noise
                        float angle = RandomCache.GetAngle();

                        float xpos = SpawnerPos.x + Mathf.Sin(angle) * RandomCache.GetCenterDistance();
                        float zpos = SpawnerPos.z + Mathf.Cos(angle) * RandomCache.GetCenterDistance();

                        var position = math.transform(location.Value,
                                                      new float3(xpos, 2 * y / testEntity.CountY, zpos));

                        CommandBuffer.SetComponent(index, instance, new Translation {
                            Value = position
                        });
                        //the +1 is to account for the fact that the upper limit is exclusive

                        //this one doesn't use the cache to allow the number of random blocks to vary more
                        uint BlockType = RandomCache.GetCubeType();
                        if (BlockType == 1)
                        {
                            CommandBuffer.AddComponent(index, instance, new MoveUp(RandomCache.GetLifeSpan()));
                        }
                        else
                        {
                            CommandBuffer.AddComponent(index, instance,
                                                       new MoveRandom(RandomCache.GetLifeSpan(), GetRandComponentfloat3()));
                        }

                        CommandBuffer.AddComponent(index, instance, new MovingCube());
                    }
                }
            }

            ///uncommenting this line means the entity that runs this job is deleted, so the above line won't happen every frame
            CommandBuffer.DestroyEntity(index, entity);
        }
        public void Execute(Entity entity, int index, ref Translation translation)
        {
            float angle = RandomCache.GetAngle();
            float newX  = SpawnerSystem.SpawnerPos.x + Mathf.Sin(angle) * RandomCache.GetCenterDistance();
            float newZ  = SpawnerSystem.SpawnerPos.z + Mathf.Cos(angle) * RandomCache.GetCenterDistance();

            translation.Value = new float3(newX, SpawnerSystem.SpawnerPos.y, newZ);
            CommandBuffer.RemoveComponent <ResetCube>(index, entity);
            uint BlockType = RandomCache.GetCubeType();

            if (BlockType == 1)
            {
                CommandBuffer.AddComponent(index, entity, new MoveUp(RandomCache.GetLifeSpan()));
            }
            else
            {
                CommandBuffer.AddComponent(index, entity, new MoveRandom(RandomCache.GetLifeSpan(), SpawnerSystem.GetRandComponentfloat3()));
            }
        }