主流程跑通
This commit is contained in:
@@ -88,77 +88,84 @@ public class ClueBoardManager : MonoBehaviour
|
||||
}
|
||||
|
||||
// 添加新的 ClueSlot
|
||||
private void AddNewClueSlot()
|
||||
[YarnCommand("AddNewClueSlot")]
|
||||
public void AddNewClueSlot()
|
||||
{
|
||||
ClueSlotBase newSlot = Instantiate(initialClueSlotPrefab, clueSlotContainer);
|
||||
newSlot.ReleaseSlot(); // 初始化插槽为未占用状态
|
||||
newSlot.ReleaseSlot();
|
||||
clueSlots.Add(newSlot);
|
||||
}
|
||||
[YarnCommand("SetSlotCorrect")]
|
||||
public void SetSlotCorrect()
|
||||
{
|
||||
clueSlots[currentStep].SetSlotCorrect();
|
||||
currentStep++;
|
||||
}
|
||||
|
||||
private void CheckCurrentSlot()
|
||||
{
|
||||
if (currentStep >= clueSlots.Count) return;
|
||||
if (currentStep >= clueSlots.Count) return;
|
||||
|
||||
ClueSlotBase currentSlot = clueSlots[currentStep];
|
||||
if (!currentSlot.isOccupied)
|
||||
ClueSlotBase currentSlot = clueSlots[currentStep];
|
||||
Clue currentClue = currentSlot.GetComponentInChildren<ClueItem>()?.GetClueData();
|
||||
|
||||
if (currentClue == null)
|
||||
{
|
||||
conclue.text="还有待填入的症状";
|
||||
Debug.Log("Slot is empty. Please insert a Clue.");
|
||||
TriggerDialogue("", "", "", currentStep);
|
||||
return;
|
||||
}
|
||||
|
||||
Clue currentClue = currentSlot.GetComponentInChildren<ClueItem>()?.GetClueData();
|
||||
if (currentClue == null) 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);
|
||||
|
||||
// // 执行判定逻辑
|
||||
if (IsValidClueForStep(currentStep, currentClue))
|
||||
// Set the previous MatchCode for comparison in Yarn
|
||||
if (step > 0)
|
||||
{
|
||||
|
||||
Debug.Log("Correct Clue for step " + currentStep);
|
||||
currentStep++;
|
||||
|
||||
if (HasNextStep())
|
||||
Clue previousClue = clueSlots[step - 1].GetComponentInChildren<ClueItem>()?.GetClueData();
|
||||
if (previousClue != null)
|
||||
{
|
||||
conclue.text="正确,但似乎这个症状不是源头";
|
||||
AddNewClueSlot();
|
||||
}
|
||||
else
|
||||
{
|
||||
conclue.text="完成分析";
|
||||
DialogController.Instance.StartDialogNode("结论");
|
||||
Debug.Log("All steps completed. Puzzle is solved!");
|
||||
DialogController.Instance.SetVariable("$previousMatchCode", previousClue.MatchCode);
|
||||
}
|
||||
}
|
||||
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;
|
||||
// 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;
|
||||
// }
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.Generic;
|
||||
using AibisDream;
|
||||
using Unity.VisualScripting;
|
||||
using UnityEngine;
|
||||
using UnityEngine.UI;
|
||||
@@ -17,10 +18,11 @@ public class ClueManager : MonoBehaviour
|
||||
}
|
||||
void Update()
|
||||
{
|
||||
// if(Input.GetKeyDown(KeyCode.U))
|
||||
// {
|
||||
// GenerateUFClue("错误绘制","UFView","can_grass_error","绿色");
|
||||
// }
|
||||
if(Input.GetKeyDown(KeyCode.U))
|
||||
{
|
||||
DialogController.Instance.StartDialogNode("AddAllClueToFavorites");
|
||||
//GenerateUFClue("错误绘制","UFView","can_grass_error","绿色");
|
||||
}
|
||||
// if(Input.GetKeyDown(KeyCode.M))
|
||||
// {
|
||||
// GenerateMemoryClue("草地","MemoryView","liuying1-2","绿色");
|
||||
@@ -62,28 +64,44 @@ public class ClueManager : MonoBehaviour
|
||||
}
|
||||
//用于生成打孔带的函数
|
||||
[YarnCommand("generate_PunchTape")]
|
||||
public void GeneratePunchTape(string clueName, string category, string memoryIndex,string mathCode=null)
|
||||
public void GeneratePunchTape(string clueName, string category, string memoryIndex,string mathCode=null,bool directlyAddToFavorites=false)
|
||||
{
|
||||
PunchTape punchTape = new PunchTape(category, clueName, memoryIndex,mathCode);
|
||||
|
||||
if(directlyAddToFavorites)
|
||||
{
|
||||
FavoritesManager.Instance.AddClue(punchTape);
|
||||
return;
|
||||
}
|
||||
GameObject clueGO = Instantiate(punchTapecluePrefab, canvas.transform);
|
||||
|
||||
ClueItem clueItem = clueGO.GetComponent<ClueItem>();
|
||||
clueItem.Setup(punchTape);
|
||||
}
|
||||
[YarnCommand("generate_UFClue")]
|
||||
public void GenerateUFClue(string clueName, string imageName,string mathCode)
|
||||
public void GenerateUFClue(string clueName, string imageName,string mathCode,bool directlyAddToFavorites=false)
|
||||
{
|
||||
Sprite UFSprite = Resources.Load<Sprite>("Art/Photos/" + imageName);
|
||||
ImageClue imageClue=new ImageClue("UFView", clueName, UFSprite,mathCode);
|
||||
if(directlyAddToFavorites)
|
||||
{
|
||||
FavoritesManager.Instance.AddClue(imageClue);
|
||||
return;
|
||||
}
|
||||
GameObject clueGO = Instantiate(imageCluePrefab, canvas.transform);
|
||||
ClueItem clueItem = clueGO.GetComponent<ClueItem>();
|
||||
clueItem.Setup(imageClue);
|
||||
}
|
||||
[YarnCommand("generate_MemoryClue")]
|
||||
public void GenerateMemoryClue(string clueName, string imageName,string mathCode)
|
||||
public void GenerateMemoryClue(string clueName, string imageName,string mathCode,bool directlyAddToFavorites=false)
|
||||
{
|
||||
Sprite UFSprite = Resources.Load<Sprite>("Art/Memory/" + imageName);
|
||||
ImageClue imageClue=new ImageClue("MemoryView", clueName, UFSprite,mathCode);
|
||||
if(directlyAddToFavorites)
|
||||
{
|
||||
FavoritesManager.Instance.AddClue(imageClue);
|
||||
return;
|
||||
}
|
||||
GameObject clueGO = Instantiate(imageCluePrefab, canvas.transform);
|
||||
ClueItem clueItem = clueGO.GetComponent<ClueItem>();
|
||||
clueItem.Setup(imageClue);
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class ClueSlotBase : MonoBehaviour, IDropHandler
|
||||
{
|
||||
@@ -16,9 +18,18 @@ public class ClueSlotBase : MonoBehaviour, IDropHandler
|
||||
[HideInInspector]
|
||||
public bool isLocked = false; // 插槽是否已占用
|
||||
|
||||
private Image slotFrame;
|
||||
|
||||
protected virtual void Start()
|
||||
{
|
||||
currentClueItem = null;
|
||||
slotFrame=transform.GetChild(0).GetComponent<Image>();
|
||||
slotFrame.color=Color.white;
|
||||
}
|
||||
public void SetSlotCorrect()
|
||||
{
|
||||
slotFrame.color=Color.green;
|
||||
SetSlotLockState(true);
|
||||
}
|
||||
|
||||
public void OnDrop(PointerEventData eventData)
|
||||
@@ -94,8 +105,6 @@ public class ClueSlotBase : MonoBehaviour, IDropHandler
|
||||
if (clueItem != null)
|
||||
{
|
||||
ClueInteraction clueInteraction = clueItem.GetComponent<ClueInteraction>();
|
||||
RectTransform transform=clueInteraction.GetComponent<RectTransform>();
|
||||
transform=OriginalTransform;
|
||||
clueInteraction?.ReturnToOriginalPosition(); // 返回到原位的逻辑
|
||||
// 你也可以在这里添加额外的逻辑来处理集合的更新
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user