/** * 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(); }
/** * Methode qui affiche les coordonnée dans le gui */ public override void OnGUI(Rect position, SerializedProperty property, GUIContent label) { CubCoordinates coordinates = new CubCoordinates( property.FindPropertyRelative("x").intValue, property.FindPropertyRelative("z").intValue ); //permet d'obtenir le label a afficher avant la postion position = EditorGUI.PrefixLabel(position, label); //affichage GUI.Label(position, coordinates.ToString()); }
/* * 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); }