Exemple #1
0
    private IEnumerator Load()
    {
        string path     = string.Format(LevelPrefix, missionInfo.Level);
        var    loadGrid = Resources.Load <Grid>(path);
        Grid   dungeon  = Instantiate(loadGrid, Vector3.zero, Quaternion.identity, dungeonParent.transform);

        if (dungeon == null)
        {
            throw new Exception("Dungeon grid don't load from resource");
        }

        var tilemapGround = dungeon.transform.Find("Ground").GetComponent <Tilemap>();
        var tilemapWall   = dungeon.transform.Find("Wall").GetComponent <Tilemap>();
        var tilemapBlack  = dungeon.transform.Find("Black").GetComponent <Tilemap>();

        int cellUnit = (int)dungeon.cellSize.x;

        Size = tilemapWall.cellBounds.size * cellUnit;

        var center = tilemapWall.cellBounds.center * cellUnit;

        Vector3 newDungPosition = new Vector3(dungeon.transform.position.x - center.x, dungeon.transform.position.y - center.y, 0);

        dungeon.transform.position = newDungPosition;

        WPosition = tilemapWall.cellBounds.center;

        foreach (var position in tilemapGround.cellBounds.allPositionsWithin)
        {
            if (tilemapGround.HasTile(position))
            {
                var worldPosition = tilemapGround.CellToWorld(position);
                worldPosition = new Vector3(worldPosition.x + 0.5f, worldPosition.y + 0.5f, -1);
                AvailablePosition.Add(worldPosition);
            }
        }

        var ps = dungeon.transform.Find("PlayerSpawnPos");

        BlackTiles(tilemapGround, tilemapWall, tilemapBlack);

        RandomSpawnObjects(keyPrefab, itemsParent.transform, missionInfo.NeedKeys);
        RandomSpawnObjects(batteryPrefab, itemsParent.transform, missionInfo.BatteryCount);
        var player = SpawnPlayer(ps.position);

        var patrolPointsParent = dungeon.transform.Find("PatrolPoints");
        List <GameObject> patrolPointsForGhost = new List <GameObject>();

        for (int i = 0; i < patrolPointsParent.childCount; i++)
        {
            patrolPointsForGhost.Add(patrolPointsParent.GetChild(i).gameObject);
        }
        SpawnGhosts(player.transform, patrolPointsForGhost);

        yield break;
    }
Exemple #2
0
    private void Start()
    {
        IdentifyHexes();
        AvailablePosition hero       = FindObjectOfType <AvailablePosition>();
        IAdjacentFinder   adjFinder  = new PositionsForFlying();
        BattleHex         startigHex = hero.GetComponentInParent <BattleHex>();
        int stepsLimit = BattleController.currentAtacker.velocity;

        startigHex.DefineAsStartingHex();
        hero.GetAvailablePositions(hero.GetComponentInParent <BattleHex>(), stepsLimit, adjFinder);
    }