using UnityEngine; public class GKTInventoryScaleToggle : MonoBehaviour { [Header("Input")] [SerializeField] private KeyCode toggleKey = KeyCode.L; [SerializeField] private bool disableDirectInputOnScaleController = true; [SerializeField] private bool allowCtrlLBypass = true; [Header("Objeto Requerido (X)")] [SerializeField] private string requiredInventoryObjectName = ""; [SerializeField] private bool requireObjectConfiguredInInventoryList = true; [Header("Referencias")] [SerializeField] private AntManScaleController scaleController; [SerializeField] private playerComponentsManager mainPlayerComponentsManager; [SerializeField] private inventoryManager mainInventoryManager; [Header("Debug")] [SerializeField] private bool showLogs = true; private void Awake() { ResolveReferences(); if (scaleController != null && disableDirectInputOnScaleController) { scaleController.SetReadToggleInputState(false); } } private void Update() { if (Input.GetKeyDown(toggleKey)) { bool bypassInventoryCheck = allowCtrlLBypass && IsControlPressed(); TryToggleScale(bypassInventoryCheck); } } public void TryToggleScale(bool bypassInventoryCheck = false) { ResolveReferences(); if (scaleController == null) { if (showLogs) { Debug.LogWarning("[GKTInventoryScaleToggle] Falta AntManScaleController en este personaje.", this); } return; } if (bypassInventoryCheck) { scaleController.RequestToggle(); if (showLogs) { Debug.Log("[GKTInventoryScaleToggle] Ctrl+L bypass activo. Se omite verificacion de objeto X.", this); } return; } if (mainInventoryManager == null) { if (showLogs) { Debug.LogWarning("[GKTInventoryScaleToggle] No se encontro inventoryManager en el personaje.", this); } return; } if (string.IsNullOrWhiteSpace(requiredInventoryObjectName)) { if (showLogs) { Debug.LogWarning("[GKTInventoryScaleToggle] El objeto X aun no esta asignado. Completa Required Inventory Object Name.", this); } return; } if (requireObjectConfiguredInInventoryList && !mainInventoryManager.existInventoryInfoFromName(requiredInventoryObjectName)) { if (showLogs) { Debug.LogWarning( "[GKTInventoryScaleToggle] El objeto X no existe en el Inventory List Manager: " + requiredInventoryObjectName, this ); } return; } int amount = mainInventoryManager.getInventoryObjectAmountByName(requiredInventoryObjectName); bool hasObject = amount > 0; if (!hasObject) { if (showLogs) { Debug.Log("[GKTInventoryScaleToggle] No puedes cambiar escala. Falta objeto X en inventario: " + requiredInventoryObjectName, this); } return; } scaleController.RequestToggle(); if (showLogs) { Debug.Log("[GKTInventoryScaleToggle] Escala alternada. Objeto X verificado: " + requiredInventoryObjectName + " x" + amount, this); } } public void SetRequiredInventoryObjectName(string newObjectName) { requiredInventoryObjectName = newObjectName; } private static bool IsControlPressed() { return Input.GetKey(KeyCode.LeftControl) || Input.GetKey(KeyCode.RightControl); } private void ResolveReferences() { if (scaleController == null) { scaleController = GetComponent(); if (scaleController == null) { scaleController = GetComponentInParent(true); } if (scaleController == null) { scaleController = GetComponentInChildren(true); } } if (mainPlayerComponentsManager == null) { mainPlayerComponentsManager = GetComponent(); if (mainPlayerComponentsManager == null) { mainPlayerComponentsManager = GetComponentInParent(true); } if (mainPlayerComponentsManager == null) { mainPlayerComponentsManager = GetComponentInChildren(true); } } if (mainInventoryManager == null && mainPlayerComponentsManager != null) { mainInventoryManager = mainPlayerComponentsManager.getInventoryManager(); } if (mainInventoryManager == null) { mainInventoryManager = GetComponent(); if (mainInventoryManager == null) { mainInventoryManager = GetComponentInParent(true); } if (mainInventoryManager == null) { mainInventoryManager = GetComponentInChildren(true); } } } }