示例#1
0
    void createGrid()
    {
        //Game object which is the parent of all the hex tiles
        GameObject hexGridGO = new GameObject("HexGrid");
        hexGridGO.tag = "Finish";
        for (float y = 0; y < gridHeightInHexes; y++)
        {
            for (float x = 0; x < gridWidthInHexes; x++)
            {
                hexTile = hexArray[(int)x,(int)y];
                hexTile.setXCoord((int)x);
                hexTile.setYCoord((int)y);

                bool isZone = hexTile.getIsZone();
                bool isNewHazard = hexTile.getIsNewHazard();
                bool isArmedHazard = hexTile.getIsArmedHazard();
                bool isKIAHazard = hexTile.getIsKIAHazard();
                bool isExploded = hexTile.getIsExploded();
                int hasXAllies = hexTile.getHasXAllies();
                bool isSelect = hexTile.getIsSelect();
                if(isZone)
                {
                    GameObject zZone= (GameObject)Instantiate(zone);
                    //Current position in grid
                    Vector2 gridPos = new Vector2(x, y);
                    zZone.transform.position = calcWorldCoord(gridPos)+new Vector3(0,0.1f,0);
                    zZone.transform.parent = hexGridGO.transform;
                }

                if(isNewHazard)
                {
                    GameObject hHazard= (GameObject)Instantiate(newHazard);
                    //Current position in grid
                    Vector2 gridPos = new Vector2(x, y);
                    hHazard.transform.position = calcWorldCoord(gridPos)+new Vector3(0,0.18f,0);
                    hHazard.transform.parent = hexGridGO.transform;
                }

                if(isArmedHazard)
                {
                    GameObject hHazard= (GameObject)Instantiate(armedHazard);
                    //Current position in grid
                    Vector2 gridPos = new Vector2(x, y);
                    hHazard.transform.position = calcWorldCoord(gridPos)+new Vector3(0,0.15f,0);
                    hHazard.transform.parent = hexGridGO.transform;
                }

                if(isKIAHazard)
                {
                    GameObject hHazard= (GameObject)Instantiate(kIAHazard);
                    //Current position in grid
                    Vector2 gridPos = new Vector2(x, y);
                    hHazard.transform.position = calcWorldCoord(gridPos)+new Vector3(0,0.19f,0);
                    hHazard.transform.parent = hexGridGO.transform;
                    if (isExploded){
                        Instantiate(allyExplosion, hHazard.transform.position, transform.rotation); /////////Maybe Problem
                        hexTile.setIsExploded(false);

                    }

                }

                if(hasXAllies>0)
                {

                    for(int i=0; i<hasXAllies;i++)
                    {
                        GameObject aAlly= (GameObject)Instantiate(ally);
                        aAlly.GetComponent<Ally>().initAlly((int)x, (int) y);
                    //Current position in grid
                        Vector2 gridPos = new Vector2(x, y);
                        aAlly.transform.position = calcWorldCoord(gridPos)+new Vector3(0,0.15f,0);
                    //alliesText.transform.position= calcWorldCoord(gridPos)+new Vector3(0,0.15f,0.2f);
                    //alliesText.text= hexArray[(int)x,(int)y].getHasXAllies().ToString();
                        aAlly.transform.parent = hexGridGO.transform;
                        if(aAlly!= null)
                            allyList.Add(aAlly);
                    }
                }

                if(isSelect)
                {
                    GameObject pPlayer= (GameObject)Instantiate(player);
                    //Current position in grid
                    Vector2 gridPos = new Vector2(x, y);
                    pPlayer.transform.position = calcWorldCoord(gridPos)+new Vector3(0,-0.1f,0);
                    pPlayer.transform.parent = hexGridGO.transform;

                }

                //normal hexes:
                GameObject hexa= (GameObject)Instantiate(hex);
                //Current position in grid
                Vector2 gGridPos = new Vector2(x, y);
                hexa.transform.position = calcWorldCoord(gGridPos);
                hexa.transform.parent = hexGridGO.transform;

            }
        }
    }