Exemple #1
0
        public void Execute(Entity ent, int index, [ReadOnly] ref C_GridIndex Grid, ref Translation Position)
        {
            float floorY = GetStackPos(Grid.x, Grid.y, StackHeights[GridIndex(Grid.x, Grid.y)]).y;

            if (Position.Value.y > floorY)
            {
                return;
            }

            Position.Value.y = floorY;
            if (abs(Position.Value.x) > Field.x * .4f)
            {
                C_Spawner BeeSpawnData = new C_Spawner()
                {
                    Count = BeesPerResource
                };
                BeeSpawnData.Prefab = PurpleBeePrefab;
                if (Position.Value.x > 0f)
                {
                    BeeSpawnData.Prefab = YellowBeePrefab;
                }

                var localToWorld = new LocalToWorld()
                {
                    Value = float4x4(quaternion(0, 0, 0, 1), Position.Value)
                };

                var spawner = ecb.Instantiate(SpawnerPrefab);
                ecb.SetComponent(spawner, BeeSpawnData);
                ecb.SetComponent(spawner, localToWorld);

                //Spawn Smoke

                C_Spawner SmokeSpawnData = new C_Spawner()
                {
                    Count  = 5,
                    Prefab = SmokePrefab
                };

                spawner = ecb.Instantiate(SpawnerPrefab);
                ecb.SetComponent(spawner, SmokeSpawnData);
                ecb.SetComponent(spawner, localToWorld);

                ecb.DestroyEntity(ent);
            }
            else
            {
                int stackIndex = StackHeights[GridIndex(Grid.x, Grid.y)];
                if ((stackIndex + 1) * ResourceSize < Field.y)
                {
                    C_Stack stack = new C_Stack()
                    {
                        index = stackIndex
                    };

                    ecb.AddComponent(ent, stack);

                    StackHeights[GridIndex(Grid.x, Grid.y)]++;
                }
                else
                {
                    ecb.DestroyEntity(ent);
                }
            }
        }