Beispiel #1
0
    public static Building CreateFromStub(BuildingStub stub)
    {
        GameObject prefab = null;

        switch (stub.type)
        {
        case BuildingStub.BuildingType.PowerStation: {
            //deprecated
            break;
        }

        case BuildingStub.BuildingType.Decoration: {
            prefab = Houseprefab;
            break;
        }
        }

        if (prefab == null)
        {
            return(null);
        }

        GameObject building = (GameObject)Instantiate(prefab);

        building.transform.position = new Vector3(stub.xPos, stub.yPos, building.transform.position.z);

        World w = World.FindObjectOfType <World>();

        w.ChangeTile(building.transform.position.ToVector2(), Tile.Building);

        return(building.GetComponent <Building>());
    }
    //Creates the world from the resource asset at path levelName
    public void CreateWorld(string levelName)
    {
        string[] lines = ReadLines(levelName);
        RoadStub[,] roadstubs         = new RoadStub[lines.Length, lines[0].Length];
        BuildingStub[,] buildingstubs = new BuildingStub[lines.Length, lines[0].Length];
        world.terraingrid             = new Tile[lines.Length, lines[0].Length];

        //Read file line by line and construct the map
        world.WorldSize = new Pair <int, int>(lines[0].Length, lines.GetLength(0));

        for (int y = 0; y < lines.GetLength(0); y++)
        {
            for (int x = 0; x < lines[0].Length; ++x)
            {
                switch (lines[y][x])
                {
                case '1': {
                    roadstubs[y, x] = new RoadStub(x, y);
                    break;
                }

                case '2': {
                    roadstubs[y, x]      = new RoadStub(x, y);
                    roadstubs[y, x].type = RoadStub.RoadType.ChargingSpot;
                    break;
                }

                case 'P': {
                    roadstubs[y, x]      = new RoadStub(x, y);
                    roadstubs[y, x].type = RoadStub.RoadType.ParkingSpot;
                    break;
                }

                case 'E': {
                    buildingstubs[y, x] = new BuildingStub(x, y, BuildingStub.BuildingType.PowerPlant);
                    world.BuildPowerplant(world.GetRealWorldCoordinates(x, y));
                    break;
                }

                case 'B': {
                    buildingstubs[y, x] = new BuildingStub(x, y, BuildingStub.BuildingType.Decoration);
                    break;
                }
                }
            }
        }
        world.roadmap = new RoadMap();
        world.roadmap.CreateMap(roadstubs);

        world.buildings = new BuildingManager();
        world.buildings.Build(buildingstubs);
    }