70 lines
2.0 KiB
C#
70 lines
2.0 KiB
C#
|
|
using System.Collections.Generic;
|
||
|
|
using UnityEngine;
|
||
|
|
|
||
|
|
namespace WarGame.Deployment
|
||
|
|
{
|
||
|
|
public class DeploymentZone : MonoBehaviour
|
||
|
|
{
|
||
|
|
[Header("Zone Dimensions")]
|
||
|
|
[SerializeField] private Vector2 zoneSize = new Vector2(10f, 6f);
|
||
|
|
[SerializeField] private int columns = 5;
|
||
|
|
[SerializeField] private int rows = 3;
|
||
|
|
[SerializeField] private Color gizmoColor = new Color(0f, 0.8f, 1f, 0.3f);
|
||
|
|
|
||
|
|
private readonly List<Vector3> slotPositions = new List<Vector3>();
|
||
|
|
private int currentSlotIndex = 0;
|
||
|
|
|
||
|
|
private void Awake()
|
||
|
|
{
|
||
|
|
GenerateSlots();
|
||
|
|
}
|
||
|
|
|
||
|
|
private void GenerateSlots()
|
||
|
|
{
|
||
|
|
slotPositions.Clear();
|
||
|
|
float cellWidth = zoneSize.x / Mathf.Max(1, columns);
|
||
|
|
float cellHeight = zoneSize.y / Mathf.Max(1, rows);
|
||
|
|
|
||
|
|
Vector3 startPos = transform.position - new Vector3(zoneSize.x * 0.5f, 0f, zoneSize.y * 0.5f);
|
||
|
|
|
||
|
|
for (int r = 0; r < rows; r++)
|
||
|
|
{
|
||
|
|
for (int c = 0; c < columns; c++)
|
||
|
|
{
|
||
|
|
Vector3 slot = startPos + new Vector3(
|
||
|
|
c * cellWidth + cellWidth * 0.5f,
|
||
|
|
0f,
|
||
|
|
r * cellHeight + cellHeight * 0.5f
|
||
|
|
);
|
||
|
|
slotPositions.Add(slot);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
public Vector3 GetNextSpawnPosition()
|
||
|
|
{
|
||
|
|
if (slotPositions.Count == 0) GenerateSlots();
|
||
|
|
|
||
|
|
if (currentSlotIndex >= slotPositions.Count)
|
||
|
|
{
|
||
|
|
currentSlotIndex = 0; // Wrap around if army is larger than grid
|
||
|
|
}
|
||
|
|
|
||
|
|
Vector3 pos = slotPositions[currentSlotIndex];
|
||
|
|
currentSlotIndex++;
|
||
|
|
return pos;
|
||
|
|
}
|
||
|
|
|
||
|
|
public void ResetSlots()
|
||
|
|
{
|
||
|
|
currentSlotIndex = 0;
|
||
|
|
}
|
||
|
|
|
||
|
|
private void OnDrawGizmos()
|
||
|
|
{
|
||
|
|
Gizmos.color = gizmoColor;
|
||
|
|
Gizmos.DrawWireCube(transform.position, new Vector3(zoneSize.x, 0.2f, zoneSize.y));
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|