Пример #1
0
    private void GenerateGrid()
    {
        if (genericGround == null)
        {
            return;
        }

        if (GameManage.DonnerInstance.Carte == null)
        {
            return;
        }

        x = (int)GameManage.DonnerInstance.Carte.Xmax;
        y = (int)GameManage.DonnerInstance.Carte.Ymax;

        int origineX = -((x) / 2);
        int origineY = -((y) / 2);

        if (solGenerique == null)
        {
            solGenerique = new PoolObjects();
            solGenerique.SetGameObject       = genericGround;
            solGenerique.SetParentGameObject = this.transform;
        }


        Carte carte = GameManage.DonnerInstance.Carte;

        for (int i = 0; i < x; i++)
        {
            for (int j = 0; j < y; j++)
            {
                if (carte.DonnerCellule(i, j) != null &&
                    carte.DonnerCellule(i, j).EstOccupe)
                {
                    int ht = carte.DonnerCellule(i, j).Hauteur;
                    for (int a = 0; a <= ht; a++)
                    {
                        solGenerique.CreerObject(new Vector3(origineX + i * h, a, origineY + j * w), Quaternion.identity);
                    }
                }
            }
        }
    }
Пример #2
0
    // Update is called once per frame
    void FixedUpdate()
    {
        if (GameManage.DonnerInstance.Role == GameManage.ROLE.ROLE_AUCUN)
        {
            return;
        }

        if (GameManage.DonnerInstance.Role == GameManage.ROLE.ROLE_JOUEUR)
        {
            AfficherGrid(false);
        }

        if (GameManage.DonnerInstance.Action == GameManage.ACTION_TYPE.ACTION_TYPE_CHANGEMENT_CARTE)
        {
            aChanger = true; ViderWorld(); GameManage.DonnerInstance.Action = GameManage.ACTION_TYPE.ACTION_TYPE_AUCUN;
        }

        if (aChanger)
        {
            GenerateGrid();
            aChanger = false;
        }


        if (GameManage.DonnerInstance.Mode == GameManage.MODE.MODE_CONSTRUCTION)
        {
            Carte carte = GameManage.DonnerInstance.Carte;
            if (Input.GetMouseButtonUp(0) || Input.touchCount > 0)
            {
                Vector3 position;

#if UNITY_ANDROID
                position = Input.touches[0].position;
#else
                position = Input.mousePosition;
#endif
                int       i   = 0;
                int       j   = 0;
                Transform obj = SelectObjet(position);
                if (obj != null && obj.tag == "grid")
                {
                    Vector3 newPos = obj.position;
                    newPos.y = 0;
                    solGenerique.CreerObject(newPos, Quaternion.identity);
                    grid.SupprimerObject(obj.gameObject);
                }
                else if (obj != null && obj.tag == "ground")
                {
                    Vector3 newPos = obj.position;
                    i = (int)Mathf.Abs(newPos.x);
                    j = (int)Mathf.Abs(newPos.z);


                    newPos.y = carte.DonnerCellule(i, j).Hauteur;
                    carte.DonnerCellule(i, j).Hauteur++;
                    solGenerique.CreerObject(newPos, Quaternion.identity);
                }
            }
            else if (Input.GetMouseButton(1))
            {
                Vector3   position = Input.mousePosition;
                Transform obj      = SelectObjet(position);
                if (obj != null && obj.tag == "ground")
                {
                    Vector3 newPos = obj.position;
                    newPos.y = -0.5f;
                    grid.CreerObject(newPos, Quaternion.identity);

                    // A faire: si en dessous il y a autre chose qu'un cube
                    solGenerique.SupprimerObject(obj.gameObject);
                }
            }
        }
    }