using UnityEngine; using Ashwild.Inventory; namespace Ashwild.Player { /// /// Held-item logic for the build hammer, placed on its hand prefab. While equipped it /// listens to the secondary-use input (right-click) and asks the construction UI to /// open/close through the bus — it never reaches for the menu itself, so the hammer /// stays a pure input source and the UI owns its own state. Left-click placement will /// be added on top of this once the build menu exists. /// [DisallowMultipleComponent] public class BuildHammerBehaviour : MonoBehaviour, IHeldItemBehaviour { #region Serialized Fields [Header("Cooldown")] /// /// Minimum time, in seconds, between two menu toggles so a held right-click /// does not flicker the menu open and shut. /// [SerializeField] private float toggleCooldown = 0.25f; #endregion #region State /// /// Earliest time, in seconds, the next menu toggle is allowed. /// private float nextToggleTime; #endregion #region Unity Lifecycle /// /// Subscribes to the secondary-use input for as long as the hammer is held. /// private void OnEnable() { PlayerEvents.SecondaryUsePressed += HandleSecondaryUse; } /// /// Unsubscribes when the hammer is put away (the prefab is destroyed). /// private void OnDisable() { PlayerEvents.SecondaryUsePressed -= HandleSecondaryUse; } #endregion #region IHeldItemBehaviour /// /// Nothing to link yet: toggling the menu needs no player refs. Present to satisfy /// the held-item contract; placement logic added later will use the context. /// public void Setup(HeldItemContext context, ItemData item) { } #endregion #region Event Handlers /// /// Requests the construction menu to open/close on right-click, gated by lock and /// cooldown. The UI decides whether that opens or closes it. /// private void HandleSecondaryUse() { if (PlayerEvents.InputLocked) return; if (Time.time < nextToggleTime) return; nextToggleTime = Time.time + toggleCooldown; PlayerEvents.RaiseBuildMenuToggleRequested(); } #endregion } }