Ejemplo n.º 1
0
    /**
     * methode qui permet de créer une cellules a partir d'une position et d'un numero
     */
    void CreateCell(int x, int z, int i)
    {
        //création de la postion a partir d'une position * le numero de case
        Vector3 position;

        position.x = x * 10f;
        position.y = 0f;
        position.z = z * 10f;

        //tableau de cellules qui instancie  la cellule dans le tableau a partir de l'argument dans unity et lui donne la position
        CubCell cell = cells[i] = Instantiate <CubCell>(cellPrefab);

        cell.transform.SetParent(transform, false);
        cell.transform.localPosition = position;
        cell.coordinates             = CubCoordinates.FromOffsetCoordinates(x, z);
        cell.color = defaultColor;

        //instanciation du label
        Text label = Instantiate <Text>(cellLabelPrefab);

        label.rectTransform.SetParent(gridCanvas.transform, false);
        label.rectTransform.anchoredPosition =
            new Vector2(position.x, position.z);
        label.text = cell.coordinates.ToStringOnSeparateLines();
    }
Ejemplo n.º 2
0
    void Triangulate(CubCell cell)
    {
        Vector3 center = cell.coordinates.getPosition();

        for (int i = 0; i < 3; i++)
        {
            AddTriangle(
                center,
                center + CubMetrics.corners[i + 1],
                center + CubMetrics.corners[i + 2]
                );
            AddTriangleColor(cell.color);
        }
    }
Ejemplo n.º 3
0
    /*
     * cette methode affiche la postion touché et la celulle
     */
    void TouchCell(Vector3 position)
    {
        position = transform.InverseTransformPoint(position);
        CubCoordinates coordinates = CubCoordinates.FromPosition(position);
        // Debug.Log("touched at " + coordinates.ToString());

        //on color la cellule
        int     index = coordinates.X + coordinates.Z * width;
        CubCell cell  = cells[index];

        if (cell.color == touchedColor)
        {
            cell.color = defaultColor;
        }
        else
        {
            cell.color = touchedColor;
        }
        cubMesh.Cubisme(cells);
    }