From bbb51d50bf10b30eb32a38938f4369d5d2b3ccbe Mon Sep 17 00:00:00 2001 From: Kim Taebum <39542671+scarleter99@users.noreply.github.com> Date: Sat, 23 Mar 2024 17:14:04 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20Animcontroller=20=EA=B0=9C=EC=84=A0=20&?= =?UTF-8?q?=20Alien=EC=97=90=EA=B2=8C=20Skill=ED=95=A0=EB=8B=B9=20(#19)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * Stalker 클래스 추가 * Tag 변경 * Alien 베이스 코드 구현 * 카메라 렌더링을 위한 layer 변경 코드 추가 * 프리팹 수정 * 안쓰는 코드 제거 * Alien Scale 수정 * CreatureType별 카메라 위치 수정 * feat: Animcontroller 개선 & Alien에게 Skill할당 --- .../Resources/Prefabs/Aliens/Stalker.prefab | 12 ++-- .../AnimController/AlienAnimController.cs | 7 +- .../AnimController/BaseAnimController.cs | 19 ----- .../AnimController/CrewAnimController.cs | 13 ++-- .../Assets/Scripts/Contents/Item/BaseItem.cs | 9 ++- .../Assets/Scripts/Contents/Item/Battery.cs | 8 ++- .../Interactable/ItemObject/BaseItemObject.cs | 2 +- .../Map/Interactable/WorkStation/Computer.cs | 4 +- .../Scripts/Contents/Skill/BaseSkill.cs | 9 ++- .../Skill/{AlienSkill.cs => BasicAttack.cs} | 14 ++-- ...AlienSkill.cs.meta => BasicAttack.cs.meta} | 0 Client/Assets/Scripts/Controllers/Alien.cs | 70 +++++++++++++++---- Client/Assets/Scripts/Controllers/Creature.cs | 40 +++++------ Client/Assets/Scripts/Controllers/Crew.cs | 52 +++++++++++--- .../Assets/Scripts/Controllers/Inventory.cs | 22 +++--- Client/Assets/Scripts/Controllers/Stalker.cs | 6 +- Client/Assets/Scripts/Utils/Define.cs | 16 +---- 17 files changed, 181 insertions(+), 122 deletions(-) rename Client/Assets/Scripts/Contents/Skill/{AlienSkill.cs => BasicAttack.cs} (82%) rename Client/Assets/Scripts/Contents/Skill/{AlienSkill.cs.meta => BasicAttack.cs.meta} (100%) diff --git a/Client/Assets/Resources/Prefabs/Aliens/Stalker.prefab b/Client/Assets/Resources/Prefabs/Aliens/Stalker.prefab index 4181557e81..a6c382352d 100644 --- a/Client/Assets/Resources/Prefabs/Aliens/Stalker.prefab +++ b/Client/Assets/Resources/Prefabs/Aliens/Stalker.prefab @@ -1033,7 +1033,7 @@ GameObject: - component: {fileID: 2656646541101528400} - component: {fileID: 8848567419615919483} - component: {fileID: 6976675480461094696} - - component: {fileID: 5652327032334742129} + - component: {fileID: 2516994780171337258} - component: {fileID: 4476358356948161216} - component: {fileID: 9205723220890699314} m_Layer: 0 @@ -1150,7 +1150,7 @@ MonoBehaviour: NetworkedBehaviours: - {fileID: 8848567419615919483} - {fileID: 6976675480461094696} - - {fileID: 5652327032334742129} + - {fileID: 2516994780171337258} - {fileID: 4476358356948161216} - {fileID: 9205723220890699314} --- !u!114 &8848567419615919483 @@ -1166,11 +1166,11 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: Animator: {fileID: 8694943018821805677} - TotalWords: 3 + TotalWords: 0 ApplyTiming: 2 SyncSettings: 79 StateHashes: 00000000d60d65cf5b3f1ae1d6355d2351b741b83a14ae2622bf60df2bd9750c36deb24b9ce643ab657fb9ed1bb7b90b53d5474c0077695bdedc2838fcb625b6dd0602721fe5045ddfd244252afa8626a8b5caa3b8bdf7198b0ed22e3bc588839e816f3ce79b5e0ed4287b39d9d2b9c97c965e76d6fae0b873be0707fe1d2bbc107fe3c9aba58e3a69d74f9854e61c148a4d5d771636ac3c0b316b7b2c1396569ce229085c803cfbf9c4db4487810b6969e3c31cc19586d5db04bc3f8c16c1802952263f2a8f6f1bc14ce7e604898d4c27398eeaba3676e238793a6700677f7b822833fe20e23b685928a8cea68c4ffde5227cfe2210f8a511a3dd9230482cdaf23aed786d421c22c806fb9dfd9b008e13f9c8fb6bd5a32d398fdc04805553ef04768500 - TriggerHashes: 000000003b2dc047 + TriggerHashes: 00000000 --- !u!114 &6976675480461094696 MonoBehaviour: m_ObjectHideFlags: 0 @@ -1206,7 +1206,7 @@ MonoBehaviour: StepRequireGroundTarget: 0 SnapDistance: 0.25 SnapSpeed: 4 ---- !u!114 &5652327032334742129 +--- !u!114 &2516994780171337258 MonoBehaviour: m_ObjectHideFlags: 0 m_CorrespondingSourceObject: {fileID: 0} @@ -1215,7 +1215,7 @@ MonoBehaviour: m_GameObject: {fileID: 8694943018831287373} m_Enabled: 1 m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: 22d7dd4b10554c359084716773cb6f10, type: 3} + m_Script: {fileID: 11500000, guid: 430d34e7eabc46ba86caccfe28e7476b, type: 3} m_Name: m_EditorClassIdentifier: _DataId: 0 diff --git a/Client/Assets/Scripts/Contents/AnimController/AlienAnimController.cs b/Client/Assets/Scripts/Contents/AnimController/AlienAnimController.cs index a7d679ec25..cae82ada88 100644 --- a/Client/Assets/Scripts/Contents/AnimController/AlienAnimController.cs +++ b/Client/Assets/Scripts/Contents/AnimController/AlienAnimController.cs @@ -29,16 +29,11 @@ protected override void PlayMove() } } - protected override void PlayInteract() + public void PlayUseSkill1() { SetTrigger("attack"); Debug.Log("Alien PlayInteract anim called"); } - protected override void PlayDead() - { - // TODO - } - #endregion } diff --git a/Client/Assets/Scripts/Contents/AnimController/BaseAnimController.cs b/Client/Assets/Scripts/Contents/AnimController/BaseAnimController.cs index 2fd82f00fa..28978db8f4 100644 --- a/Client/Assets/Scripts/Contents/AnimController/BaseAnimController.cs +++ b/Client/Assets/Scripts/Contents/AnimController/BaseAnimController.cs @@ -35,12 +35,6 @@ public void UpdateAnimation() case Define.CreatureState.Move: PlayMove(); break; - case Define.CreatureState.Interact: - PlayInteract(); - break; - case Define.CreatureState.Dead: - PlayDead(); - break; } } @@ -52,23 +46,10 @@ protected virtual void PlayMove() { } - protected virtual void PlayInteract() - { - } - - protected virtual void PlayDead() - { - } - #endregion #region SetParameter - protected void SetParameter() - { - - } - protected void SetTrigger(string parameter) { NetworkAnim.SetTrigger("IsRunning"); diff --git a/Client/Assets/Scripts/Contents/AnimController/CrewAnimController.cs b/Client/Assets/Scripts/Contents/AnimController/CrewAnimController.cs index 930422703c..c88cc09d9b 100644 --- a/Client/Assets/Scripts/Contents/AnimController/CrewAnimController.cs +++ b/Client/Assets/Scripts/Contents/AnimController/CrewAnimController.cs @@ -3,8 +3,8 @@ public class CrewAnimController : BaseAnimController { - public float SitDown { get; protected set; } - public float SitSpeedParameter { get; protected set; } + [Networked] public float SitDown { get; protected set; } + [Networked] public float SitSpeedParameter { get; protected set; } protected override void Init() { @@ -73,12 +73,17 @@ protected override void PlayMove() } } - protected override void PlayInteract() + public void PlayInteract() { // TODO } - protected override void PlayDead() + public void PlayUseItem() + { + // TODO + } + + public void PlayDead() { // TODO } diff --git a/Client/Assets/Scripts/Contents/Item/BaseItem.cs b/Client/Assets/Scripts/Contents/Item/BaseItem.cs index ae2cf3cbb2..6295fc03f9 100644 --- a/Client/Assets/Scripts/Contents/Item/BaseItem.cs +++ b/Client/Assets/Scripts/Contents/Item/BaseItem.cs @@ -1,12 +1,11 @@ using Fusion; -public class BaseItem +public abstract class BaseItem { public Crew Owner { get; set; } - [Rpc(RpcSources.StateAuthority, RpcTargets.All)] - public virtual void Rpc_Use() - { + public abstract bool CheckAndUseItem(); - } + [Rpc(RpcSources.StateAuthority, RpcTargets.All)] + protected abstract void Rpc_Use(); } diff --git a/Client/Assets/Scripts/Contents/Item/Battery.cs b/Client/Assets/Scripts/Contents/Item/Battery.cs index 555f306202..50166fd05f 100644 --- a/Client/Assets/Scripts/Contents/Item/Battery.cs +++ b/Client/Assets/Scripts/Contents/Item/Battery.cs @@ -2,8 +2,14 @@ public class Battery : BaseItem { + public override bool CheckAndUseItem() + { + Rpc_Use(); + return true; + } + [Rpc(RpcSources.StateAuthority, RpcTargets.All)] - public override void Rpc_Use() + protected override void Rpc_Use() { } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs b/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs index 6e215d9c80..3388d46066 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs @@ -13,6 +13,6 @@ public override void Spawned() public void Interact(Creature creature) { - creature.Inventory.Rpc_CheckAndGetItem(ItemType); + ((Crew)creature).Inventory.CheckAndGetItem(ItemType); } } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs index a838f27786..b24be0aedb 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs @@ -21,7 +21,7 @@ protected override IEnumerator ProgressWork() while (WorkProgress < _requiredWorkAmount && !IsCompleted) { - if (_workingCreature.Velocity.magnitude >= 1f) + if (_workingCreature.CreatureState != Define.CreatureState.Interact) { Interrupt(); } @@ -37,7 +37,7 @@ protected override IEnumerator ProgressWork() tempworkamount = WorkProgress; } ///////////////// - + yield return null; } diff --git a/Client/Assets/Scripts/Contents/Skill/BaseSkill.cs b/Client/Assets/Scripts/Contents/Skill/BaseSkill.cs index b7e0054d06..7f8da21109 100644 --- a/Client/Assets/Scripts/Contents/Skill/BaseSkill.cs +++ b/Client/Assets/Scripts/Contents/Skill/BaseSkill.cs @@ -1,13 +1,12 @@ using Fusion; -public class BaseSkill +public abstract class BaseSkill { public Alien Owner { get; set; } - [Rpc(RpcSources.StateAuthority, RpcTargets.All)] - public virtual void Rpc_Use() - { + public abstract bool CheckAndUseSkill(); - } + [Rpc(RpcSources.StateAuthority, RpcTargets.All)] + public abstract void Rpc_UseSkill(); } diff --git a/Client/Assets/Scripts/Contents/Skill/AlienSkill.cs b/Client/Assets/Scripts/Contents/Skill/BasicAttack.cs similarity index 82% rename from Client/Assets/Scripts/Contents/Skill/AlienSkill.cs rename to Client/Assets/Scripts/Contents/Skill/BasicAttack.cs index 5e342fd28c..bbb451106c 100644 --- a/Client/Assets/Scripts/Contents/Skill/AlienSkill.cs +++ b/Client/Assets/Scripts/Contents/Skill/BasicAttack.cs @@ -1,14 +1,18 @@ using Fusion; -using System.Buffers; using UnityEngine; -public class AlienSkill : BaseSkill +public class BasicAttack : BaseSkill { - [SerializeField] private float attackRange = 2f; // 근접 공격 범위 + private float attackRange = 2f; // 근접 공격 범위 - [Rpc(RpcSources.StateAuthority, RpcTargets.All)] + public override bool CheckAndUseSkill() + { + Rpc_UseSkill(); + return true; + } - public override void Rpc_Use() + [Rpc(RpcSources.StateAuthority, RpcTargets.All)] + public override void Rpc_UseSkill() { try { diff --git a/Client/Assets/Scripts/Contents/Skill/AlienSkill.cs.meta b/Client/Assets/Scripts/Contents/Skill/BasicAttack.cs.meta similarity index 100% rename from Client/Assets/Scripts/Contents/Skill/AlienSkill.cs.meta rename to Client/Assets/Scripts/Contents/Skill/BasicAttack.cs.meta diff --git a/Client/Assets/Scripts/Controllers/Alien.cs b/Client/Assets/Scripts/Controllers/Alien.cs index 5ddb9d44e9..ebef534ff2 100644 --- a/Client/Assets/Scripts/Controllers/Alien.cs +++ b/Client/Assets/Scripts/Controllers/Alien.cs @@ -1,13 +1,16 @@ +using System.Collections.Generic; using UnityEngine; using Data; -public class Alien : Creature +public abstract class Alien : Creature { #region Field public AlienData AlienData => CreatureData as AlienData; public AlienStat AlienStat => (AlienStat)BaseStat; + public List Skills { get; protected set; } + #endregion public override void SetInfo(int templateID) @@ -18,16 +21,59 @@ public override void SetInfo(int templateID) base.SetInfo(templateID); AlienStat.SetStat(AlienData); + + Skills = new List(); } protected override void HandleInput() { base.HandleInput(); + if (Input.GetKeyDown(KeyCode.F)) + { + if (CheckInteract(false)) + { + CreatureState = Define.CreatureState.Interact; + return; + } + } + else + CheckInteract(true); + if (Input.GetMouseButtonDown(0)) { - UseSkill(1); - return; + if (CheckAndUseSkill(0)) + { + CreatureState = Define.CreatureState.Use; + return; + } + } + + if (Input.GetMouseButtonDown(1)) + { + if (CheckAndUseSkill(1)) + { + CreatureState = Define.CreatureState.Use; + return; + } + } + + if (Input.GetKeyDown(KeyCode.Q)) + { + if (CheckAndUseSkill(2)) + { + CreatureState = Define.CreatureState.Use; + return; + } + } + + if (Input.GetKeyDown(KeyCode.R)) + { + if (CheckAndUseSkill(3)) + { + CreatureState = Define.CreatureState.Use; + return; + } } if (Velocity == Vector3.zero) @@ -110,16 +156,14 @@ protected override void UpdateDead() #endregion - #region Interact - - protected virtual bool UseSkill(int skillNum) + protected bool CheckAndUseSkill(int skillIdx) { - return false; - } - - #endregion - - #region Event + if (Skills[skillIdx] == null) + { + Debug.Log("No SKill" + skillIdx); + return false; + } - #endregion + return Skills[skillIdx].CheckAndUseSkill(); + } } diff --git a/Client/Assets/Scripts/Controllers/Creature.cs b/Client/Assets/Scripts/Controllers/Creature.cs index dde62cbee6..46ec146953 100644 --- a/Client/Assets/Scripts/Controllers/Creature.cs +++ b/Client/Assets/Scripts/Controllers/Creature.cs @@ -1,6 +1,7 @@ using UnityEngine; using Fusion; using Fusion.Addons.SimpleKCC; +using Data; public abstract class Creature : NetworkBehaviour { @@ -17,10 +18,9 @@ public abstract class Creature : NetworkBehaviour public SimpleKCC KCC { get; protected set; } public BaseStat BaseStat { get; protected set; } public BaseAnimController BaseAnimController { get; protected set; } - public Inventory Inventory { get; protected set; } [Networked] public int DataId { get; set; } - public Data.CreatureData CreatureData { get; protected set; } + public CreatureData CreatureData { get; protected set; } [Networked] public Define.CreatureType CreatureType { get; set; } [Networked] public Define.CreatureState CreatureState { get; set; } @@ -45,7 +45,6 @@ protected virtual void Init() BaseStat = gameObject.GetComponent(); BaseAnimController = gameObject.GetComponent(); - Inventory = gameObject.GetComponent(); } public virtual void SetInfo(int templateID) @@ -132,7 +131,6 @@ protected virtual void HandleInput() if (IsFirstPersonView) { - Quaternion cameraRotationY = Quaternion.Euler(0, CreatureCamera.transform.rotation.eulerAngles.y, 0); Velocity = cameraRotationY * new Vector3(Input.GetAxis("Horizontal"), 0, Input.GetAxis("Vertical")) * (BaseStat.Speed * Runner.DeltaTime); } @@ -174,29 +172,31 @@ protected void UpdateByState() #endregion - #region Interact - - protected bool RayCast() + protected bool CheckInteract(bool isCheck) { Ray ray = CreatureCamera.GetComponent().ViewportPointToRay(Vector3.one * 0.5f); - Debug.DrawRay(ray.origin, ray.direction * 1.5f, Color.red, 1f); // TODO - Test Code - if (!Physics.Raycast(ray, out RaycastHit rayHit, maxDistance:1.5f, layerMask:LayerMask.GetMask("MapObject"))) + if (Physics.Raycast(ray, out RaycastHit rayHit, maxDistance:1.5f, layerMask:LayerMask.GetMask("MapObject"))) { - Debug.Log("Failed to interact - Raycast failed"); - return false; + if (rayHit.transform.gameObject.TryGetComponent(out IInteractable interactable)) + { + if (!isCheck) + { + Debug.Log("CheckInteract"); + interactable.Interact(this); + Debug.DrawRay(ray.origin, ray.direction * 1.5f, Color.green, 1f); + + return true; + } + else + { + // TODO - Interact UI 출력 + } + } } - if (rayHit.transform.gameObject.TryGetComponent(out IInteractable interactable)) - { - CreatureState = Define.CreatureState.Interact; - interactable.Interact(this); - return true; - } + Debug.DrawRay(ray.origin, ray.direction * 1.5f, Color.red); - Debug.Log("Failed to interact - no IInteractable component"); return false; } - - #endregion } diff --git a/Client/Assets/Scripts/Controllers/Crew.cs b/Client/Assets/Scripts/Controllers/Crew.cs index 412fe965e8..adabf226af 100644 --- a/Client/Assets/Scripts/Controllers/Crew.cs +++ b/Client/Assets/Scripts/Controllers/Crew.cs @@ -1,5 +1,6 @@ using UnityEngine; using Data; +using Fusion; public class Crew : Creature { @@ -7,7 +8,10 @@ public class Crew : Creature public CrewData CrewData => CreatureData as CrewData; public CrewStat CrewStat => (CrewStat)BaseStat; - public bool IsRecoveringStamina { get; protected set; } + + public Inventory Inventory { get; protected set; } + + [Networked] public bool IsRecoveringStamina { get; protected set; } #endregion @@ -19,9 +23,12 @@ public override void SetInfo(int templateID) base.SetInfo(templateID); CrewStat.SetStat(CrewData); + + Inventory = gameObject.GetComponent(); + IsRecoveringStamina = true; + //UICrewStatus = FindObjectOfType(); //UICrewStatus.CurrentCrew = this; - IsRecoveringStamina = true; } public override void FixedUpdateNetwork() @@ -38,17 +45,35 @@ protected override void HandleInput() if (CreatureState == Define.CreatureState.Dead) return; + // TODO - Test Code + if (Input.GetKeyDown(KeyCode.E)) + { + OnDamaged(50); + return; + } + if (Input.GetKeyDown(KeyCode.F)) { if (CreatureState == Define.CreatureState.Interact) CreatureState = Define.CreatureState.Idle; - else - if (RayCast()) - return; + else if (CheckInteract(false)) + CreatureState = Define.CreatureState.Interact; + + return; } - if (Input.GetKeyDown(KeyCode.E)) + else + CheckInteract(true); + + if (CreatureState == Define.CreatureState.Interact || CreatureState == Define.CreatureState.Use) + return; + + if (Input.GetMouseButtonDown(0)) { - OnDamaged(50); // TODO - Test Code + if (CheckAndUseItem()) + { + CreatureState = Define.CreatureState.Use; + return; + } } if (Input.GetKeyDown(KeyCode.C)) @@ -79,7 +104,7 @@ protected override void HandleInput() { CreaturePose = Define.CreaturePose.Run; } - if (IsRecoveringStamina) //스테미너가 0이 되어도 SHIFT를 계속 누르고 있으면 RUN 상태 유지를 해제하기 위해 + if (IsRecoveringStamina) { CreaturePose = Define.CreaturePose.Stand; } @@ -195,4 +220,15 @@ public void OnDead() } #endregion + + protected bool CheckAndUseItem() + { + if (Inventory.CurrentItem == null) + { + Debug.Log("No Item"); + return false; + } + + return Inventory.CurrentItem.CheckAndUseItem(); + } } diff --git a/Client/Assets/Scripts/Controllers/Inventory.cs b/Client/Assets/Scripts/Controllers/Inventory.cs index c46a763291..4c3aab3aaa 100644 --- a/Client/Assets/Scripts/Controllers/Inventory.cs +++ b/Client/Assets/Scripts/Controllers/Inventory.cs @@ -27,12 +27,17 @@ protected virtual void Init() CurrentItemIdx = 0; } - [Rpc(RpcSources.StateAuthority, RpcTargets.All)] - public void Rpc_CheckAndGetItem(Define.ItemType itemType) + public void CheckAndGetItem(Define.ItemType itemType) { if (CurrentItem != null) return; + Rpc_GetItem(itemType); + } + + [Rpc(RpcSources.StateAuthority, RpcTargets.All)] + public void Rpc_GetItem(Define.ItemType itemType) + { Type type = Type.GetType(itemType.ToString()); if (type == null) { @@ -40,21 +45,16 @@ public void Rpc_CheckAndGetItem(Define.ItemType itemType) return; } - BaseItem item = (BaseItem)(Activator.CreateInstance(type)); - item.Owner = Owner; - } - - protected void UseItem() - { - CurrentItem.Rpc_Use(); + Items[CurrentItemIdx] = (BaseItem)(Activator.CreateInstance(type)); + Items[CurrentItemIdx].Owner = Owner; } - protected void DropItem() + public void DropItem() { } - protected void ChangeItem(int idx) + public void ChangeItem(int idx) { CurrentItemIdx = idx; } diff --git a/Client/Assets/Scripts/Controllers/Stalker.cs b/Client/Assets/Scripts/Controllers/Stalker.cs index 8f69ec82f0..a31748b5bc 100644 --- a/Client/Assets/Scripts/Controllers/Stalker.cs +++ b/Client/Assets/Scripts/Controllers/Stalker.cs @@ -1,5 +1,9 @@ public class Stalker : Alien { + public override void SetInfo(int templateID) + { + base.SetInfo(templateID); - + Skills[0] = new BasicAttack(); + } } diff --git a/Client/Assets/Scripts/Utils/Define.cs b/Client/Assets/Scripts/Utils/Define.cs index 712a1e2b18..8f45bf2bd2 100644 --- a/Client/Assets/Scripts/Utils/Define.cs +++ b/Client/Assets/Scripts/Utils/Define.cs @@ -36,21 +36,6 @@ public enum SoundType } #endregion - #region Attribute - public enum Stat - { - Name, - WalkSpeed, - RunSpeed, - Hp, - MaxHp, - Stamina, - SitSpeed, - Damage, - } - - #endregion - #region State public enum CreatureState @@ -58,6 +43,7 @@ public enum CreatureState Idle, Move, Interact, + Use, Dead, }