diff --git a/Client/Assets/Resources/Datas/ExcelData/ItemData.csv b/Client/Assets/Resources/Datas/ExcelData/ItemData.csv index 5c450e4b80..cb3793b17a 100644 --- a/Client/Assets/Resources/Datas/ExcelData/ItemData.csv +++ b/Client/Assets/Resources/Datas/ExcelData/ItemData.csv @@ -1,2 +1,2 @@ DataId,Name -201000,ItemA +201000,Battery diff --git a/Client/Assets/Resources/Datas/JsonData/ItemData.json b/Client/Assets/Resources/Datas/JsonData/ItemData.json index d8e73f6ea6..fc7b0290a2 100644 --- a/Client/Assets/Resources/Datas/JsonData/ItemData.json +++ b/Client/Assets/Resources/Datas/JsonData/ItemData.json @@ -2,7 +2,7 @@ "items": [ { "DataId": 201000, - "Name": "ItemA" + "Name": "Battery" } ] } \ No newline at end of file diff --git a/Client/Assets/Scripts/Contents/Item/BaseItem.cs b/Client/Assets/Scripts/Contents/Item/BaseItem.cs index 6295fc03f9..7564d6c6f2 100644 --- a/Client/Assets/Scripts/Contents/Item/BaseItem.cs +++ b/Client/Assets/Scripts/Contents/Item/BaseItem.cs @@ -1,10 +1,19 @@ -using Fusion; +using Data; +using Fusion; public abstract class BaseItem { - public Crew Owner { get; set; } + public int DataId { get; protected set; } + public ItemData ItemData { get; protected set; } + public Define.ItemType ItemType { get; set; } - public abstract bool CheckAndUseItem(); + public virtual void SetInfo(int templateId) + { + DataId = templateId; + ItemData = Managers.DataMng.ItemDataDict[templateId]; + } + + public abstract bool CheckAndUseItem(Crew crew); [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 50166fd05f..537108a690 100644 --- a/Client/Assets/Scripts/Contents/Item/Battery.cs +++ b/Client/Assets/Scripts/Contents/Item/Battery.cs @@ -1,14 +1,10 @@ -using Fusion; - -public class Battery : BaseItem +public class Battery : BaseItem { - public override bool CheckAndUseItem() + public override bool CheckAndUseItem(Crew crew) { - Rpc_Use(); - return true; + return false; } - [Rpc(RpcSources.StateAuthority, RpcTargets.All)] protected override void Rpc_Use() { diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/BaseInteractable.cs b/Client/Assets/Scripts/Contents/Map/Interactable/BaseInteractable.cs index 38313eb1e0..cdfa6d37e0 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/BaseInteractable.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/BaseInteractable.cs @@ -2,9 +2,10 @@ public abstract class BaseInteractable : NetworkBehaviour { - public virtual string InteractDescription { get; set; } + [Networked] public NetworkString<_16> InteractDescription { get; set; } - public abstract bool IsInteractable(Creature creature); + public abstract bool IsInteractable(Creature creature, bool isDoInteract); public abstract void Interact(Creature creature); + public abstract void PlayInteractAnimation(); } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs b/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs index c3667bd9de..f1a6db19c0 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BaseItemObject.cs @@ -1,8 +1,9 @@ +using Fusion; +using UnityEngine; + public abstract class BaseItemObject : BaseInteractable { - public Define.ItemType ItemType { get; protected set; } - - public override string InteractDescription => $"Get {ItemType}"; + public int DataId { get; protected set; } public override void Spawned() { @@ -11,18 +12,41 @@ public override void Spawned() protected abstract void Init(); - public override bool IsInteractable(Creature creature) + public override bool IsInteractable(Creature creature, bool isDoInteract) { - return creature is Crew; + if (creature.CreatureType == Define.CreatureType.Alien) + return false; + + creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString()); + + if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move)) + return false; + + if (!((Crew)creature).Inventory.CheckCanGetItem()) + return false; + + if (isDoInteract) + Interact(creature); + + return true; } public override void Interact(Creature creature) { - ((Crew)creature).Inventory.CheckAndGetItem(ItemType); + PlayInteractAnimation(); + Rpc_InteractComplete(); + + ((Crew)creature).Inventory.GetItem(DataId); + } + + [Rpc(RpcSources.All, RpcTargets.All)] + public virtual void Rpc_InteractComplete() + { + gameObject.SetActive(false); } public override void PlayInteractAnimation() { - // TODO + } } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BatteryObject.cs b/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BatteryObject.cs index 5c597df76e..b2d7d7bea8 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BatteryObject.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/ItemObject/BatteryObject.cs @@ -2,6 +2,8 @@ { protected override void Init() { - ItemType = Define.ItemType.Battery; + DataId = Define.ITEM_Battery_ID; + + InteractDescription = "GET BATTERY"; } } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BaseWorkStation.cs b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BaseWorkStation.cs index 54710d34d5..eb1f436045 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BaseWorkStation.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BaseWorkStation.cs @@ -10,7 +10,6 @@ public abstract class BaseWorkStation : BaseInteractable [Networked] public NetworkBool CanRememberWork { get; set; } [Networked] public NetworkBool CanCollaborate { get; set; } [Networked] public NetworkBool IsCompleted { get; set; } - [Networked] public NetworkString<_16> WorkingDescription { get; set; } [Networked, Capacity(3)] public NetworkLinkedList CurrentWorkers { get; } public Creature MyWorker { get; protected set; } @@ -26,7 +25,7 @@ protected virtual void Init() CurrentWorkAmount = 0f; } - public override bool IsInteractable(Creature creature) + public override bool IsInteractable(Creature creature, bool isDoInteract) { if (creature.CreatureType == Define.CreatureType.Alien) return false; @@ -34,22 +33,31 @@ public override bool IsInteractable(Creature creature) if (!CanUseAgain && IsCompleted) return false; + creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString()); + if (CurrentWorkers.Count >= 3 || (!CanCollaborate && CurrentWorkers.Count >= 1)) return false; if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move)) return false; + if (isDoInteract) + Interact(creature); + return true; } public override void Interact(Creature creature) { MyWorker = creature; - MyWorker.IngameUI.WorkProgressBarUI.Show(WorkingDescription.ToString(), TotalWorkAmount); + MyWorker.IngameUI.InteractInfoUI.Hide(); + MyWorker.CreatureState = Define.CreatureState.Interact; + MyWorker.CreaturePose = Define.CreaturePose.Stand; + MyWorker.CurrentWorkStation = this; + MyWorker.IngameUI.WorkProgressBarUI.Show(InteractDescription.ToString(), TotalWorkAmount); - Rpc_AddWorker(MyWorker.NetworkObject.Id); PlayInteractAnimation(); + Rpc_AddWorker(MyWorker.NetworkObject.Id); StartCoroutine(CoWorkProgress()); } @@ -64,6 +72,16 @@ public void MyWorkInterrupt() Debug.Log($"{MyWorker.NetworkObject.Id}: Interrupt Work"); // TODO - Test code } + public virtual void WorkComplete() + { + if (MyWorker.CreatureType == Define.CreatureType.Crew) + Rpc_CrewWorkComplete(); + else if (MyWorker.CreatureType == Define.CreatureType.Alien) + Rpc_AlienWorkComplete(); + else + Debug.LogError("Failed to WorkComplete"); + } + [Rpc(RpcSources.All, RpcTargets.StateAuthority)] protected void Rpc_AddWorker(NetworkId networkId) { @@ -111,12 +129,6 @@ protected virtual IEnumerator CoWorkProgress() } MyWorkInterrupt(); - - if (MyWorker.CreatureType == Define.CreatureType.Crew) - Rpc_CrewWorkComplete(); - else if (MyWorker.CreatureType == Define.CreatureType.Alien) - Rpc_AlienWorkComplete(); - else - Debug.LogError("Failed to WorkProgress"); + WorkComplete(); } } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BatteryCharger.cs b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BatteryCharger.cs new file mode 100644 index 0000000000..7edc717e79 --- /dev/null +++ b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BatteryCharger.cs @@ -0,0 +1,57 @@ +public class BatteryCharger : BaseWorkStation +{ + public Crew MyCrew => (Crew)MyWorker; + + protected override void Init() + { + base.Init(); + + InteractDescription = "USE COMPUTER"; + + CanUseAgain = true; + CanRememberWork = true; + CanCollaborate = true; + IsCompleted = false; + + TotalWorkAmount = 10f; + } + + public override bool IsInteractable(Creature creature, bool isDoInteract) + { + if (creature.CreatureType == Define.CreatureType.Alien) + return false; + + if (!CanUseAgain && IsCompleted) + return false; + + creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString()); + + if (CurrentWorkers.Count >= 3 || (!CanCollaborate && CurrentWorkers.Count >= 1)) + return false; + + if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move)) + return false; + + if (((Crew)creature).Inventory.CurrentItem.ItemType != Define.ItemType.Battery) + return false; + + if (isDoInteract) + Interact(creature); + + return true; + } + + public override void WorkComplete() + { + MyCrew.Inventory.CurrentItemIdx = -1; + + base.WorkComplete(); + } + + + public override void PlayInteractAnimation() + { + MyCrew.CrewAnimController.PlayKeypadUse(); + } +} + diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BatteryCharger.cs.meta b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BatteryCharger.cs.meta new file mode 100644 index 0000000000..b9292038f5 --- /dev/null +++ b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/BatteryCharger.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: a6f761c8b53645c6a3a0f637a602eb8e +timeCreated: 1711932298 \ No newline at end of file diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs index 0cc8ba8916..c94cab57f1 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Computer.cs @@ -1,6 +1,3 @@ -using System.Collections; -using UnityEngine; - public class Computer : BaseWorkStation { public Crew MyCrew => (Crew)MyWorker; @@ -9,14 +6,14 @@ protected override void Init() { base.Init(); + InteractDescription = "USE COMPUTER"; + CanUseAgain = false; CanRememberWork = true; CanCollaborate = true; IsCompleted = false; TotalWorkAmount = 100f; - WorkingDescription = "Fixing Computer"; - InteractDescription = "Fix computer"; } public override void PlayInteractAnimation() diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/Door.cs b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Door.cs similarity index 70% rename from Client/Assets/Scripts/Contents/Map/Interactable/Door.cs rename to Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Door.cs index cde80e5c59..97ae28a188 100644 --- a/Client/Assets/Scripts/Contents/Map/Interactable/Door.cs +++ b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Door.cs @@ -2,65 +2,62 @@ public class Door : BaseWorkStation { + [Networked] public float OpenWorkAmount { get; set; } + [Networked] public float CloseWorkAmount { get; set; } + [Networked] public NetworkBool IsOpened { get; set; } public NetworkMecanimAnimator NetworkAnim { get; protected set; } - public override string InteractDescription => IsOpened ? "Close door" : "Open door"; - protected override void Init() { base.Init(); NetworkAnim = transform.GetComponent(); + InteractDescription = "USE DOOR"; + CanUseAgain = true; CanCollaborate = false; CanRememberWork = false; IsCompleted = false; IsOpened = false; - TotalWorkAmount = 5f; - WorkingDescription = "DOOR"; + OpenWorkAmount = 5; + CloseWorkAmount = 1; + + TotalWorkAmount = IsOpened ? CloseWorkAmount : OpenWorkAmount; } - public override bool IsInteractable(Creature creature) + public override bool IsInteractable(Creature creature, bool isDoInteract) { + if (creature.CreatureType == Define.CreatureType.Alien && IsOpened) + return false; + if (!CanUseAgain && IsCompleted) return false; + creature.IngameUI.InteractInfoUI.Show(InteractDescription.ToString()); + if (CurrentWorkers.Count >= 3 || (!CanCollaborate && CurrentWorkers.Count >= 1)) return false; if (!(creature.CreatureState == Define.CreatureState.Idle || creature.CreatureState == Define.CreatureState.Move)) return false; - if (creature.CreatureType == Define.CreatureType.Alien && IsOpened) - return false; + TotalWorkAmount = IsOpened ? CloseWorkAmount : OpenWorkAmount; - return true; - } - - public override void Interact(Creature creature) - { - MyWorker = creature; - MyWorker.IngameUI.WorkProgressBarUI.Show(WorkingDescription.ToString(), TotalWorkAmount); - Rpc_AddWorker(MyWorker.NetworkObject.Id); - PlayInteractAnimation(); - - if (IsOpened) - TotalWorkAmount = 1; - else - TotalWorkAmount = 5; + if (isDoInteract) + Interact(creature); - MyWorker.IngameUI.WorkProgressBarUI.Show(WorkingDescription.ToString(), TotalWorkAmount); - - StartCoroutine(CoWorkProgress()); + return true; } [Rpc(RpcSources.All, RpcTargets.StateAuthority)] protected override void Rpc_CrewWorkComplete() { + base.Rpc_CrewWorkComplete(); + IsOpened = !IsOpened; NetworkAnim.Animator.SetBool("OpenParameter", IsOpened); } @@ -68,6 +65,8 @@ protected override void Rpc_CrewWorkComplete() [Rpc(RpcSources.All, RpcTargets.All)] protected override void Rpc_AlienWorkComplete() { + base.Rpc_CrewWorkComplete(); + gameObject.SetActive(false); //Managers.NetworkMng.Runner.Despawn(gameObject.GetComponent()); } diff --git a/Client/Assets/Scripts/Contents/Map/Interactable/Door.cs.meta b/Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Door.cs.meta similarity index 100% rename from Client/Assets/Scripts/Contents/Map/Interactable/Door.cs.meta rename to Client/Assets/Scripts/Contents/Map/Interactable/WorkStation/Door.cs.meta diff --git a/Client/Assets/Scripts/Controllers/Alien.cs b/Client/Assets/Scripts/Controllers/Alien.cs index 2f9617e9b9..77ea53e126 100644 --- a/Client/Assets/Scripts/Controllers/Alien.cs +++ b/Client/Assets/Scripts/Controllers/Alien.cs @@ -64,11 +64,11 @@ protected override void HandleInput() if (CreatureState == Define.CreatureState.Interact || CreatureState == Define.CreatureState.Use) return; - CheckInteract(false); + CheckAndInteract(false); if (Input.GetKeyDown(KeyCode.F)) { - if (CheckInteract(true)) + if (CheckAndInteract(true)) { return; } diff --git a/Client/Assets/Scripts/Controllers/Creature.cs b/Client/Assets/Scripts/Controllers/Creature.cs index c8f93e23cd..5cd1befe06 100644 --- a/Client/Assets/Scripts/Controllers/Creature.cs +++ b/Client/Assets/Scripts/Controllers/Creature.cs @@ -34,7 +34,9 @@ public abstract class Creature : NetworkBehaviour [Networked] public Vector3 Direction { get; set; } [Networked] public Vector3 Velocity { get; set; } - + + public BaseWorkStation CurrentWorkStation { get; set; } + #endregion public override void Spawned() @@ -164,37 +166,18 @@ protected virtual void UpdateDead() { } #endregion - protected bool CheckInteract(bool tryInteract) + protected bool CheckAndInteract(bool isDoInteract) { if (!HasStateAuthority || CreatureState == Define.CreatureState.Dead || IngameUI == null) return false; Ray ray = CreatureCamera.GetComponent().ViewportPointToRay(Vector3.one * 0.5f); - if (Physics.Raycast(ray, out RaycastHit rayHit, maxDistance:2f, layerMask:LayerMask.GetMask("MapObject"))) - { - if (rayHit.transform.gameObject.TryGetComponent(out BaseInteractable interactable) && interactable.IsInteractable(this)) - { - IngameUI.InteractInfoUI.Show(interactable.InteractDescription); - - if (tryInteract) - { - IngameUI.InteractInfoUI.Hide(); - CreatureState = Define.CreatureState.Interact; - CreaturePose = Define.CreaturePose.Stand; - - interactable.Interact(this); - - Debug.DrawRay(ray.origin, ray.direction * 2f, Color.green, 1f); + if (Physics.Raycast(ray, out RaycastHit rayHit, maxDistance:1.5f, layerMask:LayerMask.GetMask("MapObject"))) + if (rayHit.transform.gameObject.TryGetComponent(out BaseInteractable interactable)) + return interactable.IsInteractable(this, isDoInteract); - return true; - } - } - } - else - { - IngameUI.InteractInfoUI.Hide(); - } + IngameUI.InteractInfoUI.Hide(); Debug.DrawRay(ray.origin, ray.direction * 1.5f, Color.red); @@ -203,11 +186,13 @@ protected bool CheckInteract(bool tryInteract) public void InterruptInteract() { - if (!HasStateAuthority || CreatureState == Define.CreatureState.Dead) + if (!HasStateAuthority || CurrentWorkStation == null || CreatureState == Define.CreatureState.Dead) return; IngameUI.WorkProgressBarUI.Hide(); CreatureState = Define.CreatureState.Idle; + + CurrentWorkStation = null; } public void ReturnToIdle(float time) diff --git a/Client/Assets/Scripts/Controllers/Crew.cs b/Client/Assets/Scripts/Controllers/Crew.cs index dba1df12fa..d4a55b7c1b 100644 --- a/Client/Assets/Scripts/Controllers/Crew.cs +++ b/Client/Assets/Scripts/Controllers/Crew.cs @@ -74,7 +74,7 @@ protected override void HandleInput() if (CreatureState == Define.CreatureState.Damaged || CreatureState == Define.CreatureState.Dead || CreatureState == Define.CreatureState.Use) return; - CheckInteract(false); + CheckAndInteract(false); // TODO - Test Code if (Input.GetKeyDown(KeyCode.E)) @@ -91,12 +91,8 @@ protected override void HandleInput() } if (Input.GetKeyDown(KeyCode.F)) - { - if (CheckInteract(true)) - { + if (CheckAndInteract(true)) return; - } - } //if (Input.GetMouseButtonDown(0)) //{ @@ -126,20 +122,14 @@ protected override void HandleInput() if (Input.GetKey(KeyCode.LeftShift)) { if (CreaturePose != Define.CreaturePose.Sit && !IsRecoveringStamina) - { CreaturePose = Define.CreaturePose.Run; - } if (IsRecoveringStamina) - { CreaturePose = Define.CreaturePose.Stand; - } } else { if (CreaturePose == Define.CreaturePose.Run) - { CreaturePose = Define.CreaturePose.Stand; - } } } @@ -159,9 +149,7 @@ protected void UpdateStamina() { CrewStat.OnRecoverStamina(Define.PASIVE_RECOVER_STAMINA * Runner.DeltaTime); if (CrewStat.Stamina >= 20) //스테미너가 0이하가 된 뒤 20까지 회복 되면 다시 달리기 가능으로 변경 - { IsRecoveringStamina = false; - } } } @@ -270,6 +258,6 @@ protected bool CheckAndUseItem() return false; } - return Inventory.CurrentItem.CheckAndUseItem(); + return Inventory.CurrentItem.CheckAndUseItem(this); } } diff --git a/Client/Assets/Scripts/Controllers/Inventory.cs b/Client/Assets/Scripts/Controllers/Inventory.cs index 752ee42640..28058c64a4 100644 --- a/Client/Assets/Scripts/Controllers/Inventory.cs +++ b/Client/Assets/Scripts/Controllers/Inventory.cs @@ -1,17 +1,13 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using Fusion; -using UnityEngine; public class Inventory: NetworkBehaviour { public Crew Owner { get; protected set; } - public Define.CreatureState CreatureState => Owner.CreatureState; - public Define.CreaturePose CreaturePose => Owner.CreaturePose; - public List Items { get; protected set; } - [Networked] public int CurrentItemIdx { get; protected set; } - public BaseItem CurrentItem => Items[CurrentItemIdx]; + public List ItemInventory { get; protected set; } + [Networked] public int CurrentItemIdx { get; set; } + public BaseItem CurrentItem => Managers.ObjectMng.Items[ItemInventory[CurrentItemIdx]]; public override void Spawned() { @@ -22,36 +18,52 @@ protected virtual void Init() { Owner = gameObject.GetComponent(); - Items = new List(Define.MAX_ITEM_NUM); + ItemInventory = new List(Define.MAX_ITEM_NUM); for (int i = 0; i < Define.MAX_ITEM_NUM; i++) { - Items.Add(null); + ItemInventory.Add(-1); } CurrentItemIdx = 0; } - public bool CheckAndGetItem(Define.ItemType itemType) + public bool CheckCanGetItem() { - if (CurrentItem != null) - return false; + for (int i = 0; i < Define.MAX_ITEM_NUM; i++) + { + if (ItemInventory[i] == -1) + return true; + } - Rpc_GetItem(itemType); - return true; + return false; } - [Rpc(RpcSources.StateAuthority, RpcTargets.All)] - public void Rpc_GetItem(Define.ItemType itemType) + public void GetItem(int itemId) { - Type type = Type.GetType(itemType.ToString()); - if (type == null) + if (ItemInventory[CurrentItemIdx] == -1) { - Debug.LogError("Failed to Rpc_CheckAndGetItem: " + itemType); + ItemInventory[CurrentItemIdx] = itemId; return; } - Items[CurrentItemIdx] = (BaseItem)(Activator.CreateInstance(type)); - Items[CurrentItemIdx].Owner = Owner; + for (int i = 0; i < Define.MAX_ITEM_NUM; i++) + if (ItemInventory[i] == -1) + { + ItemInventory[i] = itemId; + return; + } + } + + public bool CheckAndUseItem(int itemIdx) + { + if (ItemInventory[CurrentItemIdx] == -1) + return false; + + if (!CurrentItem.CheckAndUseItem(Owner)) + return false; + + ItemInventory[CurrentItemIdx] = -1; + return true; } public void DropItem() diff --git a/Client/Assets/Scripts/Managers/Contents/ObjectManager.cs b/Client/Assets/Scripts/Managers/Contents/ObjectManager.cs index 9a321ba473..e71d5d34b9 100644 --- a/Client/Assets/Scripts/Managers/Contents/ObjectManager.cs +++ b/Client/Assets/Scripts/Managers/Contents/ObjectManager.cs @@ -1,3 +1,4 @@ +using System; using System.Collections.Generic; using Data; using Fusion; @@ -8,6 +9,8 @@ public class ObjectManager public Dictionary Crews { get; protected set; } public Dictionary Aliens { get; protected set; } + public Dictionary Items { get; protected set; } + public Creature MyCreature { get; set; } public Transform CrewRoot => GetRootTransform("@Crews"); public Transform AlienRoot => GetRootTransform("@Aliens"); @@ -16,6 +19,9 @@ public void Init() { Crews = new Dictionary(); Aliens = new Dictionary(); + Items = new Dictionary(); + + BindItems(); } public Transform GetRootTransform(string name) @@ -27,6 +33,30 @@ public Transform GetRootTransform(string name) return root.transform; } + #region Bind + + public void BindItems() + { + foreach (var itemData in Managers.DataMng.ItemDataDict) + { + Type itemType = Type.GetType(itemData.Value.Name); + if (itemType == null) + { + Debug.LogError("Failed to BindAction: " + itemData.Value.Name); + return; + } + + BaseItem item = (BaseItem)(Activator.CreateInstance(itemType)); + item.SetInfo(itemData.Key); + + Items[itemData.Key] = item; + } + } + + #endregion + + #region Creature + public NetworkObject SpawnCrew(int crewDataId, Vector3 spawnPosition) { string className = Managers.DataMng.CrewDataDict[crewDataId].Name; @@ -83,4 +113,6 @@ public CreatureData GetCreatureDataWithDataId(int dataId) Debug.Log("Invalid GetCreatureDataWithDataId"); return null; } + + #endregion } diff --git a/Client/Assets/Scripts/Utils/Define.cs b/Client/Assets/Scripts/Utils/Define.cs index 500fcca15e..045a0a85bd 100644 --- a/Client/Assets/Scripts/Utils/Define.cs +++ b/Client/Assets/Scripts/Utils/Define.cs @@ -11,6 +11,7 @@ public enum CreatureType public enum ItemType { + None, Battery, } @@ -118,7 +119,7 @@ public enum CameraMode public const int ALIEN_STALKER_ID = 102000; - public const int ITEM_ITEMA_ID = 201000; + public const int ITEM_Battery_ID = 201000; #endregion @@ -133,11 +134,7 @@ public enum CameraMode public const int PLAYER_COUNT = 4; public const int MAX_ITEM_NUM = 4; public const int MAX_SKILL_NUM = 4; - public const float PLAYER_SPAWN_POSITION_X = 20f; - public const float PLAYER_SPAWN_POSITION_Y = 0.3f; - public const float PLAYER_SPAWN_POSITION_Z = 10f; - public const float GRAVITY_VALUE = -9.81f; public const int PASIVE_RECOVER_STAMINA = 5; public const int RUN_USE_STAMINA = 10;