77 lines
2.0 KiB
C#
77 lines
2.0 KiB
C#
|
using System.Collections.Generic;
|
||
|
using UnityEngine;
|
||
|
using Script.Gameplay.Connect;
|
||
|
|
||
|
namespace Script.Gameplay.Facility
|
||
|
{
|
||
|
// 号码枚举类型
|
||
|
public enum NumberType
|
||
|
{
|
||
|
Zero,
|
||
|
One,
|
||
|
Two,
|
||
|
Three,
|
||
|
Four,
|
||
|
Five,
|
||
|
// Six,
|
||
|
// Seven,
|
||
|
// Eight,
|
||
|
// Nine
|
||
|
}
|
||
|
|
||
|
// 号码槽
|
||
|
public class NumberSlotController : MonoBehaviour, IConnectable, ISignalSender
|
||
|
{
|
||
|
[Header("号码槽设置")]
|
||
|
[SerializeField] private NumberType currentNumber = NumberType.Zero;
|
||
|
[SerializeField] private NumberType correctNumber = NumberType.One;
|
||
|
|
||
|
public List<ConnectionLine> ConnectionLines { get; set; } = new List<ConnectionLine>();
|
||
|
|
||
|
// 不可编辑,不可交互
|
||
|
// 可连接,可发信号
|
||
|
|
||
|
public void OnGazeEnter() { }
|
||
|
public void OnGazeExit() { }
|
||
|
public Vector3 GetPosition() => transform.position;
|
||
|
public GameObject GetGameObject() => gameObject;
|
||
|
public string GetConnectableName() => gameObject.name;
|
||
|
|
||
|
// 接收信号
|
||
|
public void SignalActive(bool active, GameObject sender)
|
||
|
{
|
||
|
if (active)
|
||
|
{
|
||
|
SwitchToNextNumber();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// 切换到下一个号码
|
||
|
private void SwitchToNextNumber()
|
||
|
{
|
||
|
currentNumber = (NumberType)(((int)currentNumber + 1) % System.Enum.GetValues(typeof(NumberType)).Length);
|
||
|
CheckNumberAndSendSignal();
|
||
|
}
|
||
|
|
||
|
// 检查号码并发信号
|
||
|
private void CheckNumberAndSendSignal()
|
||
|
{
|
||
|
bool isCorrect = currentNumber == correctNumber;
|
||
|
SendSignal(isCorrect);
|
||
|
}
|
||
|
|
||
|
// 发出信号
|
||
|
public void SendSignal(bool active)
|
||
|
{
|
||
|
if (ConnectionLines != null)
|
||
|
{
|
||
|
foreach (var line in ConnectionLines)
|
||
|
{
|
||
|
line.SignalActive(active, this.gameObject);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|