From 64fe9eb811441320aaaa880c70708a2f0771c2e0 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 5 Aug 2025 16:38:29 -0400 Subject: [PATCH] changed: rebuilt lock-on system to accomodate arbitrary targets --- Assets/Scripts/Core/LockOnManager.cs | 209 +++++++++++++++++++++------ 1 file changed, 161 insertions(+), 48 deletions(-) diff --git a/Assets/Scripts/Core/LockOnManager.cs b/Assets/Scripts/Core/LockOnManager.cs index e8a0717..b565226 100644 --- a/Assets/Scripts/Core/LockOnManager.cs +++ b/Assets/Scripts/Core/LockOnManager.cs @@ -5,91 +5,187 @@ using System.Numerics; using Sirenix.OdinInspector; using Unity.Cinemachine; using UnityEngine; +using UnityEngine.Serialization; using UnityEngine.UIElements; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3; public class LockOnManager : MonoBehaviour{ + class ReferencedTarget{ + public GameObject gameObject; + public float targetWeight; + public float refVelocity; + public CinemachineTargetGroup.Target cinemachineTarget; + } private CinemachineTargetGroup.Target playerTarget; // Lock On settings - [Space(5)] - public float lockOnRange = 40f; + [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 GameObject lockonGameObject; // Needed because nulling the Target below doesn't actually empty it out + [Space(10)] + public GameObject lockonGameObject; // Needed because nulling the Target below doesn't actually empty it out + + [ShowInInspector] + ReferencedTarget mainTarget; + + [ShowInInspector] + List activeTargets = new List(); + [ReadOnly] public CinemachineTargetGroup.Target lockonTarget; public CinemachineTargetGroup targetGroup; - - [Space(5)] - public List lockOnTargets = new List(); + + [FormerlySerializedAs("lockOnTargets")] [Space(5)] + public List acceptedTargets = new List(); // UI - [ShowInInspector] - public UIDocument lockOnDocument; + [ShowInInspector] public UIDocument lockOnDocument; private Label elementLabelName; - private VisualElement elementRoot; - + private VisualElement elementRoot; + // Start is called once before the first execution of Update after the MonoBehaviour is created void Start(){ // Save the player target object to track later playerTarget = targetGroup.Targets[0]; - + // Quick check for things in lock-on target that aren't lock-onable if (lockonGameObject != null && lockonTarget.Object.GetComponent() == null) { Debug.LogError($"Game Object {lockonTarget.Object.name} does not implement the ILockOnTarget interface!"); } - + elementRoot = lockOnDocument.rootVisualElement.Query("LockOnGroup"); elementLabelName = lockOnDocument.rootVisualElement.Query