Exemplo n.º 1
0
    void Start()
    {
        resourcesObject = GameObject.Find("ResourcesObject").transform;
        Debug.Log(Map.mapSizeX + " " + Map.mapSizeY);

        for (int i = Map.mapSizeY - 1; i >= 0; i--)
        {
            for (int j = Map.mapSizeX - 1; j >= 0; j--)
            {
                Map.mapData [j, i] = new TileData();
            }
        }

        CreateHillsAndLakes();
        CreateForests();
        CreateStones();

        int startOrder   = 0;
        int currentOrder = 0;

        for (int i = Map.mapSizeY - 1; i >= 0; i--)
        {
            currentOrder = startOrder;
            for (int j = Map.mapSizeX - 1; j >= 0; j--)
            {
                string        path   = "";
                Point <float> iso_pt = Point <float> .ToIsometric(new Point <int> (j, i));

                Transform tileObject = null;

                switch (Map.mapData [j, i].tileType)
                {
                case TileData.TileType.Ground:
                {
                    path = "Prefabs/Ground/grass" + Map.mapData [j, i].prefabID;
                    LoadTile(path);
                    break;
                }

                case TileData.TileType.Hill:
                {
                    path = "Prefabs/Hill/hill" + Map.mapData [j, i].prefabID;
                    LoadTile(path);
                    break;
                }

                case TileData.TileType.Lake:
                {
                    path = "Prefabs/Lake/water" + Map.mapData [j, i].prefabID;
                    LoadTile(path);
                    break;
                }
                }

                tileObject = PlaceTile(tileToLoad, iso_pt /*, Map.mapData [j, i]*/);
                tileObject.GetComponent <Renderer>().sortingOrder = 0;
                Map.mapData [j, i].InitTile(tileObject);

                if (Map.resourceData [j, i] != null)
                {
                    //create resource
                    ResourceData resource = Map.resourceData[j, i];
                    switch (Map.resourceData [j, i].resourceType)
                    {
                    case ResourceData.ResourceType.Stone:
                        int stoneAmount = Random.Range(0, 101);
                        if (stoneAmount <= 100 && stoneAmount > 75)
                        {
                            path = "Prefabs/Stone/StoneLarge" + Random.Range(1, 3 /*Number of Stone types*/);
                        }
                        else if (stoneAmount <= 75 && stoneAmount > 50)
                        {
                            path = "Prefabs/Stone/StoneMedium" + Random.Range(1, 9 /*Number of Stone types*/);
                        }
                        else if (stoneAmount <= 50 && stoneAmount > 25)
                        {
                            path = "Prefabs/Stone/StoneMidSmall" + Random.Range(1, 3 /*Number of Stone types*/);
                        }
                        else
                        {
                            path = "Prefabs/Stone/StoneSmall" + Random.Range(1, 3 /*Number of Stone types*/);
                        }

                        LoadTile(path);
                        tileObject = PlaceTile(tileToLoad, iso_pt);
                        //Transform tileObject = Instantiate (tileToLoad, new Vector3 (iso_pt.x, iso_pt.y, 0), Quaternion.identity) as Transform;
                        tileObject.GetComponent <Renderer>().sortingOrder = currentOrder + 1;
                        tileObject.parent = resourcesObject;
                        tileObject.tag    = "Resource";
                        tileObject.gameObject.AddComponent <Stone> ();
                        //ResourceData stoneData = new ResourceData (ResourceData.ResourceType.Stone, tileObject);
                        resource.InitTile(tileObject);
                        resource.script.amountLeft = stoneAmount;
                        break;

                    case ResourceData.ResourceType.Wood:
                        path = "Prefabs/Wood/Tree" + Random.Range(1, 2 /*Number of tree types*/);
                        LoadTile(path);
                        tileObject = PlaceTile(tileToLoad, iso_pt);
                        //Transform tileObject = Instantiate (tileToLoad, new Vector3 (iso_pt.x, iso_pt.y, 0), Quaternion.identity) as Transform;
                        tileObject.GetComponent <Renderer> ().sortingOrder = currentOrder + 1;
                        tileObject.parent = resourcesObject;
                        tileObject.tag    = "Resource";
                        resource.InitTile(tileObject);
                        break;
                    }
                }
                currentOrder++;
            }
            startOrder++;
        }
    }