feat(Button): 实现按钮预制体,测试倒计时功能,添加从测试开始的按钮
This commit is contained in:
111
Assets/Script/Gameplay/Facility/ButtonInteractController.cs
Normal file
111
Assets/Script/Gameplay/Facility/ButtonInteractController.cs
Normal file
@@ -0,0 +1,111 @@
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Script.Gameplay.Interface;
|
||||
using Script.Gameplay.Connect;
|
||||
|
||||
namespace Script.Gameplay.Facility
|
||||
{
|
||||
public class ButtonInteractController : MonoBehaviour, IInteractable, IEditableComponent, IConnectable
|
||||
{
|
||||
#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;
|
||||
StartCoroutine(SendSignalCoroutine(interactor));
|
||||
Debug.Log("Button pressed");
|
||||
}
|
||||
|
||||
public void OnGazeEnter(GameObject editor)
|
||||
{
|
||||
// 可选:高亮按钮等
|
||||
}
|
||||
|
||||
public void OnGazeExit(GameObject editor)
|
||||
{
|
||||
// 可选:取消高亮
|
||||
}
|
||||
|
||||
private IEnumerator SendSignalCoroutine(GameObject sender)
|
||||
{
|
||||
SendSignal(true, sender);
|
||||
// 按钮压下的动画或效果可以在这里添加
|
||||
|
||||
yield return new WaitForSeconds(signalDuration);
|
||||
|
||||
SendSignal(false, sender);
|
||||
// 按钮弹起的动画或效果可以在这里添加
|
||||
}
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
public string GetConnectableName()
|
||||
{
|
||||
return gameObject.name;
|
||||
}
|
||||
|
||||
public ConnectionLine OutputConnectionLine { get; set; }
|
||||
public ConnectionLine InputConnectionLine { get; set; }
|
||||
|
||||
public bool IsConnectedOutput { get; set; }
|
||||
public bool IsConnectedInput { get; set; }
|
||||
|
||||
public void ReceiveSignal(bool active, GameObject sender)
|
||||
{
|
||||
// 按钮通常不响应输入信号,可留空或自定义逻辑
|
||||
}
|
||||
|
||||
public void SendSignal(bool active, GameObject sender)
|
||||
{
|
||||
if (OutputConnectionLine != null)
|
||||
{
|
||||
OutputConnectionLine.ReceiveSignal(active);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user