From a8e34e4f3bd0869eed2fdc65d36a245073e1d6a8 Mon Sep 17 00:00:00 2001 From: NTG_Lenovo Date: Wed, 30 Aug 2023 14:18:09 +0900 Subject: [PATCH] =?UTF-8?q?#28=20=EC=9C=A0=EB=8B=9B=20=EC=83=9D=EC=84=B1?= =?UTF-8?q?=20=EB=B0=8F=20=EB=B0=B0=EC=B9=98=20=EB=B0=A9=EC=8B=9D=20?= =?UTF-8?q?=EB=B3=80=EA=B2=BD=20=ED=85=8C=EC=8A=A4=ED=8A=B8=EC=9A=A9(?= =?UTF-8?q?=EC=94=AC=20=EB=B3=91=ED=95=A9)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- BlueWater/Assets/01.Scenes/02.Main_TG2.unity | 31 +---- .../Assets/02.Scripts/Ai/AiController.cs | 61 +++++---- BlueWater/Assets/02.Scripts/Ai/Unit/Unit.cs | 1 - .../02.Scripts/Ai/Unit/UnitController.cs | 127 ++++++------------ .../Assets/02.Scripts/Ai/Unit/UnitManager.cs | 21 ++- .../02.Scripts/Data/So/UnitDataSo.asset | 10 ++ .../Assets/02.Scripts/Data/UnitDataSo.cs | 2 +- BlueWater/Assets/02.Scripts/DataManager.cs | 12 +- BlueWater/Assets/02.Scripts/IslandInfo.cs | 6 +- .../Assets/02.Scripts/Utility/GlobalValue.cs | 3 +- 10 files changed, 121 insertions(+), 153 deletions(-) diff --git a/BlueWater/Assets/01.Scenes/02.Main_TG2.unity b/BlueWater/Assets/01.Scenes/02.Main_TG2.unity index 261ec6bc5..b334a0f12 100644 --- a/BlueWater/Assets/01.Scenes/02.Main_TG2.unity +++ b/BlueWater/Assets/01.Scenes/02.Main_TG2.unity @@ -6297,35 +6297,9 @@ MonoBehaviour: k__BackingField: - {fileID: 1128501715} - {fileID: 1545632329} - k__BackingField: - - {fileID: 0} - - {fileID: 0} - 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} + k__BackingField: [] + k__BackingField: [] 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 + k__BackingField: [] mouseSpot: {fileID: 0} boat: {fileID: 0} assaultCard: {fileID: 0} diff --git a/BlueWater/Assets/02.Scripts/Ai/AiController.cs b/BlueWater/Assets/02.Scripts/Ai/AiController.cs index 6e76ae97a..0820b32e6 100644 --- a/BlueWater/Assets/02.Scripts/Ai/AiController.cs +++ b/BlueWater/Assets/02.Scripts/Ai/AiController.cs @@ -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; diff --git a/BlueWater/Assets/02.Scripts/Ai/Unit/Unit.cs b/BlueWater/Assets/02.Scripts/Ai/Unit/Unit.cs index bb3a507cc..8b069a51e 100644 --- a/BlueWater/Assets/02.Scripts/Ai/Unit/Unit.cs +++ b/BlueWater/Assets/02.Scripts/Ai/Unit/Unit.cs @@ -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; } diff --git a/BlueWater/Assets/02.Scripts/Ai/Unit/UnitController.cs b/BlueWater/Assets/02.Scripts/Ai/Unit/UnitController.cs index 88f74e6b8..b519a501e 100644 --- a/BlueWater/Assets/02.Scripts/Ai/Unit/UnitController.cs +++ b/BlueWater/Assets/02.Scripts/Ai/Unit/UnitController.cs @@ -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(); - 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(); - // 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 } diff --git a/BlueWater/Assets/02.Scripts/Ai/Unit/UnitManager.cs b/BlueWater/Assets/02.Scripts/Ai/Unit/UnitManager.cs index 2c070d24a..89c2945c5 100644 --- a/BlueWater/Assets/02.Scripts/Ai/Unit/UnitManager.cs +++ b/BlueWater/Assets/02.Scripts/Ai/Unit/UnitManager.cs @@ -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 /// /// 에디터용 부대 생성 함수 /// - 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(); + item.SetIslandInfo(hitIslandInfo); + } + item.SetAttackerType(unitController.unit.AttackerType); item.gameObject.SetActive(true); } } @@ -447,7 +456,7 @@ namespace BlueWaterProject /// /// 기존에 생성된 부대 병력들이 있으면 확인해서 삭제해주는 함수 /// - private void DestroyDeployedUnits(UnitController unitController) + public void DestroyDeployedUnits(UnitController unitController) { if (unitController.transform.childCount <= 0) return; diff --git a/BlueWater/Assets/02.Scripts/Data/So/UnitDataSo.asset b/BlueWater/Assets/02.Scripts/Data/So/UnitDataSo.asset index d37ba49aa..e47f2e550 100644 --- a/BlueWater/Assets/02.Scripts/Data/So/UnitDataSo.asset +++ b/BlueWater/Assets/02.Scripts/Data/So/UnitDataSo.asset @@ -83,3 +83,13 @@ MonoBehaviour: k__BackingField: 0 k__BackingField: -1 k__BackingField: [] + - k__BackingField: unit_archer_e_001 + k__BackingField: ai_stat_captain_e_001 + k__BackingField: ai_stat_sailor_e_001 + k__BackingField: Enemy001 + k__BackingField: 5 + k__BackingField: 6 + k__BackingField: -1 + k__BackingField: 0 + k__BackingField: -1 + k__BackingField: [] diff --git a/BlueWater/Assets/02.Scripts/Data/UnitDataSo.cs b/BlueWater/Assets/02.Scripts/Data/UnitDataSo.cs index e04a9b02d..8b6f65a16 100644 --- a/BlueWater/Assets/02.Scripts/Data/UnitDataSo.cs +++ b/BlueWater/Assets/02.Scripts/Data/UnitDataSo.cs @@ -7,6 +7,6 @@ namespace BlueWaterProject [CreateAssetMenu(fileName = "UnitDataSo", menuName = "ScriptableObjects/UnitData", order = 2)] public class UnitDataSo : ScriptableObject { - public List unitDataList = new(GlobalValue.UNIT_CAPACITY); + public List unitDataList = new(GlobalValue.UNIT_DATA_CAPACITY); } } \ No newline at end of file diff --git a/BlueWater/Assets/02.Scripts/DataManager.cs b/BlueWater/Assets/02.Scripts/DataManager.cs index 31c035d20..8c5160def 100644 --- a/BlueWater/Assets/02.Scripts/DataManager.cs +++ b/BlueWater/Assets/02.Scripts/DataManager.cs @@ -21,6 +21,7 @@ public class DataManager : Singleton [field: Title("DataBase")] [field: SerializeField] public List CardList { get; private set; } = new(GlobalValue.CARD_DATA_CAPACITY); + [field: SerializeField] public List IslandInfoList { get; private set; } = new(GlobalValue.ISLAND_DATA_CAPACITY); [Title("DataBase", "GameObject")] public GameObject mouseSpot; @@ -33,15 +34,15 @@ public class DataManager : Singleton 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 UnitManager.Inst.CreateUnit(item, AttackerType.OFFENSE); } } + + private void InitIslandInfo() + { + var islandInfos = FindObjectsOfType(); + + IslandInfoList.AddRange(islandInfos); + } /// /// Dictionary 초기화 함수 diff --git a/BlueWater/Assets/02.Scripts/IslandInfo.cs b/BlueWater/Assets/02.Scripts/IslandInfo.cs index 3a7866628..0601231a4 100644 --- a/BlueWater/Assets/02.Scripts/IslandInfo.cs +++ b/BlueWater/Assets/02.Scripts/IslandInfo.cs @@ -66,9 +66,9 @@ namespace BlueWaterProject { if (!unit.gameObject.activeSelf) continue; - var aiController = enemy.GetComponent(); - aiController.IslandInfo = this; - EnemyList.Add(aiController.transform); + //var aiController = enemy.GetComponent(); + //aiController.SetIslandInfo(this); + EnemyList.Add(enemy); } } diff --git a/BlueWater/Assets/02.Scripts/Utility/GlobalValue.cs b/BlueWater/Assets/02.Scripts/Utility/GlobalValue.cs index 3bcebdde2..be39ea902 100644 --- a/BlueWater/Assets/02.Scripts/Utility/GlobalValue.cs +++ b/BlueWater/Assets/02.Scripts/Utility/GlobalValue.cs @@ -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;