52 lines
2.0 KiB
C#
52 lines
2.0 KiB
C#
using System.Collections.Generic;
|
|
using Actions;
|
|
using UnityEngine;
|
|
|
|
namespace Grid {
|
|
public class GridSystemVisual : MonoBehaviour {
|
|
[SerializeField] private Transform GridSystemVisualSinglePrefab;
|
|
private GridSystemVisualSingle[,] gridSystemVisualSingleArray;
|
|
|
|
public static GridSystemVisual Instance { get; private set; }
|
|
|
|
private void Awake() {
|
|
if (Instance is not null) {
|
|
Debug.LogError($"There is more than one GridSystemVisual! {transform} - {Instance}");
|
|
Destroy(gameObject);
|
|
return;
|
|
}
|
|
|
|
Instance = this;
|
|
}
|
|
|
|
private void Start() {
|
|
int width = LevelGrid.Instance.GetWidth();
|
|
int height = LevelGrid.Instance.GetHeight();
|
|
gridSystemVisualSingleArray = new GridSystemVisualSingle[width, height];
|
|
|
|
for (int x = 0; x < width; x++) {
|
|
for (int z = 0; z < height; z++) {
|
|
Transform gridSystemVisualSingleTransform = Instantiate(GridSystemVisualSinglePrefab, LevelGrid.Instance.GetWorldPosition(new(x, z)), Quaternion.identity);
|
|
gridSystemVisualSingleArray[x, z] = gridSystemVisualSingleTransform.GetComponent<GridSystemVisualSingle>();
|
|
}
|
|
}
|
|
}
|
|
|
|
private void Update() => UpdateGridVisual();
|
|
|
|
public void HideAllGridPosition() {
|
|
foreach (GridSystemVisualSingle gridSystemVisualSingle in gridSystemVisualSingleArray)
|
|
gridSystemVisualSingle.Hide();
|
|
}
|
|
|
|
public void ShowGridPositionList(List<GridPosition> gridPositionList) {
|
|
foreach (GridPosition gridPosition in gridPositionList)
|
|
gridSystemVisualSingleArray[gridPosition.X, gridPosition.Z].Show();
|
|
}
|
|
|
|
private void UpdateGridVisual() {
|
|
HideAllGridPosition();
|
|
ShowGridPositionList(UnitActionSystem.Instance.SelectedAction.GetValidActionGridPositionList());
|
|
}
|
|
}
|
|
} |