#28 유닛 생성 및 배치 방식 변경 테스트용(씬 병합)

This commit is contained in:
NTG_Lenovo 2023-08-30 14:18:09 +09:00
parent 4ed3453f3b
commit a8e34e4f3b
10 changed files with 121 additions and 153 deletions

View File

@ -6297,35 +6297,9 @@ MonoBehaviour:
<HouseList>k__BackingField:
- {fileID: 1128501715}
- {fileID: 1545632329}
<UnitList>k__BackingField:
- {fileID: 0}
- {fileID: 0}
<EnemyList>k__BackingField:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
<UnitList>k__BackingField: []
<EnemyList>k__BackingField: []
<TargetAllList>k__BackingField:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
- {fileID: 1128501715}
- {fileID: 1545632329}
--- !u!1001 &991516669
@ -8439,6 +8413,7 @@ MonoBehaviour:
- card_003
- card_004
- card_005
<IslandInfoList>k__BackingField: []
mouseSpot: {fileID: 0}
boat: {fileID: 0}
assaultCard: {fileID: 0}

View File

@ -70,6 +70,9 @@ namespace BlueWaterProject
[Tooltip("캐릭터가 선택되었을 때 색상")]
[SerializeField] protected Color selectedSkinColor = Color.blue;
[DisableIf("@true")]
[SerializeField] private IslandInfo islandInfo;
protected bool isAttacking;
private Vector3 commandedPos;
@ -82,7 +85,6 @@ namespace BlueWaterProject
protected Transform bodyContainer;
protected Transform flagContainer;
public IslandInfo IslandInfo { get; set; }
protected Animator aiAnimator;
protected NavMeshAgent navMeshAgent;
private UnitController myUnitController;
@ -122,20 +124,7 @@ namespace BlueWaterProject
private void Start()
{
InitStart();
switch (attackerType)
{
case AttackerType.NONE:
break;
case AttackerType.OFFENSE:
StartCoroutine(nameof(FindTargetInOffense));
break;
case AttackerType.DEFENSE:
StartCoroutine(nameof(FindTarget));
break;
default:
throw new ArgumentOutOfRangeException();
}
ExecuteFindTarget();
Attack();
}
@ -327,29 +316,29 @@ namespace BlueWaterProject
case OffenseType.NONE:
break;
case OffenseType.NORMAL:
if (IslandInfo.EnemyList.Count > 0)
if (islandInfo.EnemyList.Count > 0)
{
SetNearestTargetDestination(IslandInfo.EnemyList);
SetNearestTargetDestination(islandInfo.EnemyList);
}
else if (IslandInfo.HouseList.Count > 0)
else if (islandInfo.HouseList.Count > 0)
{
SetNearestTargetDestination(IslandInfo.HouseList);
SetNearestTargetDestination(islandInfo.HouseList);
}
break;
case OffenseType.ONLY_HOUSE:
if (navMeshAgent.pathStatus == NavMeshPathStatus.PathPartial)
{
SetNearestTargetDestination(IslandInfo.TargetAllList);
SetNearestTargetDestination(islandInfo.TargetAllList);
}
else
{
if (IslandInfo.HouseList.Count > 0)
if (islandInfo.HouseList.Count > 0)
{
SetNearestTargetDestination(IslandInfo.HouseList);
SetNearestTargetDestination(islandInfo.HouseList);
}
else if (IslandInfo.EnemyList.Count > 0)
else if (islandInfo.EnemyList.Count > 0)
{
SetNearestTargetDestination(IslandInfo.EnemyList);
SetNearestTargetDestination(islandInfo.EnemyList);
}
}
break;
@ -545,6 +534,23 @@ namespace BlueWaterProject
}
#endif
public void ExecuteFindTarget()
{
switch (attackerType)
{
case AttackerType.NONE:
break;
case AttackerType.OFFENSE:
StartCoroutine(nameof(FindTargetInOffense));
break;
case AttackerType.DEFENSE:
StartCoroutine(nameof(FindTarget));
break;
default:
throw new ArgumentOutOfRangeException();
}
}
private void SetActiveViewModel(Transform container, int model)
{
foreach (Transform item in container)
@ -592,7 +598,7 @@ namespace BlueWaterProject
protected virtual bool CanAttack()
{
if (!TargetTransform || !IslandInfo.TargetAllList.Contains(TargetTransform)) return false;
if (!TargetTransform || !islandInfo.TargetAllList.Contains(TargetTransform)) return false;
var targetInAttackRange = Vector3.Distance(transform.position, TargetTransform.position) <=
AiStat.AtkRange;
@ -637,9 +643,9 @@ namespace BlueWaterProject
private void RemoveIslandInfo()
{
if (!IslandInfo) return;
if (!islandInfo) return;
IslandInfo.RemoveListElement(IslandInfo.EnemyList, transform);
islandInfo.RemoveListElement(islandInfo.EnemyList, transform);
}
private void SetAgentIsStopped(bool value)
@ -676,6 +682,7 @@ namespace BlueWaterProject
}
}
public void SetIslandInfo(IslandInfo info) => islandInfo = info;
public void SetAttackerType(AttackerType type) => attackerType = type;
public void SetOffenseType(OffenseType type) => offenseType = type;
public void SetDefenseType(DefenseType type) => defenseType = type;

View File

@ -30,7 +30,6 @@ namespace BlueWaterProject
[field: Range(0, GlobalValue.ONE_UNIT_CAPACITY - 1)]
[field: SerializeField] public int SailorCount { get; set; }
[field: DisableIf("@true")]
[field: SerializeField] public AttackerType AttackerType { get; set; }
[field: SerializeField] public OffenseType OffenseType { get; set; }

View File

@ -8,11 +8,6 @@ namespace BlueWaterProject
public class UnitController : MonoBehaviour
{
#region Property and variable
[PropertyOrder(-11)]
[ShowIf("@unit.AttackerType == AttackerType.OFFENSE")]
//[InlineButton("SetIslandInfoTest", "테스트 설정")]
[SerializeField] private IslandInfo attackIslandInfo;
[PropertyOrder(-10)]
public Unit unit;
@ -26,23 +21,44 @@ namespace BlueWaterProject
private void OnDrawGizmosSelected()
{
if (unit == null || unit.SailorCount <= 0) return;
var gridSize = 0;
var unitManager = UnitManager.Inst != null ? UnitManager.Inst : FindObjectOfType<UnitManager>();
var matrix = unitManager.UnitMatrices.Find(um => um.units == unit.SailorCount);
if (matrix == null) return;
for (var i = 0; i < unit.SailorCount; i++)
switch (unit.SailorCount)
{
var row = i / matrix.columns;
var column = i % matrix.columns;
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;
var xOffset = (column - (matrix.columns - 1) / 2.0f) * unitManager.UnitSpacing;
var zOffset = (row - (matrix.rows - 1) / 2.0f) * unitManager.UnitSpacing;
var spawnPosition = transform.position + new Vector3(xOffset, 0, zOffset);
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.down);
Gizmos.color = Physics.Raycast(ray, unitManager.MaxGroundDistance, unitManager.GroundLayer) ? Color.blue : Color.red;
Gizmos.DrawRay(ray.origin, ray.direction * unitManager.MaxGroundDistance);
var ray = new Ray(spawnPosition, 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);
}
}
}
@ -62,14 +78,14 @@ namespace BlueWaterProject
[Button("유닛 생성")]
public void CreateUnit()
{
UnitManager.Inst.CreateUnit(this);
UnitManager.Inst.CreateUnitInEditor(this);
}
[PropertyOrder(-8)]
[HorizontalGroup("Split", 0.5f)]
[EnableIf("CanAssignUnit")]
[Button("유닛 배치")]
private void SetAssignUnitInScene()
private void SetAssignUnitInEditor()
{
if (UnitManager.Inst.CanAssignUnit(this, transform.position))
{
@ -101,24 +117,14 @@ namespace BlueWaterProject
[Button("유닛 초기화")]
private void ResetUnit()
{
unit = new Unit();
attackIslandInfo = null;
isClickedTypeAllButton = false;
}
[PropertyOrder(1)]
[GUIColor("GetTypeAllButtonColor")]
//[ShowIf("ShowTypeAllButton")]
[Button("타입 모두 적용")]
private void SetTypeAll()
{
foreach (var soldier in unit.UnitList)
var tempUnitIdx = unit.Idx;
UnitManager.Inst.DestroyDeployedUnits(this);
unit = new Unit
{
soldier.SetOffenseType(unit.OffenseType);
soldier.SetDefenseType(unit.DefenseType);
}
isClickedTypeAllButton = true;
Idx = tempUnitIdx
};
isClickedTypeAllButton = false;
}
public void MoveCommand(Vector3 targetPos)
@ -129,56 +135,9 @@ namespace BlueWaterProject
}
}
// private void SetIslandInfoTest()
// {
// if (unit.AttackerType != AttackerType.OFFENSE) return;
//
// var islandInfo = FindObjectOfType<IslandInfo>();
// attackIslandInfo = islandInfo;
//
// foreach (var soldier in unit.UnitList)
// {
// soldier.IslandInfo = attackIslandInfo;
// }
// }
// private bool ShowTypeAllButton()
// {
// switch (unit.AttackerType)
// {
// case AttackerType.NONE:
// return false;
// case AttackerType.OFFENSE:
// if (unit.OffenseType == OffenseType.NONE)
// {
// return false;
// }
// break;
// case AttackerType.DEFENSE:
// if (unit.DefenseType == DefenseType.NONE)
// {
// return false;
// }
// break;
// default:
// throw new ArgumentOutOfRangeException();
// }
//
// return true;
// }
private Color GetCreateUnitButtonColor() => unit.UnitList.Count > 0 ? Color.white : Color.green;
// private Color GetAttackerTypeButtonColor()
// {
// if (unit.UnitList.Count > 0)
// {
// return unit.AttackerType == AttackerType.NONE ? Color.green : Color.white;
// }
//
// return Color.white;
// }
private Color GetTypeAllButtonColor() => isClickedTypeAllButton ? Color.white : Color.green;
private void OnTypeChanged() => isClickedTypeAllButton = false;
//public void SetAttackerType(AttackerType value) => unit.AttackerType = value;
#endregion
}

View File

@ -263,8 +263,8 @@ namespace BlueWaterProject
if (currentPos > newUnitController.unit.SailorCount) break;
var xOffset = (i - (gridSize - 1) / 2.0f) * UnitSpacing;
var zOffset = (j - (gridSize - 1) / 2.0f) * UnitSpacing;
var zOffset = (i - (gridSize - 1) / 2.0f) * UnitSpacing;
var xOffset = (j - (gridSize - 1) / 2.0f) * UnitSpacing;
var spawnPosition = unitControllerTransform.position + new Vector3(xOffset, 0, zOffset);
var baseObj = Instantiate(BaseCharacterPrefab, spawnPosition,
@ -287,7 +287,7 @@ namespace BlueWaterProject
/// <summary>
/// 에디터용 부대 생성 함수
/// </summary>
public void CreateUnit(UnitController unitController)
public void CreateUnitInEditor(UnitController unitController)
{
var unit = DataManager.Inst.GetUnitSoKey(unitController.unit.Idx);
@ -340,8 +340,8 @@ namespace BlueWaterProject
if (currentPos > unitController.unit.SailorCount) break;
var xOffset = (i - (gridSize - 1) / 2.0f) * UnitSpacing;
var zOffset = (j - (gridSize - 1) / 2.0f) * UnitSpacing;
var zOffset = (i - (gridSize - 1) / 2.0f) * UnitSpacing;
var xOffset = (j - (gridSize - 1) / 2.0f) * UnitSpacing;
var spawnPosition = unitControllerTransform.position + new Vector3(xOffset, 0, zOffset);
var baseObj = Instantiate(BaseCharacterPrefab, spawnPosition,
@ -440,6 +440,15 @@ namespace BlueWaterProject
unitController.transform.position = assignPos;
foreach (var item in unitController.unit.UnitList)
{
var myPos = item.transform.position;
var ray = new Ray(myPos, Vector3.down);
if (Physics.Raycast(ray, out var hit, MaxGroundDistance, GroundLayer))
{
item.transform.position = new Vector3(myPos.x, hit.point.y, myPos.z);
var hitIslandInfo = hit.transform.root.GetComponent<IslandInfo>();
item.SetIslandInfo(hitIslandInfo);
}
item.SetAttackerType(unitController.unit.AttackerType);
item.gameObject.SetActive(true);
}
}
@ -447,7 +456,7 @@ namespace BlueWaterProject
/// <summary>
/// 기존에 생성된 부대 병력들이 있으면 확인해서 삭제해주는 함수
/// </summary>
private void DestroyDeployedUnits(UnitController unitController)
public void DestroyDeployedUnits(UnitController unitController)
{
if (unitController.transform.childCount <= 0) return;

View File

@ -83,3 +83,13 @@ MonoBehaviour:
<OffenseType>k__BackingField: 0
<DefenseType>k__BackingField: -1
<UnitList>k__BackingField: []
- <Idx>k__BackingField: unit_archer_e_001
<CaptainStatIdx>k__BackingField: ai_stat_captain_e_001
<SailorStatIdx>k__BackingField: ai_stat_sailor_e_001
<UnitName>k__BackingField: Enemy001
<UnitType>k__BackingField: 5
<SailorCount>k__BackingField: 6
<AttackerType>k__BackingField: -1
<OffenseType>k__BackingField: 0
<DefenseType>k__BackingField: -1
<UnitList>k__BackingField: []

View File

@ -7,6 +7,6 @@ namespace BlueWaterProject
[CreateAssetMenu(fileName = "UnitDataSo", menuName = "ScriptableObjects/UnitData", order = 2)]
public class UnitDataSo : ScriptableObject
{
public List<Unit> unitDataList = new(GlobalValue.UNIT_CAPACITY);
public List<Unit> unitDataList = new(GlobalValue.UNIT_DATA_CAPACITY);
}
}

View File

@ -21,6 +21,7 @@ public class DataManager : Singleton<DataManager>
[field: Title("DataBase")]
[field: SerializeField] public List<string> CardList { get; private set; } = new(GlobalValue.CARD_DATA_CAPACITY);
[field: SerializeField] public List<IslandInfo> IslandInfoList { get; private set; } = new(GlobalValue.ISLAND_DATA_CAPACITY);
[Title("DataBase", "GameObject")]
public GameObject mouseSpot;
@ -33,15 +34,15 @@ public class DataManager : Singleton<DataManager>
protected override void OnAwake()
{
InitDictionary();
InitCard();
InitIslandInfo();
}
private void InitDictionary()
{
aiViewDictionary = CreateDictionaryFromList(AiViewDataSo.aiViewDataList, GlobalValue.AI_VIEW_DATA_CAPACITY);
aiStatDictionary = CreateDictionaryFromList(AiStatDataSo.aiStatDataList, GlobalValue.AI_STAT_DATA_CAPACITY);
unitDictionary = CreateDictionaryFromList(UnitDataSo.unitDataList, GlobalValue.UNIT_CAPACITY);
unitDictionary = CreateDictionaryFromList(UnitDataSo.unitDataList, GlobalValue.UNIT_DATA_CAPACITY);
cardDictionary = CreateDictionaryFromList(CardDataSo.cardDataList, GlobalValue.CARD_DATA_CAPACITY);
}
@ -52,6 +53,13 @@ public class DataManager : Singleton<DataManager>
UnitManager.Inst.CreateUnit(item, AttackerType.OFFENSE);
}
}
private void InitIslandInfo()
{
var islandInfos = FindObjectsOfType<IslandInfo>();
IslandInfoList.AddRange(islandInfos);
}
/// <summary>
/// Dictionary 초기화 함수

View File

@ -66,9 +66,9 @@ namespace BlueWaterProject
{
if (!unit.gameObject.activeSelf) continue;
var aiController = enemy.GetComponent<AiController>();
aiController.IslandInfo = this;
EnemyList.Add(aiController.transform);
//var aiController = enemy.GetComponent<AiController>();
//aiController.SetIslandInfo(this);
EnemyList.Add(enemy);
}
}

View File

@ -3,7 +3,8 @@ public class GlobalValue
public const int CARD_DATA_CAPACITY = 50;
public const int AI_VIEW_DATA_CAPACITY = 50;
public const int AI_STAT_DATA_CAPACITY = 50;
public const int UNIT_CAPACITY = 50;
public const int UNIT_DATA_CAPACITY = 50;
public const int ISLAND_DATA_CAPACITY = 50;
public const int ONE_UNIT_CAPACITY = 16;
public const int AI_ANIMATOR_CAPACITY = 10;