유닛 배치 오류 수정

This commit is contained in:
NTG_Lenovo 2023-09-11 12:41:02 +09:00
parent 243fcbd0ef
commit c1e4175e26
8 changed files with 458816 additions and 223729 deletions

File diff suppressed because it is too large Load Diff

View File

@ -132,11 +132,11 @@ namespace BlueWaterProject
{
aiAnimator.SetFloat(SpeedHash, navMeshAgent.velocity.normalized.magnitude);
if (!TargetTransform || !navMeshAgent.enabled) return;
var distanceToTarget = Vector3.Distance(transform.position, TargetTransform.position);
navMeshAgent.isStopped = distanceToTarget <= navMeshAgent.stoppingDistance;
// if (!TargetTransform || !navMeshAgent.enabled) return;
//
// var distanceToTarget = Vector3.Distance(transform.position, TargetTransform.position);
//
// navMeshAgent.isStopped = distanceToTarget <= navMeshAgent.stoppingDistance;
// switch (AiStat.AttackerType)
// {
@ -364,24 +364,12 @@ namespace BlueWaterProject
break;
case EDefenseType.STRIKER:
SetNearestTargetInDefense(transform.position, AiStat.ViewRange);
// if (TargetTransform)
// {
// Utils.SetCloseDestination(navMeshAgent, TargetTransform.position, AiStat.AtkRange - 0.5f, AiStat.AtkRange);
// }
break;
case EDefenseType.MIDFIELDER:
SetNearestTargetInDefense(transform.position, AiStat.ViewRange);
// if (TargetTransform)
// {
// Utils.SetCloseDestination(navMeshAgent, TargetTransform.position, AiStat.AtkRange - 0.5f, AiStat.AtkRange);
// }
break;
case EDefenseType.DEFENDER:
SetNearestTargetInDefense(defensePos, AiStat.DefenseRange);
// if (TargetTransform)
// {
// Utils.SetCloseDestination(navMeshAgent, TargetTransform.position, AiStat.AtkRange - 0.5f, AiStat.AtkRange);
// }
break;
case EDefenseType.KEEPER:
SetNearestTargetInDefense(transform.position, AiStat.ViewRange);
@ -676,12 +664,13 @@ namespace BlueWaterProject
StartCoroutine(nameof(AttackAnimation));
}
private IEnumerator AttackAnimation()
protected virtual IEnumerator AttackAnimation()
{
while (true)
{
if (!CanAttack())
{
isAttacking = false;
yield return FindTargetWaitTime;
continue;
}

View File

@ -132,7 +132,7 @@ namespace BlueWaterProject
protected override void Attack()
{
StartCoroutine(nameof(ShootArrowAnimation));
StartCoroutine(nameof(AttackAnimation));
}
public override void SetNearestTargetInOffense<T>(List<T> targetList)
@ -221,7 +221,7 @@ namespace BlueWaterProject
// return targetInAttackRange && raycastHitTarget;
// }
private IEnumerator ShootArrowAnimation()
protected override IEnumerator AttackAnimation()
{
while (true)
{

View File

@ -20,45 +20,14 @@ namespace BlueWaterProject
private void OnDrawGizmosSelected()
{
if (unit == null || unit.SailorCount <= 0) return;
var gridSize = 0;
if (!Application.isPlaying || unit == null || unit.SailorCount <= 0) return;
switch (unit.SailorCount)
foreach (var item in unit.UnitList)
{
case 0:
gridSize = 1;
break;
case <= 3:
gridSize = 2;
break;
case <= 8:
gridSize = 3;
break;
case <= 15:
gridSize = 4;
break;
default:
print("유닛의 병사 숫자 설정 에러");
break;
}
for (var i = 0; i < gridSize; i++)
{
for (var j = 0; j < gridSize; j++)
{
var currentPos = i * gridSize + j;
if (currentPos > unit.SailorCount) break;
var xOffset = (i - (gridSize - 1) / 2.0f) * UnitManager.Inst.UnitSpacing;
var zOffset = (j - (gridSize - 1) / 2.0f) * UnitManager.Inst.UnitSpacing;
var spawnPosition = transform.position + new Vector3(xOffset, 0, zOffset);
var ray = new Ray(spawnPosition + 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);
}
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);
}
}

View File

@ -442,11 +442,11 @@ namespace BlueWaterProject
for (var i = 0; i < unitController.unit.SailorCount; i++)
{
var soldierPos = unitController.unit.UnitList[i].transform.position;
var ray = new Ray(soldierPos + Vector3.up, Vector3.down);
var unitPos = unitController.unit.UnitList[i].transform.position;
var ray = new Ray(unitPos + Vector3.up, Vector3.down);
if (Physics.Raycast(ray, out var hit, MaxGroundDistance, GroundLayer))
{
soldierPos.y = hit.point.y;
unitPos.y = hit.point.y;
}
else
{

View File

@ -28,7 +28,7 @@ MonoBehaviour:
<SailorStatIdx>k__BackingField: ai_stat_sailor_e_004
<UnitName>k__BackingField: EnemySwordKnight001
<UnitType>k__BackingField: -1
<SailorCount>k__BackingField: 3
<SailorCount>k__BackingField: 11
<AttackerType>k__BackingField: 1
<OffenseType>k__BackingField: -1
<DefenseType>k__BackingField: 2

View File

@ -104,6 +104,20 @@ namespace BlueWaterProject
{
TargetAllList.Remove(element);
}
CleanupList(list);
CleanupList(TargetAllList);
}
private void CleanupList(List<Transform> list)
{
for (var i = list.Count - 1; i >= 0; i--)
{
if (list[i] == null || list[i].gameObject == null)
{
list.RemoveAt(i);
}
}
}
#endregion

View File

@ -8920,7 +8920,7 @@ Rigidbody:
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 155132}
serializedVersion: 4
m_Mass: 1
m_Mass: 100
m_Drag: 0
m_AngularDrag: 0.05
m_CenterOfMass: {x: 0, y: 0, z: 0}