155 lines
5.2 KiB
C#
155 lines
5.2 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using AibisDream;
|
|
|
|
public class ClueBoardManager : MonoBehaviour
|
|
{
|
|
[SerializeField] private GameObject clueBoardUI; // ClueBoard UI的GameObject
|
|
[SerializeField] private Button toggleButton; // 开启/关闭ClueBoard的按钮
|
|
[SerializeField] private Button submitButton; // 提交按钮
|
|
[SerializeField] private TMP_Text conclue; // 提交按钮
|
|
[SerializeField] private ClueSlotBase initialClueSlotPrefab; // 初始的ClueSlot预制体
|
|
[SerializeField] private Transform clueSlotContainer; // ClueSlot的容器
|
|
|
|
private RectTransform clueBoardRectTransform; // ClueBoard的RectTransform
|
|
private List<ClueSlotBase> clueSlots = new List<ClueSlotBase>(); // 当前存在的所有ClueSlot
|
|
private int currentStep = 0; // 当前步骤编号
|
|
|
|
private int maxStep = 3; // 当前步骤编号
|
|
private bool isBoardOpen = false;
|
|
private Vector2 hiddenPosition; // ClueBoard隐藏时的位置
|
|
private Vector2 visiblePosition; // ClueBoard显示时的位置
|
|
|
|
private void Start()
|
|
{
|
|
clueBoardRectTransform = clueBoardUI.GetComponent<RectTransform>();
|
|
|
|
// 定义ClueBoard UI的位置
|
|
hiddenPosition = new Vector2(-Screen.width, clueBoardRectTransform.anchoredPosition.y); // 屏幕右侧
|
|
visiblePosition = new Vector2(0, clueBoardRectTransform.anchoredPosition.y); // 屏幕内
|
|
|
|
// 设置初始位置和状态
|
|
clueBoardRectTransform.anchoredPosition = hiddenPosition;
|
|
clueBoardUI.SetActive(false);
|
|
|
|
toggleButton.onClick.AddListener(ToggleClueBoard); // 绑定按钮事件
|
|
submitButton.onClick.AddListener(CheckCurrentSlot); // 绑定提交事件
|
|
|
|
conclue.text="待分析症状";
|
|
|
|
// 初始化第一个ClueSlot
|
|
AddNewClueSlot();
|
|
}
|
|
|
|
// 开启或关闭 ClueBoard
|
|
private void ToggleClueBoard()
|
|
{
|
|
if (isBoardOpen)
|
|
{
|
|
CloseClueBoard();
|
|
}
|
|
else
|
|
{
|
|
OpenClueBoard();
|
|
}
|
|
}
|
|
|
|
private void OpenClueBoard()
|
|
{
|
|
clueBoardUI.SetActive(true);
|
|
isBoardOpen = true;
|
|
|
|
// 用DOTween从右侧移动到可见区域
|
|
clueBoardRectTransform.DOAnchorPos(visiblePosition, 0.5f);
|
|
}
|
|
|
|
private void CloseClueBoard()
|
|
{
|
|
isBoardOpen = false;
|
|
|
|
// 用DOTween移动回右侧屏幕外
|
|
clueBoardRectTransform.DOAnchorPos(hiddenPosition, 0.5f).OnComplete(() =>
|
|
{
|
|
clueBoardUI.SetActive(false); // 移动完成后隐藏UI
|
|
});
|
|
}
|
|
|
|
// 添加新的 ClueSlot
|
|
private void AddNewClueSlot()
|
|
{
|
|
ClueSlotBase newSlot = Instantiate(initialClueSlotPrefab, clueSlotContainer);
|
|
newSlot.ReleaseSlot(); // 初始化插槽为未占用状态
|
|
clueSlots.Add(newSlot);
|
|
}
|
|
|
|
private void CheckCurrentSlot()
|
|
{
|
|
if (currentStep >= clueSlots.Count) return;
|
|
|
|
ClueSlotBase currentSlot = clueSlots[currentStep];
|
|
if (!currentSlot.isOccupied)
|
|
{
|
|
conclue.text="还有待填入的症状";
|
|
Debug.Log("Slot is empty. Please insert a Clue.");
|
|
return;
|
|
}
|
|
|
|
Clue currentClue = currentSlot.GetComponentInChildren<ClueItem>()?.GetClueData();
|
|
if (currentClue == null) return;
|
|
|
|
// // 执行判定逻辑
|
|
if (IsValidClueForStep(currentStep, currentClue))
|
|
{
|
|
|
|
Debug.Log("Correct Clue for step " + currentStep);
|
|
currentStep++;
|
|
|
|
if (HasNextStep())
|
|
{
|
|
conclue.text="正确,但似乎这个症状不是源头";
|
|
AddNewClueSlot();
|
|
}
|
|
else
|
|
{
|
|
conclue.text="完成分析";
|
|
DialogController.Instance.StartDialogNode("结论");
|
|
Debug.Log("All steps completed. Puzzle is solved!");
|
|
}
|
|
}
|
|
else
|
|
{
|
|
conclue.text="症状分析错误";
|
|
Debug.Log("Incorrect Clue. Please try again.");
|
|
}
|
|
}
|
|
|
|
// 根据步骤判定当前 Clue 是否符合条件
|
|
private bool IsValidClueForStep(int step, Clue clue)
|
|
{
|
|
switch (step)
|
|
{
|
|
case 0:
|
|
return clue.Category == "UFView"; // 第一关要求Clue的Category为"UF"
|
|
case 1:
|
|
Clue previousClue = clueSlots[step - 1].GetComponentInChildren<ClueItem>()?.GetClueData();
|
|
return clue.Category == "MemoryView" && clue.MatchCode == previousClue?.MatchCode; // 第二关要求Category为"Memory"且匹配MatchCode
|
|
// 可以根据需要继续添加更多步骤和判定规则
|
|
case 2:
|
|
Clue previousClue2 = clueSlots[step - 1].GetComponentInChildren<ClueItem>()?.GetClueData();
|
|
return clue.Category == "EyeView" && clue.MatchCode == previousClue2?.MatchCode; // 第二关要求Category为"EyeView"且匹配MatchCode
|
|
// 可以根据需要继续添加更多步骤和判定规则
|
|
default:
|
|
return false;
|
|
}
|
|
}
|
|
|
|
// // 检查是否包含下一步
|
|
private bool HasNextStep()
|
|
{
|
|
return currentStep < 3;
|
|
}
|
|
}
|