2025-10-20 09:34:22 +08:00
|
|
|
using System.Collections;
|
2025-10-20 19:40:55 +08:00
|
|
|
using System.Collections.Generic;
|
2025-10-20 09:34:22 +08:00
|
|
|
using UnityEngine;
|
|
|
|
using Script.Gameplay.Interface;
|
|
|
|
using Script.Gameplay.Connect;
|
|
|
|
|
|
|
|
namespace Script.Gameplay.Facility
|
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
public class ButtonInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable, ISignalSender
|
2025-10-20 09:34:22 +08:00
|
|
|
{
|
|
|
|
#region Interactable
|
|
|
|
|
|
|
|
public bool Interactable = true;
|
|
|
|
[SerializeField] private float signalDuration = 1.0f; // 信号持续时间(秒)
|
|
|
|
|
|
|
|
public string GetInteractPrompt()
|
|
|
|
{
|
|
|
|
return "按F按下按钮";
|
|
|
|
}
|
|
|
|
|
|
|
|
public void Interact(GameObject interactor)
|
|
|
|
{
|
|
|
|
if (!Interactable) return;
|
2025-10-20 19:40:55 +08:00
|
|
|
StartCoroutine(SendSignalCoroutine());
|
2025-10-20 09:34:22 +08:00
|
|
|
Debug.Log("Button pressed");
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnGazeEnter(GameObject editor)
|
|
|
|
{
|
|
|
|
// 可选:高亮按钮等
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnGazeExit(GameObject editor)
|
|
|
|
{
|
|
|
|
// 可选:取消高亮
|
|
|
|
}
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
private IEnumerator SendSignalCoroutine()
|
2025-10-20 09:34:22 +08:00
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
SendSignal(true);
|
|
|
|
Interactable = false;
|
2025-10-20 09:34:22 +08:00
|
|
|
// 按钮压下的动画或效果可以在这里添加
|
|
|
|
|
|
|
|
yield return new WaitForSeconds(signalDuration);
|
2025-10-20 19:40:55 +08:00
|
|
|
SendSignal(false);
|
|
|
|
Interactable = true;
|
2025-10-20 09:34:22 +08:00
|
|
|
// 按钮弹起的动画或效果可以在这里添加
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region EditableComponent
|
|
|
|
|
|
|
|
[SerializeField] private bool isActive = true;
|
|
|
|
|
|
|
|
public bool IsActive
|
|
|
|
{
|
|
|
|
get => isActive;
|
|
|
|
set
|
|
|
|
{
|
|
|
|
isActive = value;
|
|
|
|
Interactable = isActive;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public string ComponentName { get; set; } = "Button";
|
|
|
|
public LockLevel LockLevel => LockLevel.Red;
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
|
|
|
|
#region Connectable
|
|
|
|
|
|
|
|
public void OnGazeEnter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public void OnGazeExit()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
public Vector3 GetPosition()
|
|
|
|
{
|
|
|
|
return transform.position;
|
|
|
|
}
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
public GameObject GetGameObject()
|
|
|
|
{
|
|
|
|
return gameObject;
|
|
|
|
}
|
|
|
|
|
2025-10-20 09:34:22 +08:00
|
|
|
public string GetConnectableName()
|
|
|
|
{
|
|
|
|
return gameObject.name;
|
|
|
|
}
|
|
|
|
|
2025-10-20 19:40:55 +08:00
|
|
|
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
|
|
|
|
public void SignalActive(bool active, GameObject sender)
|
2025-10-20 09:34:22 +08:00
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
// 按钮通常不接收信号,因此这里可以留空
|
2025-10-20 09:34:22 +08:00
|
|
|
}
|
2025-10-20 19:40:55 +08:00
|
|
|
|
|
|
|
public void SendSignal(bool active)
|
2025-10-20 09:34:22 +08:00
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
if (ConnectionLines != null)
|
2025-10-20 09:34:22 +08:00
|
|
|
{
|
2025-10-20 19:40:55 +08:00
|
|
|
foreach (var line in ConnectionLines)
|
|
|
|
{
|
|
|
|
line.SignalActive(active, this.gameObject);
|
|
|
|
}
|
2025-10-20 09:34:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#endregion
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|