コード例 #1
0
ファイル: TileViewController.cs プロジェクト: JammedGame/LD48
    private static TileView[,] SpawnTileViews(GameWorld gameWorld)
    {
        // init tile views.
        var width          = gameWorld.LevelData.Width;
        var height         = gameWorld.LevelData.Height;
        var tileViews      = new TileView[width, height];
        var tileViewPrefab = Resources.Load <TileView>("Prefabs/Tile");

        for (int i = 0; i < width; i++)
        {
            for (int j = 0; j < height; j++)
            {
                var tile = gameWorld.GetTile(i, j);
                tileViews[i, j] = TileView.CreateView(tile, tileViewPrefab);
            }
        }

        return(tileViews);
    }
コード例 #2
0
ファイル: ViewController.cs プロジェクト: JammedGame/LD47
    public ViewController(GameWorld gameWorld)
    {
        this.gameWorld = gameWorld;

        tileViewPrefab = Resources.Load <TileView>("Prefabs/TileView");
        tile2View      = new TileView[levelData.Width, levelData.Height];
        for (var i = 0; i < levelData.Width; i++)
        {
            for (var j = 0; j < levelData.Height; j++)
            {
                var tile     = gameWorld.GetTile(i, j);
                var tileView = TileView.CreateView(tile, tileViewPrefab);
                tile2View[i, j] = tileView;
            }
        }

        foreach (var train in gameWorld.AllTrains)
        {
            allTrainViews.Add(TrainView.CreateView(train));
        }

        foreach (var trainSpawn in levelData.TrainSpawns)
        {
            HomeIconView.Spawn(trainSpawn);
        }

        foreach (var cargSpawner in gameWorld.AllCargoSpawners)
        {
            CargoIconsView.Create(cargSpawner);
        }

        var levelTextPrefab = Resources.Load <TextMeshPro>("Prefabs/LevelText");

        foreach (var levelText in levelData.LevelTexts)
        {
            var levelTextInstance =
                Object.Instantiate(levelTextPrefab, TileViewUtil.GetPosition3D(levelText.X, levelText.Y),
                                   Quaternion.identity);
            levelTextInstance.text = levelText.Text;
            levelTextInstance.GetComponent <RectTransform>().sizeDelta = new Vector2(levelText.Width, levelText.Height);
        }
    }