94 lines
2.9 KiB
C#
94 lines
2.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
[Serializable]
|
|
public class Unit
|
|
{
|
|
[Tooltip("부대의 이름")]
|
|
public string unitName;
|
|
|
|
[Tooltip("부대의 종류")]
|
|
public GlobalValue.UnitType unitType;
|
|
|
|
[Tooltip("부대의 병력 수")]
|
|
public int soliderCount;
|
|
|
|
[Tooltip("부대 병력 리스트")]
|
|
public List<AiController> soldierList;
|
|
|
|
public Unit()
|
|
{
|
|
unitName = null;
|
|
unitType = GlobalValue.UnitType.NONE;
|
|
soliderCount = 0;
|
|
soldierList = new List<AiController>();
|
|
}
|
|
|
|
public Unit(string unitName, GlobalValue.UnitType unitType, int soliderCount, List<AiController> soldierList)
|
|
{
|
|
this.unitName = unitName;
|
|
this.unitType = unitType;
|
|
this.soliderCount = soliderCount;
|
|
|
|
this.soldierList = new List<AiController>(this.soliderCount);
|
|
this.soldierList = soldierList;
|
|
}
|
|
}
|
|
|
|
public class UnitController : MonoBehaviour
|
|
{
|
|
public Unit unit;
|
|
|
|
#if UNITY_EDITOR
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
if (unit == null || unit.soliderCount <= 0) return;
|
|
|
|
var unitManager = Application.isPlaying ? GameManager.Inst.UnitManager : FindObjectOfType<UnitManager>();
|
|
if (unitManager == null) return;
|
|
|
|
var matrix = unitManager.UnitMatrices.Find(um => um.soldiers == unit.soliderCount);
|
|
if (matrix == null) return;
|
|
|
|
for (var i = 0; i < unit.soliderCount; i++)
|
|
{
|
|
var row = i / matrix.columns;
|
|
var column = i % matrix.columns;
|
|
|
|
var xOffset = (column - (matrix.columns - 1) / 2.0f) * 0.5f;
|
|
var zOffset = (row - (matrix.rows - 1) / 2.0f) * 0.5f;
|
|
var spawnPosition = transform.position + new Vector3(xOffset, 0, zOffset);
|
|
|
|
var ray = new Ray(spawnPosition, Vector3.down);
|
|
Gizmos.color = Physics.Raycast(ray, unitManager.MaxGroundDistance, unitManager.GroundLayer) ? Color.green : Color.red;
|
|
Gizmos.DrawRay(ray.origin, ray.direction * unitManager.MaxGroundDistance);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
[ContextMenu("유닛 생성")]
|
|
public void CreateUnit()
|
|
{
|
|
if (!Application.isPlaying)
|
|
{
|
|
var unitManager = FindObjectOfType<UnitManager>();
|
|
unitManager.CreateUnit(this, unit);
|
|
return;
|
|
}
|
|
|
|
GameManager.Inst.UnitManager.CreateUnit(this, unit);
|
|
}
|
|
|
|
public void MoveCommand(Vector3 targetPos)
|
|
{
|
|
foreach (var soldier in unit.soldierList)
|
|
{
|
|
soldier.GetNavMeshAgent().SetDestination(targetPos);
|
|
}
|
|
}
|
|
}
|
|
} |