Пример #1
0
    private void SpawnEnemyGameObjects()
    {
        List <GameObject> spawners = new List <GameObject>();

        Tile.PositionOnGrid flags =
            (
                Tile.PositionOnGrid.TopLeftCorner |
                Tile.PositionOnGrid.TopRightCorner |
                Tile.PositionOnGrid.BottomLeftCorner |
                Tile.PositionOnGrid.BottomRightCorner
            );
        IEnumerable <Enum> flagValues = flags.GetIndividualFlags();

        foreach (Enum value in flagValues)
        {
            spawners.Add(
                assetSpawner.SpawnAssetGeneric(
                    mapGenerator.Grid,
                    assets.EnemySpawner,
                    assets.EnemySpawner.name,
                    (Tile.PositionOnGrid)value
                    ));
        }

        foreach (GameObject go in spawners)
        {
            go.GetComponent <SpawnAgentOverTime>().Init(assetSpawner, go.transform.parent.GetComponent <Tile>());
        }
    }
    internal virtual void SpawnEnemy()
    {
        if (currentTile == null)
        {
            return;
        }
        if (assetSpawner == null)
        {
            return;
        }

        try
        {
            GameObject go = assetSpawner.SpawnAssetGeneric(
                asset: agentToSpawn,                            //the agent we want to spawn into the world
                assetName: agentToSpawn.name,                   //the name of the agent, e.g: skeleton
                t: currentTile,                                 //the current tile the thing this is attached to is on
                spawnOntoRandomTileNeighbour: true              //whether we want this object to spawn automagically onto a randomly selected neighbour tile
                );

            if (!go.CompareTag("Enemy"))
            {
                go.tag = "Enemy";
            }
            Tile goT = go.GetComponent <Tile>();
            goT.Type = Tile.TileType.Enemy;
            Agents.Agent      spawnedAgent = go.GetComponent <Agents.Agent>();
            AISuperSimpleMove aiMover      = go.AddComponent <AISuperSimpleMove>();
            spawnedAgent.Init(agentConfig, aiMover);
            aiMover.Init(spawnedAgent, agentConfig, go.transform.parent.GetComponent <Tile>());
            TurnManagement.AgentTurnSetter.AddAgentToStateMachine(spawnedAgent);
            amountOfAgentsSpawned++;
            go.name += $" ({amountOfAgentsSpawned})";
        }
        catch { /*please don't do what I'm doing here*/ }
    }