From 5886c9783b82b403c3060b9ae80940dc1b25ca54 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 7 Oct 2025 21:30:32 -0400 Subject: [PATCH] refactor: moved a lot of player related scripts to the Reset.Units namespace --- Assets/Scripts/Core/GenericLockOnTarget.cs | 20 +- .../Graph Tasks/UpdateObjectCameraTracking.cs | 2 +- Assets/Scripts/Core/InputFinder.cs | 47 +- Assets/Scripts/Core/LockOnManager.cs | 516 +++++++++--------- .../Scripts/Core/Networking/SessionManager.cs | 3 +- .../Core/{GameManager.cs => PlayerManager.cs} | 21 +- ...eManager.cs.meta => PlayerManager.cs.meta} | 0 .../Scripts/Core/Tools/DebugOverlayDrawer.cs | 2 +- Assets/Scripts/Core/UIManager.cs | 20 + Assets/Scripts/Core/UIManager.cs.meta | 3 + Assets/Scripts/Units/Combat/UnitCombat.cs | 5 +- Assets/Scripts/Units/Combat/UnitComponent.cs | 13 + .../Units/Combat/UnitComponent.cs.meta | 3 + Assets/Scripts/Units/Enemy.cs | 5 - Assets/Scripts/Units/IKillable.cs | 2 +- Assets/Scripts/Units/Player.cs | 80 +-- Assets/Scripts/Units/PlayerCamera.cs | 68 +-- Assets/Scripts/Units/PlayerControls.cs | 1 + Assets/Scripts/Units/Unit.cs | 108 ++-- 19 files changed, 518 insertions(+), 401 deletions(-) rename Assets/Scripts/Core/{GameManager.cs => PlayerManager.cs} (85%) rename Assets/Scripts/Core/{GameManager.cs.meta => PlayerManager.cs.meta} (100%) create mode 100644 Assets/Scripts/Core/UIManager.cs create mode 100644 Assets/Scripts/Core/UIManager.cs.meta create mode 100644 Assets/Scripts/Units/Combat/UnitComponent.cs create mode 100644 Assets/Scripts/Units/Combat/UnitComponent.cs.meta diff --git a/Assets/Scripts/Core/GenericLockOnTarget.cs b/Assets/Scripts/Core/GenericLockOnTarget.cs index 161057e..6b6b0f7 100644 --- a/Assets/Scripts/Core/GenericLockOnTarget.cs +++ b/Assets/Scripts/Core/GenericLockOnTarget.cs @@ -1,16 +1,18 @@ using System; using UnityEngine; -public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{ - public float lockonTargetRadius{ get; set; } = 1f; - public bool lockonDebug{ get; set; } = false; - public float lockonRaycastVerticalOffset{ get; set; } +namespace Reset.Units{ + public class GenericLockOnTarget : MonoBehaviour, ILockOnTarget{ + public float lockonTargetRadius{ get; set; } = 1f; + public bool lockonDebug{ get; set; } = false; + public float lockonRaycastVerticalOffset{ get; set; } - public void OnTargetDelete(){ - GetComponent().SafelyDeleteTarget(); - } + public void OnTargetDelete(){ + GetComponent().SafelyDeleteTarget(); + } - void OnDestroy(){ - OnTargetDelete(); + void OnDestroy(){ + OnTargetDelete(); + } } } diff --git a/Assets/Scripts/Core/Graph Tasks/UpdateObjectCameraTracking.cs b/Assets/Scripts/Core/Graph Tasks/UpdateObjectCameraTracking.cs index d27c35e..8c91028 100644 --- a/Assets/Scripts/Core/Graph Tasks/UpdateObjectCameraTracking.cs +++ b/Assets/Scripts/Core/Graph Tasks/UpdateObjectCameraTracking.cs @@ -4,7 +4,7 @@ using ParadoxNotion.Serialization.FullSerializer; using UnityEngine; using Logger = ParadoxNotion.Services.Logger; -namespace NodeCanvas.Tasks.Actions { +namespace Reset.Units { [Category("Reset")] public class UpdateObjectCameraTracking : ActionTask { diff --git a/Assets/Scripts/Core/InputFinder.cs b/Assets/Scripts/Core/InputFinder.cs index f2d1f41..03b73cb 100644 --- a/Assets/Scripts/Core/InputFinder.cs +++ b/Assets/Scripts/Core/InputFinder.cs @@ -4,32 +4,33 @@ using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.UIElements; -public class InputFinder : MonoBehaviour{ - public InputActionMap actionMap; - - void Start(){ - actionMap.actions[0].performed += ctx => { InputPressed(ctx); }; - - GetComponent().enabled = false; - } +namespace Reset.Units{ + public class InputFinder : MonoBehaviour{ + public InputActionMap actionMap; - public void AwaitNewInput(){ - GameManager.ClearCurrentController(); - - GetComponent().enabled = true; - actionMap.Enable(); - } + void Start(){ + actionMap.actions[0].performed += ctx => { InputPressed(ctx); }; - void InputPressed(InputAction.CallbackContext context){ - try { - GameManager.AttachControllerToPlayer(context.control.device); - Debug.Log(context.control.device); - } catch (Exception e) { - Debug.LogError($"Failed to set the new device to the player: {e.Message}"); - return; + GetComponent().enabled = false; } - GetComponent().enabled = false; - actionMap.Disable(); + public void AwaitNewInput(){ + PlayerManager.ClearCurrentController(); + + GetComponent().enabled = true; + actionMap.Enable(); + } + + void InputPressed(InputAction.CallbackContext context){ + try { + PlayerManager.AttachControllerToPlayer(context.control.device); + } catch (Exception e) { + Debug.LogError($"Failed to set the new device to the player: {e.Message}"); + return; + } + + GetComponent().enabled = false; + actionMap.Disable(); + } } } diff --git a/Assets/Scripts/Core/LockOnManager.cs b/Assets/Scripts/Core/LockOnManager.cs index c5208ba..8ac5582 100644 --- a/Assets/Scripts/Core/LockOnManager.cs +++ b/Assets/Scripts/Core/LockOnManager.cs @@ -4,6 +4,7 @@ using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using Reset; +using Reset.Core; using Sirenix.OdinInspector; using Unity.Cinemachine; using UnityEngine; @@ -13,278 +14,301 @@ using UnityEngine.UIElements; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3; -public class LockOnManager : MonoBehaviour{ - public class ActiveLockOnTarget{ - public GameObject gameObject; - public float targetWeight; - public float refVelocity; - public CinemachineTargetGroup.Target cinemachineTarget; - } - - public static LockOnManager Instance; - - // Lock On settings - [Space(5)] public float lockOnRange = 40f; - public float lockOnMaxAngle = 70f; - [Range(0,1)] public float mainTargetWeight = .15f; - [FormerlySerializedAs("smoothing")] public float smoothTime = 1f; - - // Lock On Tracking - [Space(10)] - - public ActiveLockOnTarget mainTarget; - - public List activeTargets = new List(); - - [ReadOnly] public CinemachineTargetGroup.Target lockonTarget; - public CinemachineTargetGroup targetGroup; - - public List acceptedTargets = new List(); - - // UI - [ShowInInspector] public UIDocument lockOnDocument; - private Label elementLabelName; - private VisualElement elementRoot; - - private void Awake(){ - // // Register as singleton - // if (Instance == null) { - // Instance = this; - // } else { - // this.enabled = false; - // return; - // } - - // References from camera - targetGroup = GameManager.Camera.transform.Find("Target Group").GetComponent(); - lockOnDocument = GameManager.UI.transform.Find("Lock On").GetComponent(); - } - - // Start is called once before the first execution of Update after the MonoBehaviour is created - void Start(){ - // Quick check for things in lock-on target that aren't lock-onable - if (mainTarget != null && mainTarget.gameObject.GetComponent() == null) { - mainTarget.gameObject.AddComponent(); - Debug.LogWarning($"The object {mainTarget.gameObject.name} has no ILockOnTarget interface. This isn't hyper critical, but adding one as a GenericLockOnTarget anyways."); +namespace Reset.Units{ + public class LockOnManager : MonoBehaviour{ + public class ActiveLockOnTarget{ + public GameObject gameObject; + public float targetWeight; + public float refVelocity; + public CinemachineTargetGroup.Target cinemachineTarget; } - elementRoot = lockOnDocument.rootVisualElement.Query("LockOnGroup"); - elementLabelName = lockOnDocument.rootVisualElement.Query