2023-08-21 18:08:11 +00:00
|
|
|
using System.Collections.Generic;
|
|
|
|
using Sirenix.OdinInspector;
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
// ReSharper disable once CheckNamespace
|
|
|
|
namespace BlueWaterProject
|
|
|
|
{
|
|
|
|
public class IslandInfo : MonoBehaviour
|
|
|
|
{
|
|
|
|
#region Property and variable
|
|
|
|
|
|
|
|
[field: SerializeField] public string IslandName { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField] public List<Transform> HouseList { get; private set; }
|
|
|
|
|
2023-09-12 14:46:57 +00:00
|
|
|
[field: SerializeField] public List<EnemyUnit> UnitList { get; private set; }
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
[field: SerializeField] public List<Transform> EnemyList { get; private set; }
|
|
|
|
|
|
|
|
[field: SerializeField] public List<Transform> TargetAllList { get; private set; }
|
2023-09-11 07:16:02 +00:00
|
|
|
|
|
|
|
public IslandInfo()
|
|
|
|
{
|
|
|
|
IslandName = null;
|
|
|
|
HouseList = null;
|
|
|
|
UnitList = null;
|
|
|
|
EnemyList = null;
|
|
|
|
TargetAllList = null;
|
|
|
|
}
|
|
|
|
|
2023-09-12 14:46:57 +00:00
|
|
|
public IslandInfo(string islandName, List<Transform> houseList, List<EnemyUnit> unitList, List<Transform> enemyList, List<Transform> targetAllList)
|
2023-09-11 07:16:02 +00:00
|
|
|
{
|
|
|
|
IslandName = islandName;
|
|
|
|
HouseList = houseList;
|
|
|
|
UnitList = unitList;
|
|
|
|
EnemyList = enemyList;
|
|
|
|
TargetAllList = targetAllList;
|
|
|
|
}
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Unity built-in Function
|
|
|
|
|
|
|
|
private void Awake()
|
|
|
|
{
|
|
|
|
InitIslandInfo();
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Custom function
|
|
|
|
|
|
|
|
[GUIColor(0, 1, 0)]
|
|
|
|
[Button("섬 정보 추출")]
|
|
|
|
private void InitIslandInfo()
|
|
|
|
{
|
|
|
|
HouseList = new List<Transform>(5);
|
|
|
|
|
|
|
|
var houses = transform.Find("Houses");
|
2023-08-30 05:57:45 +00:00
|
|
|
|
|
|
|
if (houses)
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-08-30 05:57:45 +00:00
|
|
|
foreach (Transform house in houses)
|
|
|
|
{
|
|
|
|
if (!house.CompareTag("House") || !house.gameObject.activeSelf) continue;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
2023-08-30 05:57:45 +00:00
|
|
|
var houseInfo = house.GetComponent<HouseInfo>();
|
2023-09-04 07:31:04 +00:00
|
|
|
houseInfo.SetIslandInfo(this);
|
2023-08-30 05:57:45 +00:00
|
|
|
HouseList.Add(houseInfo.transform);
|
|
|
|
}
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
|
2023-09-12 14:46:57 +00:00
|
|
|
UnitList = new List<EnemyUnit>(20);
|
2023-08-21 18:08:11 +00:00
|
|
|
|
|
|
|
var units = transform.Find("Units");
|
2023-08-30 05:57:45 +00:00
|
|
|
|
|
|
|
if (units)
|
2023-08-21 18:08:11 +00:00
|
|
|
{
|
2023-08-30 05:57:45 +00:00
|
|
|
foreach (Transform unit in units)
|
|
|
|
{
|
|
|
|
if (!unit.CompareTag("Unit") || !unit.gameObject.activeSelf) continue;
|
2023-08-21 18:08:11 +00:00
|
|
|
|
2023-09-12 14:46:57 +00:00
|
|
|
UnitList.Add(unit.GetComponent<EnemyUnit>());
|
2023-08-30 05:57:45 +00:00
|
|
|
}
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
EnemyList = new List<Transform>(UnitList.Capacity * 16);
|
|
|
|
|
|
|
|
foreach (var unit in UnitList)
|
|
|
|
{
|
|
|
|
foreach (Transform enemy in unit.transform)
|
|
|
|
{
|
|
|
|
if (!unit.gameObject.activeSelf) continue;
|
|
|
|
|
2023-08-30 05:18:09 +00:00
|
|
|
//var aiController = enemy.GetComponent<AiController>();
|
|
|
|
//aiController.SetIslandInfo(this);
|
|
|
|
EnemyList.Add(enemy);
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
TargetAllList = new List<Transform>(HouseList.Capacity + EnemyList.Capacity);
|
|
|
|
|
|
|
|
foreach (var enemy in EnemyList)
|
|
|
|
{
|
|
|
|
TargetAllList.Add(enemy);
|
|
|
|
}
|
|
|
|
|
|
|
|
foreach (var house in HouseList)
|
|
|
|
{
|
|
|
|
TargetAllList.Add(house);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public void RemoveListElement(List<Transform> list, Transform element)
|
|
|
|
{
|
|
|
|
if (list.Contains(element))
|
|
|
|
{
|
|
|
|
list.Remove(element);
|
|
|
|
}
|
|
|
|
|
|
|
|
if (TargetAllList.Contains(element))
|
|
|
|
{
|
|
|
|
TargetAllList.Remove(element);
|
|
|
|
}
|
2023-09-11 03:41:02 +00:00
|
|
|
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
}
|
2023-08-21 18:08:11 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|