85 lines
2.6 KiB
C#
85 lines
2.6 KiB
C#
using Sirenix.OdinInspector;
|
|
using UnityEngine;
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
namespace BlueWaterProject
|
|
{
|
|
public class EnemyUnit : BaseUnit
|
|
{
|
|
#region Property and variable
|
|
|
|
[PropertyOrder(-10)]
|
|
public EnemyUnitStat enemyUnitStat;
|
|
|
|
private bool isClickedTypeAllButton;
|
|
|
|
#endregion
|
|
|
|
#region Unity built-in function
|
|
|
|
private void OnDrawGizmosSelected()
|
|
{
|
|
if (!Application.isPlaying || enemyUnitStat == null || enemyUnitStat.SailorCount <= 0) return;
|
|
|
|
foreach (var item in enemyUnitStat.EnemyAiList)
|
|
{
|
|
var unitPos = item.transform.position;
|
|
var ray = new Ray(unitPos + Vector3.up, Vector3.down);
|
|
Gizmos.color = Physics.Raycast(ray, UnitManager.Inst.MaxGroundDistance, UnitManager.Inst.GroundLayer) ? Color.blue : Color.red;
|
|
Gizmos.DrawRay(ray.origin, ray.direction * UnitManager.Inst.MaxGroundDistance);
|
|
}
|
|
}
|
|
|
|
#endregion
|
|
|
|
#region Custom function
|
|
|
|
[PropertyOrder(-9)]
|
|
[HorizontalGroup("Split", 0.5f)]
|
|
[GUIColor("GetCreateUnitButtonColor")]
|
|
[EnableIf("@DataManager.Inst.GetEnemyUnitStatSoFromKey(enemyUnitStat.Idx) != null")]
|
|
[Button("유닛 생성")]
|
|
public void CreateUnit()
|
|
{
|
|
UnitManager.Inst.CreateEnemyUnitInEditor(this);
|
|
}
|
|
|
|
[PropertyOrder(-8)]
|
|
[HorizontalGroup("Split", 0.5f)]
|
|
[EnableIf("CanAssignUnit")]
|
|
[Button("유닛 배치")]
|
|
public void AssignUnit()
|
|
{
|
|
if (UnitManager.Inst.CanAssignUnit(this, transform.position))
|
|
{
|
|
UnitManager.Inst.AssignEnemyUnit(this, transform.position);
|
|
}
|
|
}
|
|
|
|
private bool CanAssignUnit()
|
|
{
|
|
return UnitManager.Inst.CanAssignUnit(this, transform.position);
|
|
}
|
|
|
|
[PropertyOrder(-7)]
|
|
[GUIColor(1, 0, 0)]
|
|
[Button("유닛 초기화")]
|
|
private void ResetUnit()
|
|
{
|
|
var tempUnitIdx = enemyUnitStat.Idx;
|
|
UnitManager.Inst.DestroyDeployedUnits(this);
|
|
|
|
enemyUnitStat = new EnemyUnitStat()
|
|
{
|
|
Idx = tempUnitIdx
|
|
};
|
|
isClickedTypeAllButton = false;
|
|
}
|
|
|
|
private Color GetCreateUnitButtonColor() => enemyUnitStat.EnemyAiList.Count > 0 ? Color.white : Color.green;
|
|
private Color GetTypeAllButtonColor() => isClickedTypeAllButton ? Color.white : Color.green;
|
|
private void OnTypeChanged() => isClickedTypeAllButton = false;
|
|
|
|
#endregion
|
|
}
|
|
} |