Пример #1
0
    public void GenerateLevel()
    {
        if (trunksParent) {
            Object.Destroy(trunksParent);
            trunksParent = null;
        }

        trunksParent = new GameObject ();
        trunksParent.name = string.Format (parentNameFormatter, levelIdx);

        rmg = new RoomGenerator ();
        rmg.GenerateRoom ();
        rmg.FillTilemap ();
        rmg.GenerateNeighborMap ();

        RoomGenerator.TileType[,] tiles = rmg.TileMapData;

        TrunkManager tm = new TrunkManager (rmg.mapWidth);
        tm.FillWithData (rmg.NeighborMapData, tiles);

        TextureConfig.TextureData td = TextureConfig.BackgroundTextures[levelIdx];

        for (int i = 0; i < TrunkManager.MaxTrunks; i ++) {
            if (tm[i] == null) continue;
            GameObject t = new GameObject((string.Format(trunkNameFormatter, i)) ,typeof(MeshRenderer), typeof(MeshFilter));
            Trunk trunk = tm[i];
            t.GetComponent<MeshFilter>().mesh = trunk.mesh;
            Vector3 pos = t.transform.position;
            pos.x = trunk.x;
            pos.y = trunk.y;
            t.transform.position = pos;
            t.transform.SetParent(trunksParent.transform);
            MeshRenderer mr = t.GetComponent<MeshRenderer>();
            Material mtl = Resources.Load(td.path) as Material;
            mr.sharedMaterial = mtl;
        }
    }