using System; using System.Collections; using System.Collections.Generic; using System.Numerics; using System.Runtime.CompilerServices; using Reset; using Reset.Core; using Sirenix.OdinInspector; using Unity.Cinemachine; using UnityEngine; using UnityEngine.InputSystem; using UnityEngine.Serialization; using UnityEngine.UIElements; using Vector2 = UnityEngine.Vector2; using Vector3 = UnityEngine.Vector3; namespace Reset.Units{ public class LockOnManager : UnitComponent, IUnitTargetProvider { public class ActiveLockOnTarget{ public GameObject gameObject; public float targetWeight; public float refVelocity; public CinemachineTargetGroup.Target cinemachineTarget; } public static LockOnManager Instance; // IUnitTargetProvider public GameObject UnitTarget => mainTarget.gameObject; // 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 && Unit.UnitIsLocal()) { Instance = this; } else { enabled = false; return; } // References from camera targetGroup = PlayerManager.Camera.transform.Find("Target Group").GetComponent(); lockOnDocument = UIManager.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."); } elementRoot = lockOnDocument.rootVisualElement.Query("LockOnGroup"); elementLabelName = lockOnDocument.rootVisualElement.Query