Files
2025TapTapGameJam/Assets/Script/Gameplay/Facility/NumberSlotController.cs

96 lines
2.8 KiB
C#
Raw Normal View History

using System;
2025-10-20 19:59:44 +08:00
using System.Collections.Generic;
using UnityEngine;
using Script.Gameplay.Connect;
namespace Script.Gameplay.Facility
2025-10-20 19:59:44 +08:00
{
// 号码枚举类型
public enum NumberType
{
Circle,
Cloud,
Flower,
Leaf,
Wave,
2025-10-20 19:59:44 +08:00
}
// 号码槽
public class NumberSlotController : BaseFacilityController
2025-10-20 19:59:44 +08:00
{
[Header("号码槽设置")]
[SerializeField] private NumberType currentNumber = NumberType.Circle;
[SerializeField] private NumberType correctNumber = NumberType.Cloud;
[Header("图标")]
[SerializeField] private GameObject CircleIcon;
[SerializeField] private GameObject CloudIcon;
[SerializeField] private GameObject FlowerIcon;
[SerializeField] private GameObject LeafIcon;
[SerializeField] private GameObject WaveIcon;
private void Start()
{
// 初始化图标显示
UpdateIconDisplay();
// 检查初始号码并发送信号
CheckNumberAndSendSignal();
}
2025-10-20 19:59:44 +08:00
// 接收信号
public override void OnSignalReceived(bool active, GameObject sender)
2025-10-20 19:59:44 +08:00
{
base.OnSignalReceived(active, sender);
2025-10-20 19:59:44 +08:00
if (active)
{
SwitchToNextNumber();
}
}
// 切换到下一个号码
private void SwitchToNextNumber()
{
currentNumber = (NumberType)(((int)currentNumber + 1) % System.Enum.GetValues(typeof(NumberType)).Length);
CheckNumberAndSendSignal();
// 更新图标显示
UpdateIconDisplay();
}
private void UpdateIconDisplay()
{
// 隐藏所有图标
CircleIcon.SetActive(false);
CloudIcon.SetActive(false);
FlowerIcon.SetActive(false);
LeafIcon.SetActive(false);
WaveIcon.SetActive(false);
// 根据当前号码显示对应图标
switch (currentNumber)
{
case NumberType.Circle:
CircleIcon.SetActive(true);
break;
case NumberType.Cloud:
CloudIcon.SetActive(true);
break;
case NumberType.Flower:
FlowerIcon.SetActive(true);
break;
case NumberType.Leaf:
LeafIcon.SetActive(true);
break;
case NumberType.Wave:
WaveIcon.SetActive(true);
break;
}
2025-10-20 19:59:44 +08:00
}
// 检查号码并发信号
private void CheckNumberAndSendSignal()
{
bool isCorrect = currentNumber == correctNumber;
SendSignal(isCorrect, this.gameObject);
2025-10-20 19:59:44 +08:00
}
}
}