示例#1
0
    /// <summary>
    /// Creates the initial garden UI.
    /// </summary>
    void Start()
    {
        Application.runInBackground = true;


        // Extract size from tile prefab
        TilePrefabWidth  = TilePrefab.GetComponent <SpriteRenderer>().bounds.size.x;
        TilePrefabHeight = TilePrefab.GetComponent <SpriteRenderer>().bounds.size.y;
        // Initi GuiTiles
        for (int row = 0; row < garden.GardenHeigth; row++)
        {
            for (int col = 0; col < garden.GardenWidth; col++)
            {
                Garden.GridPosition gridPosition = new Garden.GridPosition(col, row);
                GameObject          go           = (GameObject)Instantiate(TilePrefab, transform.position, Quaternion.identity);
                go.transform.SetParent(this.transform);
                go.layer = this.gameObject.layer;
                go.transform.position = GridPositionToUnityPosition(gridPosition);
                go.GetComponent <GuiTile>().SetColorForState(garden.GetTileStatus(gridPosition));

                tiles.Add(go);
            }
        }
        Garden.AddObserver(this);

        // Init GuiMower
        GameObject mowerGo = Instantiate(MowerPrefab);

        mowerGo.GetComponent <GuiMower>().Init(this);

        // Init GuiMovingObstacles
        foreach (var movingObstacle in Garden.MovingObstacles)
        {
            GameObject obstacleGO = Instantiate(AnimalPrefab);
            obstacleGO.GetComponent <GuiMovingObstacle>().Init(this, movingObstacle);
        }
    }