深入模块的各种特殊处理以及对话处理
This commit is contained in:
@@ -6,6 +6,7 @@ using System.Linq;
|
||||
using DG.Tweening;
|
||||
using AibisDream;
|
||||
using Yarn.Unity;
|
||||
using System;
|
||||
|
||||
public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
@@ -32,6 +33,8 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
get { return cableref; }
|
||||
set { cableref = value; }
|
||||
}
|
||||
public event Action<Plug> OnPlugInserted;
|
||||
public event Action OnPlugRemoved;
|
||||
|
||||
|
||||
private void Awake()
|
||||
@@ -102,6 +105,7 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
// 通知 DialogueManager 开始拖拽
|
||||
DialogueManager.Instance.SetDragging(true);
|
||||
currentSocket?.RemovePlug(this);
|
||||
OnPlugRemoved?.Invoke();
|
||||
|
||||
plugSprite.enabled = true;
|
||||
|
||||
@@ -167,6 +171,7 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
{
|
||||
currentSocket = closestSocket;
|
||||
currentSocket.InsertPlug(this);
|
||||
OnPlugInserted?.Invoke(this); // 触发插入事件
|
||||
transform.position = currentSocket.GetPosition();
|
||||
plugSprite.enabled = false;
|
||||
//transform.rotation = startRotation;
|
||||
@@ -177,6 +182,7 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
{
|
||||
//transform.rotation = startRotation;
|
||||
initialSocket.InsertPlug(this);
|
||||
OnPlugInserted?.Invoke(this); // 触发插入事件
|
||||
plugSprite.enabled =false; // Make the plug sprite disappear when it is inserted into the initial socket.
|
||||
});
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
using AibisDream;
|
||||
using UnityEngine;
|
||||
using System;
|
||||
|
||||
public class Socket : MonoBehaviour, ISocket
|
||||
{
|
||||
@@ -7,18 +8,26 @@ public class Socket : MonoBehaviour, ISocket
|
||||
public Vector2 InsertionPoint => transform.position;
|
||||
private Plug plug=null;
|
||||
private YarnOption _option;
|
||||
public bool waitYarnCommand=false;
|
||||
private bool waitYarnCommand = false;
|
||||
|
||||
public bool WaitYarnCommand
|
||||
{
|
||||
get { return waitYarnCommand; }
|
||||
}
|
||||
|
||||
public bool notAlowedDeep=false;
|
||||
[HideInInspector]
|
||||
public TargetPointData targetData; // 新增属性
|
||||
|
||||
|
||||
|
||||
public YarnOption Option
|
||||
|
||||
{
|
||||
set => _option = value;
|
||||
}
|
||||
|
||||
|
||||
public void Start()
|
||||
{
|
||||
targetData=transform.GetComponent<TargetPointData>();
|
||||
|
||||
@@ -8,6 +8,7 @@ using DG.Tweening;
|
||||
using TMPro;
|
||||
using UnityEditor.Localization.Plugins.XLIFF.V20;
|
||||
using AibisDream;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class OscilloscopeController : MonoBehaviour
|
||||
{
|
||||
@@ -32,6 +33,8 @@ public class OscilloscopeController : MonoBehaviour
|
||||
|
||||
public TMP_Text screenText;
|
||||
|
||||
private Socket currentSocket;
|
||||
|
||||
void Start()
|
||||
{
|
||||
scanLine.startWidth=0.05f;
|
||||
@@ -41,6 +44,7 @@ public class OscilloscopeController : MonoBehaviour
|
||||
plug = FindObjectOfType<Plug>();
|
||||
DeepInButton.GetComponent<Button>().onClick.AddListener(DeepIn);
|
||||
screenText.text="";
|
||||
currentSocket=null;
|
||||
|
||||
}
|
||||
|
||||
@@ -51,7 +55,7 @@ public class OscilloscopeController : MonoBehaviour
|
||||
Debug.Log("未找到插头");
|
||||
return;
|
||||
}
|
||||
var currentSocket = plug.currentSocket;
|
||||
currentSocket = plug.currentSocket;
|
||||
|
||||
if (currentSocket == null || currentSocket.targetData == null)
|
||||
{
|
||||
@@ -62,18 +66,83 @@ public class OscilloscopeController : MonoBehaviour
|
||||
|
||||
string originalString = currentSocket.name;
|
||||
string trimmedString = originalString.Replace("Socket", "");
|
||||
string yarnString = "On"+trimmedString+"DeepIn";
|
||||
|
||||
if(!currentSocket.waitYarnCommand)
|
||||
if(currentSocket.WaitYarnCommand)
|
||||
{
|
||||
StartCoroutine(ScanForError(trimmedString)); // 启动扫描协程
|
||||
// DialogController.Instance.SetVariable("$ViewToDeepIn",trimmedString);
|
||||
// DialogController.Instance.StartDialogNode("DeepInView");
|
||||
}
|
||||
else if(currentSocket.targetData.HasExternalError())
|
||||
{
|
||||
transitionManager.SetViewAvailability(trimmedString, true);
|
||||
DeepInButton.interactable=false;
|
||||
HandleDeepIn();
|
||||
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
DialogController.Instance.SetVariable("$ViewToDeepIn",trimmedString);
|
||||
DialogController.Instance.StartDialogNode("DeepInView");
|
||||
StartCoroutine(ScanForError(trimmedString)); // 启动扫描协程
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
private void DeepInexecution()
|
||||
{
|
||||
string originalString = currentSocket.name;
|
||||
string trimmedString = originalString.Replace("Socket", "");
|
||||
StartCoroutine(transitionManager.StartTransitionCoroutine(trimmedString));
|
||||
DeepInButton.interactable=true;
|
||||
phaseSlider.interactable=true;
|
||||
screenText.text="";
|
||||
plug.Enable_plugInput();
|
||||
|
||||
}
|
||||
private void HandleDeepIn()
|
||||
{
|
||||
if(currentSocket.notAlowedDeep)
|
||||
{
|
||||
screenText.text="特殊保护,禁止深入模块";
|
||||
DeepInButton.interactable=true;
|
||||
phaseSlider.interactable=true;
|
||||
//screenText.text="";
|
||||
plug.Enable_plugInput();
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
screenText.text="错误找到,开始深入准备";
|
||||
}
|
||||
string originalString = currentSocket.name;
|
||||
string trimmedString = originalString.Replace("Socket", "");
|
||||
string yarnString = "On"+trimmedString+"DeepIn";
|
||||
if(DialogController.Instance.CheckIfNodeExistInCurrentYarnProject(yarnString))
|
||||
{
|
||||
DialogController.Instance.StartDialogNode(yarnString);
|
||||
if(!currentSocket.notAlowedDeep)
|
||||
{
|
||||
DialogController.OnDialogueComplete+=DeepInexecution;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(!currentSocket.notAlowedDeep)
|
||||
{
|
||||
DeepInexecution();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
void HandleExternalError()
|
||||
{
|
||||
scanLine.gameObject.SetActive(false);
|
||||
phaseSlider.interactable = false;
|
||||
waveformVisualizer.gameObject.SetActive(false);
|
||||
screenText.text = "外部错误已关联,可以直接深入";
|
||||
}
|
||||
|
||||
private IEnumerator ScanForError(string trimmedString)
|
||||
{
|
||||
phaseSlider.interactable=false;
|
||||
@@ -120,17 +189,12 @@ private IEnumerator ScanForError(string trimmedString)
|
||||
|
||||
scanLine.startColor = Color.red;
|
||||
scanLine.endColor = Color.red;
|
||||
Debug.Log("找到错误,可以开始深入");
|
||||
screenText.text="找到错误,可以开始深入";
|
||||
//Debug.Log("找到错误,可以开始深入");
|
||||
//screenText.text="找到错误,可以开始深入";
|
||||
yield return new WaitForSeconds(1f);
|
||||
transitionManager.SetViewAvailability(trimmedString, true);
|
||||
DeepInButton.interactable=false;
|
||||
StartCoroutine(transitionManager.StartTransitionCoroutine(trimmedString));
|
||||
yield return new WaitForSeconds(0.5f);
|
||||
DeepInButton.interactable=true;
|
||||
phaseSlider.interactable=true;
|
||||
screenText.text="";
|
||||
plug.Enable_plugInput();
|
||||
HandleDeepIn();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -169,6 +233,13 @@ private IEnumerator ScanForError(string trimmedString)
|
||||
var targetData = currentSocket.targetData;
|
||||
if (targetData != null)
|
||||
{
|
||||
if(targetData.HasExternalError())
|
||||
{
|
||||
|
||||
screenText.text="外部错误已关联,可以直接深入";
|
||||
return;
|
||||
}
|
||||
|
||||
if(!setInitSliderValue)
|
||||
{
|
||||
setInitSliderValue=true;
|
||||
|
||||
@@ -2,24 +2,29 @@ using UnityEngine;
|
||||
|
||||
public class TargetPointData : MonoBehaviour
|
||||
{
|
||||
public WaveformType waveformType = WaveformType.Sine; // 正常波形类型
|
||||
public bool isCorrect = true; // 是否为正确模块
|
||||
//public WaveformType errorWaveformType = WaveformType.Spike; // 错误波形类型(如果有错误)
|
||||
public WaveformType waveformType = WaveformType.Sine; // 正常波形类型
|
||||
public bool isCorrect = true; // 是否为正确模块
|
||||
public bool isExternalError = false; // 是否为外部错误
|
||||
|
||||
public bool HasExternalError()
|
||||
{
|
||||
return isExternalError;
|
||||
}
|
||||
|
||||
[HideInInspector]
|
||||
public int randomShift;
|
||||
[HideInInspector]
|
||||
public float initialRandomPhase; // 随机初始相位
|
||||
[HideInInspector]
|
||||
public int spikeIndex=-1;
|
||||
|
||||
[HideInInspector]
|
||||
public float sliderValue=-1;
|
||||
public float initialRandomPhase; // 随机初始相位
|
||||
[HideInInspector]
|
||||
public int spikeIndex = -1;
|
||||
[HideInInspector]
|
||||
public float sliderValue = -1;
|
||||
|
||||
void Start()
|
||||
{
|
||||
randomShift = Random.Range(7, 13);
|
||||
initialRandomPhase = Mathf.PI * randomShift*0.1f; // 随机初始相位
|
||||
//initialRandomPhase = Mathf.PI * 1f; // 随机初始相位
|
||||
}
|
||||
void Start()
|
||||
{
|
||||
randomShift = Random.Range(7, 13);
|
||||
initialRandomPhase = Mathf.PI * randomShift * 0.1f; // 随机初始相位
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -30,12 +30,12 @@ public class DialogueManager : MonoBehaviour
|
||||
if (isHovering)
|
||||
{
|
||||
// 设置悬停光标
|
||||
MouseCursorManager.Instance.SetCursor(MouseCursorManager.Instance.dialogueCursor);
|
||||
//MouseCursorManager.Instance.SetCursor(MouseCursorManager.Instance.dialogueCursor);
|
||||
}
|
||||
else
|
||||
{
|
||||
// 重置光标
|
||||
MouseCursorManager.Instance.ResetCursor();
|
||||
//MouseCursorManager.Instance.ResetCursor();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,10 +48,10 @@ public class DialogueManager : MonoBehaviour
|
||||
string dialogueNode = interactable.gameObject.name + "Dialogue";
|
||||
|
||||
// 检查节点是否存在并触发对话
|
||||
if(DialogController.Instance.CheckIfNodeExistInCurrentYarnProject(dialogueNode))
|
||||
{
|
||||
DialogController.Instance.StartDialogNode(dialogueNode);
|
||||
}
|
||||
// if(DialogController.Instance.CheckIfNodeExistInCurrentYarnProject(dialogueNode))
|
||||
// {
|
||||
// DialogController.Instance.StartDialogNode(dialogueNode);
|
||||
// }
|
||||
}
|
||||
|
||||
public void SetDragging(bool dragging)
|
||||
|
||||
Reference in New Issue
Block a user