Files
secretsplash/Runtime/PSXInteractable.cs
Jan Racek 4aa4e49424 psst
2026-03-24 13:00:54 +01:00

62 lines
2.5 KiB
C#

using UnityEngine;
namespace SplashEdit.RuntimeCode
{
/// <summary>
/// Makes an object interactable by the player.
/// When the player is within range and presses the interact button,
/// the onInteract Lua event fires.
/// </summary>
[RequireComponent(typeof(PSXObjectExporter))]
public class PSXInteractable : MonoBehaviour
{
[Header("Interaction Settings")]
[Tooltip("Distance within which the player can interact with this object")]
[SerializeField] private float interactionRadius = 2.0f;
[Tooltip("Button that triggers interaction (0-15, matches PS1 button mapping)")]
[SerializeField] private int interactButton = 5; // Default to Cross button
[Tooltip("Can this object be interacted with multiple times?")]
[SerializeField] private bool isRepeatable = true;
[Tooltip("Cooldown between interactions (in frames, 60 = 1 second at NTSC)")]
[SerializeField] private ushort cooldownFrames = 30;
[Tooltip("Show interaction prompt when in range (requires UI system)")]
[SerializeField] private bool showPrompt = true;
[Header("Advanced")]
[Tooltip("Require line-of-sight to player for interaction")]
[SerializeField] private bool requireLineOfSight = false;
[Tooltip("Custom interaction point offset from object center")]
[SerializeField] private Vector3 interactionOffset = Vector3.zero;
// Public accessors for export
public float InteractionRadius => interactionRadius;
public int InteractButton => interactButton;
public bool IsRepeatable => isRepeatable;
public ushort CooldownFrames => cooldownFrames;
public bool ShowPrompt => showPrompt;
public bool RequireLineOfSight => requireLineOfSight;
public Vector3 InteractionOffset => interactionOffset;
private void OnDrawGizmosSelected()
{
// Draw interaction radius
Gizmos.color = new Color(1f, 1f, 0f, 0.3f); // Yellow, semi-transparent
Vector3 center = transform.position + interactionOffset;
Gizmos.DrawWireSphere(center, interactionRadius);
// Draw filled sphere with lower alpha
Gizmos.color = new Color(1f, 1f, 0f, 0.1f);
Gizmos.DrawSphere(center, interactionRadius);
// Draw interaction point
Gizmos.color = Color.yellow;
Gizmos.DrawSphere(center, 0.1f);
}
}
}