| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113 |
- using UnityEngine;
- using System.Collections;
- using System.Collections.Generic;
- using TMPro;
- public class PositionGridManager : MonoBehaviour
- {
- public int gridWidth = 5;
- public int gridHeight = 5;
- public List<CharacterInGroup> characters;
- public GameObject gridCellPrefab;
- public Transform gridParent;
- private CharacterInGroup selectedCharacter;
- void Start()
- {
- GenerateGrid();
- UpdateGridDisplay();
- }
- void GenerateGrid()
- {
- for (int x = 0; x < gridWidth; x++)
- {
- for (int y = 0; y < gridHeight; y++)
- {
- GameObject cell = Instantiate(gridCellPrefab, gridParent);
- GridCell cellComponent = cell.GetComponent<GridCell>();
- cellComponent.Setup(this, x, y);
- }
- }
- }
- public void OnCellClicked(int x, int y)
- {
- if (selectedCharacter != null)
- {
- selectedCharacter.gridX = x;
- selectedCharacter.gridY = y;
- selectedCharacter = null;
- UpdateGridDisplay();
- }
- else
- {
- CharacterInGroup character = characters.Find(c => c.gridX == x && c.gridY == y);
- if (character != null)
- {
- selectedCharacter = character;
- }
- }
- }
- void UpdateGridDisplay()
- {
- GridCell[] cells = gridParent.GetComponentsInChildren<GridCell>();
- foreach (var cell in cells)
- {
- CharacterInGroup character = characters.Find(c => c.gridX == cell.gridX && c.gridY == cell.gridY);
- if (character != null)
- {
- cell.SetLabel(character.characterName);
- }
- else
- {
- cell.SetLabel("");
- }
- }
- }
- public void AddCharacter(CharacterInGroup c)
- {
- if (!characters.Contains(c))
- characters.Add(c);
- UpdateGridDisplay();
- }
- public CharacterInGroup GetFrontlineTarget(Vector3 attackerDirection)
- {
- int line = attackerDirection.z > 0 ? 0 : gridHeight - 1;
- List<CharacterInGroup> frontline = characters.FindAll(c => c.gridY == line);
- if (frontline.Count > 0)
- return frontline[0]; // ici, on prend le premier pour simplifier
- return null;
- }
- public float GetPositionBonus(CharacterInGroup character)
- {
- if (character.characterType == CharacterInGroup.CharacterType.Warrior && character.gridY > 1)
- return -0.5f; // Malus Guerrier derrière
- if (character.characterType == CharacterInGroup.CharacterType.Priest && character.gridY == 0)
- return -0.3f; // Malus Prêtre en front
- return 0f; // Aucun bonus/malus
- }
- #if UNITY_EDITOR
- private void OnDrawGizmos()
- {
- Gizmos.color = Color.cyan;
- for (int x = 0; x < gridWidth; x++)
- {
- for (int y = 0; y < gridHeight; y++)
- {
- Gizmos.DrawWireCube(transform.position + new Vector3(x, 0, y), Vector3.one);
- }
- }
- }
- #endif
- }
|