增加了messagebox显示的命令和功能,另外为对话暂停做了一些事件准备
This commit is contained in:
@@ -14,12 +14,17 @@ namespace AibisDream
|
||||
|
||||
private Dictionary<string, Action<YarnOption[]>> commandMap = new();
|
||||
|
||||
public static event Action OnDialogueStart;
|
||||
public static event Action OnDialogueComplete;
|
||||
|
||||
public bool quickRunMode;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
_variableStorage = GetComponentInChildren<InMemoryVariableStorage>();
|
||||
dialogueRunner.onDialogueStart.AddListener(() => OnDialogueStart?.Invoke());
|
||||
dialogueRunner.onDialogueComplete.AddListener(() => OnDialogueComplete?.Invoke());
|
||||
}
|
||||
|
||||
#region 变量操作
|
||||
|
||||
@@ -4,6 +4,7 @@ using UnityEngine.EventSystems;
|
||||
using UnityEngine.UI;
|
||||
using System.Linq;
|
||||
using DG.Tweening;
|
||||
using AibisDream;
|
||||
|
||||
public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUpHandler
|
||||
{
|
||||
@@ -16,6 +17,7 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
private Quaternion pickupRotationOffset = Quaternion.Euler(0, 0, 30);
|
||||
public Socket initialSocket; // new variable
|
||||
public Image plugSprite; // new variable
|
||||
public bool IsInDialogue { get; set; } = false;
|
||||
|
||||
private void Awake()
|
||||
{
|
||||
@@ -27,16 +29,38 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
startPosition = initialSocket.GetPosition();
|
||||
|
||||
transform.position = startPosition;
|
||||
//startRotation = initialSocket.GetRotation();
|
||||
|
||||
// Insert the plug into the initial socket and make the sprite disappear.
|
||||
initialSocket.InsertPlug(this);
|
||||
plugSprite.enabled = false;
|
||||
DialogController.OnDialogueStart += HandleDialogueStart;
|
||||
DialogController.OnDialogueComplete += HandleDialogueComplete;
|
||||
}
|
||||
void OnDestroy()
|
||||
{
|
||||
// Unsubscribe from dialogue events
|
||||
DialogController.OnDialogueStart -= HandleDialogueStart;
|
||||
DialogController.OnDialogueComplete -= HandleDialogueComplete;
|
||||
}
|
||||
void HandleDialogueStart()
|
||||
{
|
||||
// Dialogue has started, disable plug interactions
|
||||
IsInDialogue = true;
|
||||
Debug.Log("in dialogue");
|
||||
}
|
||||
|
||||
void HandleDialogueComplete()
|
||||
{
|
||||
// Dialogue has completed, enable plug interactions
|
||||
IsInDialogue = false;
|
||||
Debug.Log("dialoguecompleted");
|
||||
}
|
||||
|
||||
|
||||
public void OnPointerDown(PointerEventData eventData)
|
||||
{
|
||||
if (IsInDialogue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isDragging = true;
|
||||
image.raycastTarget = false;
|
||||
currentSocket?.RemovePlug(this);
|
||||
@@ -49,6 +73,10 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
|
||||
public void OnDrag(PointerEventData eventData)
|
||||
{
|
||||
if (IsInDialogue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (isDragging)
|
||||
{
|
||||
Vector3 screenPosition = new Vector3(eventData.position.x, eventData.position.y,
|
||||
@@ -61,6 +89,10 @@ public class Plug : MonoBehaviour, IDragHandler, IPointerDownHandler, IPointerUp
|
||||
|
||||
public void OnPointerUp(PointerEventData eventData)
|
||||
{
|
||||
if (IsInDialogue)
|
||||
{
|
||||
return;
|
||||
}
|
||||
isDragging = false;
|
||||
image.raycastTarget = true;
|
||||
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 96c710ec3df0efb4da61a5dc0401c01b
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,42 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
using TMPro;
|
||||
using Yarn.Unity;
|
||||
|
||||
public class MessageBox : MonoBehaviour
|
||||
{
|
||||
public TMP_Text messageText; // Unity UI Text component
|
||||
|
||||
public void SetWarning(string message)
|
||||
{
|
||||
messageText.color = Color.red; // Set text color to red for warnings
|
||||
messageText.text = message;
|
||||
}
|
||||
|
||||
public void SetNormal(string message)
|
||||
{
|
||||
messageText.color = Color.black; // Set text color to black for normal messages
|
||||
messageText.text = message;
|
||||
}
|
||||
|
||||
[YarnCommand("messagebox")]
|
||||
public void HandleMessageBoxCommand(string type,string text)
|
||||
{
|
||||
// 根据消息类型调用相应的方法
|
||||
if (type == "warning")
|
||||
{
|
||||
SetWarning(text);
|
||||
}
|
||||
else if (type == "normal")
|
||||
{
|
||||
SetNormal(text);
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.LogError("Invalid message type for messagebox command: " + type);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: b8075ce97e8dbfd48b3f4b3ac09b1ded
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user