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
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7f5359facd804a0cb94d416c9c54a167
|
||||
timeCreated: 1760923022
|
@@ -7,26 +7,31 @@ namespace Script.Gameplay.Global
|
||||
{
|
||||
public enum GameState
|
||||
{
|
||||
Boot, // 初始化
|
||||
MainMenu, // 主菜单
|
||||
Playing, // 游戏中
|
||||
Paused, // 暂停
|
||||
GameOver, // 游戏结束
|
||||
Victory // 胜利
|
||||
Boot, // 初始化
|
||||
MainMenu, // 主菜单
|
||||
Playing, // 游戏中
|
||||
Paused, // 暂停
|
||||
GameOver, // 游戏结束
|
||||
Victory // 胜利
|
||||
}
|
||||
|
||||
|
||||
public class GameFlowManager : MonoSingleton<GameFlowManager>
|
||||
{
|
||||
public bool IsOpenRestartGameOnCountdownFinish = true;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
GameCountdownManager.Instance.StartLevelTimer();
|
||||
GameCountdownManager.Instance.OnFinish.AddListener(RestartGame);
|
||||
GameCountdownManager.Instance.OnFinish.AddListener(() =>
|
||||
{
|
||||
if (IsOpenRestartGameOnCountdownFinish) RestartGame();
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
public void RestartGame()
|
||||
{
|
||||
GameManager.Instance.ReStartGame();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -103,6 +103,8 @@ namespace Gameplay.Player
|
||||
if (outTarget != null && inputTarget != null && outTarget != inputTarget)
|
||||
{
|
||||
ConnectionLine connectionLine = ConnectionLineManager.Instance.GenerateConnectionLine(outTarget, inputTarget);
|
||||
outTarget.OutputConnectionLine = connectionLine;
|
||||
inputTarget.InputConnectionLine = connectionLine;
|
||||
// 重置信号目标
|
||||
outTarget = null;
|
||||
inputTarget = null;
|
||||
|
@@ -4,9 +4,10 @@ namespace UI
|
||||
{
|
||||
public class StartGameButton : UIBase
|
||||
{
|
||||
public string levelName = "Level1";
|
||||
public void StartGame()
|
||||
{
|
||||
ScenesManager.Instance.LoadGameplay("Level1");
|
||||
ScenesManager.Instance.LoadGameplay(levelName);
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user