Beispiel #1
0
    // Use this for initialization
    void Start()
    {
        //Create an empty parent GameObject to control the scale of the entire layout.
        mapScaler = GameObject.Find("MapScaler");
        if (mapScaler == null)
        {
            mapScaler = new GameObject("MapScaler");
        }

        //Create an empty parent for the grid.
        gridLayout = GameObject.Find("GridLayout");
        if (gridLayout == null)
        {
            gridLayout = new GameObject("GridLayout");
            gridLayout.transform.SetParent(mapScaler.transform);
        }

        //Create an empty parent for the Player Character pieces.
        playerLayout = GameObject.Find("PlayerLayout");
        if (playerLayout == null)
        {
            playerLayout = new GameObject("PlayerLayout");
            playerLayout.transform.SetParent(mapScaler.transform);
        }

        //Create an empty parent for the NPC pieces.
        npcLayout = GameObject.Find("NPCLayout");
        if (npcLayout == null)
        {
            npcLayout = new GameObject("NPCLayout");
            npcLayout.transform.SetParent(mapScaler.transform);
        }

        //Create an empty parent for the Tile pieces.
        tileLayout = GameObject.Find("TileLayout");
        if (tileLayout == null)
        {
            tileLayout = new GameObject("TileLayout");
            tileLayout.transform.SetParent(mapScaler.transform);
        }

        MapItem  grid       = JsonUtility.FromJson <MapItem> (JSONSTRING);
        Vector3  gridVector = new Vector3(-0.5f, 0, -0.5f);
        GridMesh gridMaker  = Instantiate(gridPrefab, gridVector, Quaternion.identity).GetComponent <GridMesh>();

        gridMaker.transform.SetParent(gridLayout.transform);
        gridMaker.setSize(grid.width);
        buildMap(grid);
    }