172 lines
6.0 KiB
C#
172 lines
6.0 KiB
C#
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using System.Collections.Generic;
|
|
using System.Collections;
|
|
using DG.Tweening;
|
|
using TMPro;
|
|
using AibisDream;
|
|
using Yarn.Unity;
|
|
|
|
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显示时的位置
|
|
[YarnCommand("wait_for_ClueBoard_close")]
|
|
public IEnumerator WaitForClose()
|
|
{
|
|
// 这里等待关闭按钮点击事件
|
|
while (isBoardOpen)
|
|
{
|
|
yield return null; // 每帧检查一次
|
|
}
|
|
}
|
|
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();
|
|
}
|
|
}
|
|
[YarnCommand("OpenClueBoard")]
|
|
public 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
|
|
[YarnCommand("AddNewClueSlot")]
|
|
public void AddNewClueSlot()
|
|
{
|
|
ClueSlotBase newSlot = Instantiate(initialClueSlotPrefab, clueSlotContainer);
|
|
newSlot.ReleaseSlot();
|
|
clueSlots.Add(newSlot);
|
|
}
|
|
[YarnCommand("SetSlotCorrect")]
|
|
public void SetSlotCorrect()
|
|
{
|
|
clueSlots[currentStep].SetSlotCorrect();
|
|
currentStep++;
|
|
}
|
|
|
|
private void CheckCurrentSlot()
|
|
{
|
|
if (currentStep >= clueSlots.Count) return;
|
|
|
|
ClueSlotBase currentSlot = clueSlots[currentStep];
|
|
Clue currentClue = currentSlot.GetComponentInChildren<ClueItem>()?.GetClueData();
|
|
|
|
if (currentClue == null)
|
|
{
|
|
TriggerDialogue("", "", "", currentStep);
|
|
return;
|
|
}
|
|
|
|
// Trigger Yarn to handle the current clue, name, and step
|
|
TriggerDialogue(currentClue.Category, currentClue.MatchCode, currentClue.ClueName, currentStep);
|
|
}
|
|
private void TriggerDialogue(string clueCategory, string matchCode, string clueName, int step)
|
|
{
|
|
if (DialogController.Instance.CheckIfNodeExistInCurrentYarnProject("ClueBoard"))
|
|
{
|
|
// Set Yarn variables
|
|
DialogController.Instance.SetVariable("$clueBoardStep", step);
|
|
DialogController.Instance.SetVariable("$clueCategory", clueCategory);
|
|
DialogController.Instance.SetVariable("$clueMatchCode", matchCode);
|
|
DialogController.Instance.SetVariable("$clueName", clueName);
|
|
|
|
// Set the previous MatchCode for comparison in Yarn
|
|
if (step > 0)
|
|
{
|
|
Clue previousClue = clueSlots[step - 1].GetComponentInChildren<ClueItem>()?.GetClueData();
|
|
if (previousClue != null)
|
|
{
|
|
DialogController.Instance.SetVariable("$previousMatchCode", previousClue.MatchCode);
|
|
}
|
|
}
|
|
|
|
// Start the Yarn dialog node
|
|
DialogController.Instance.StartDialogNode("ClueBoard");
|
|
}
|
|
}
|
|
|
|
// 根据步骤判定当前 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;
|
|
// }
|
|
}
|