using UnityEngine; /// /// Base class for all interactive objects that implement IInteractiveObject. /// Consolidates common properties and methods to reduce code duplication. /// public abstract class InteractiveObjectBase : MonoBehaviour, IInteractiveObject { [Header("Interactive Object Settings")] [SerializeField] protected string objectDisplayName = "Interactive Object"; [SerializeField] protected Transform customInteractionPoint; // Optional: use instead of collider center [SerializeField] protected bool enableDebugLogs = false; /// /// Get the interaction point - uses custom point if assigned, otherwise collider center /// public virtual Vector3 GetInteractionPoint() { if (customInteractionPoint != null) { Log("GetInteractionPoint: Using custom interaction point"); return customInteractionPoint.position; } Collider collider = GetComponent(); if (collider != null) { Log($"GetInteractionPoint: Using collider center at {collider.bounds.center}"); return collider.bounds.center; } Log("GetInteractionPoint: No collider found, using transform position"); return transform.position; } /// /// Get the display name for this interactive object /// public virtual string GetDisplayName() { Log($"GetDisplayName: Returning '{objectDisplayName}'"); return objectDisplayName; } /// /// Check if this object can be interacted with /// Override in derived classes to add custom logic /// public virtual bool CanInteract() { Log("CanInteract: Default implementation returns true"); return true; } /// /// Perform the interaction /// Must be implemented by derived classes /// public abstract void Interact(GameObject player); /// /// Protected logging utility with optional debug toggle /// protected void Log(string message) { if (enableDebugLogs) { DebugManager.Log(GetType().Name, message, gameObject); } } /// /// Set the display name at runtime /// public void SetDisplayName(string newName) { objectDisplayName = newName; Log($"Display name changed to '{newName}'"); } /// /// Set custom interaction point Transform /// public void SetCustomInteractionPoint(Transform point) { customInteractionPoint = point; Log($"Custom interaction point set to {point.name}"); } }