using UnityEngine; /// /// Types of interactions available in the game. /// public enum InteractionType { Generic, Pickup, Use, Talk, Enter, Build, Open, Activate } /// /// Contains preview information about an interaction for UI display. /// [System.Serializable] public struct InteractionPreview { /// /// The action verb (e.g., "Pick up", "Enter", "Use"). /// public string ActionVerb; /// /// The name of the target object (e.g., "Iron Ore", "Tunnel"). /// public string TargetName; /// /// Optional icon to display in UI. /// public Sprite Icon; /// /// The type of interaction. /// public InteractionType Type; /// /// Whether this interaction requires holding the button. /// public bool RequiresHold; /// /// Duration to hold if RequiresHold is true. /// public float HoldDuration; /// /// Input hint to display (e.g., "[F]", "[E]"). /// public string InputHint; /// /// Create a simple interaction preview. /// public static InteractionPreview Simple(string actionVerb, string targetName, InteractionType type = InteractionType.Generic) { return new InteractionPreview { ActionVerb = actionVerb, TargetName = targetName, Type = type, RequiresHold = false, HoldDuration = 0f, InputHint = "[F]" }; } /// /// Create a pickup interaction preview. /// public static InteractionPreview Pickup(string itemName, Sprite icon = null) { return new InteractionPreview { ActionVerb = "Pick up", TargetName = itemName, Icon = icon, Type = InteractionType.Pickup, RequiresHold = false, InputHint = "[F]" }; } /// /// Create an enter/use interaction preview. /// public static InteractionPreview Enter(string targetName) { return new InteractionPreview { ActionVerb = "Enter", TargetName = targetName, Type = InteractionType.Enter, RequiresHold = false, InputHint = "[F]" }; } /// /// Create a hold-to-interact preview. /// public static InteractionPreview Hold(string actionVerb, string targetName, float duration, InteractionType type = InteractionType.Use) { return new InteractionPreview { ActionVerb = actionVerb, TargetName = targetName, Type = type, RequiresHold = true, HoldDuration = duration, InputHint = "[Hold F]" }; } /// /// Get the full display string (e.g., "[F] Pick up Iron Ore"). /// public string GetDisplayString() { return $"{InputHint} {ActionVerb} {TargetName}"; } } /// /// Interface for objects that can be interacted with by the player. /// public interface IInteractable { /// /// Perform the interaction. /// /// The GameObject performing the interaction (usually the player) void Interact(GameObject interactor); /// /// Get preview information about this interaction for UI display. /// Default implementation returns a generic preview. /// InteractionPreview GetInteractionPreview() { return InteractionPreview.Simple("Interact", "Object"); } /// /// Check if this object can currently be interacted with. /// Default implementation always returns true. /// /// The GameObject attempting to interact /// True if interaction is possible bool CanInteract(GameObject interactor) { return true; } /// /// Get the world position of this interactable for distance calculations. /// Default implementation returns zero vector (override in implementation). /// Vector3 GetInteractionPoint() { return Vector3.zero; } }