using Reset.Core; using Reset.Items; using Unity.Netcode; using UnityEngine; using UnityEngine.Profiling; namespace Reset.Units{ public class PlayerCombat : UnitCombat{ public CombatType currentCombatType; private IEquipable currentWeapon; private GameObject currentWeaponItem; public void OnDrawWeapon(){ if (Unit.UnitIsNetworked()) { CreatePlayerWeaponRpc(); } else { CreatePlayerWeapon(); } } [Rpc(SendTo.Everyone)] public void CreatePlayerWeaponRpc(){ CreatePlayerWeapon(); } public void CreatePlayerWeapon(){ // Remove a current weapon DisposeCurrentWeapon(); // Reference inventory and inventory PlayerInventory playerInventory = Unit.Inventory as PlayerInventory; PlayerAnimation playerAnimation = Unit.Animation as PlayerAnimation; // Add weapon to status and hand currentWeapon = playerInventory.meleeWeapon; currentWeaponItem = playerInventory.meleeWeapon.InstantiateItemObject(); // Move item to hand currentWeaponItem.transform.SetParent(playerAnimation.rightHand); currentWeaponItem.transform.localPosition = playerInventory.meleeWeapon.handPositionOffset; currentWeaponItem.transform.rotation = playerAnimation.rightHand.rotation * Quaternion.Euler(playerInventory.meleeWeapon.handRotationOffset); // Add related weapon's actor script (currentWeapon as Weapon).AddActorScript(); } public GameObject GetCurrentWeaponItem(){ return currentWeaponItem; } public void OnHolsterWeapon(){ DisposeCurrentWeapon(); } public void DisposeCurrentWeapon(){ // Return if no weapon active if (currentWeapon == null) { return; } // Destroy physical mesh Destroy(currentWeaponItem); // Destroy weapon actor if ((GetComponent()) != null) { Destroy(GetComponent()); } // Remove references currentWeaponItem = null; currentWeapon = null; } } }