示例#1
0
    //VegType vegType;

    public Vegetation(uint i, uint j, VegID vegID)
    {
        if (resources == null)
        {
            initResources();
        }

        //vegType = (vegID == VegID.tree_0 || vegID == VegID.tree_1) ? VegType.TREE : VegType.PLANT;
        //this.vegID = vegID;
        initRepresentation(i, j, vegID);
    }
示例#2
0
    private void initRepresentation(uint i, uint j, VegID id)
    {
        Debug.Assert(resources.ContainsKey(id), "Nature not loaded: " + id);
        GameObject prefab = resources[id];

        WorldTerrain wt      = WorldTerrain.GetInstance();
        float        map_top = wt.getTileWorldPositionY(wt.getNumTilesY() - 1, 0);
        float        map_h   = wt.getTileWorldPositionY(0, wt.getNumTilesX() - 1) - wt.getTileWorldPositionY(wt.getNumTilesY() - 1, 0);

        Vector3 size = prefab.GetComponent <SpriteRenderer> ().bounds.size;
        Vector3 pos  = wt.getTileWorldPosition(i, j);

        pos.y += size.y / 2 - WorldTerrain.TILE_HEIGHT_UNITS / 2;
        pos.z  = WorldTerrain.PLANTS_Z_LAYER - (map_top - (pos.y)) / map_h;

        representation      = (GameObject)GameObject.Instantiate(prefab, pos, Quaternion.identity);
        m_currentVegetation = id;
    }