Files
Net.Like.Xue.Tokyo/Packages-Local/Com.Project.B.Unity/NodeCanvas/ComicNode.cs

55 lines
1.6 KiB
C#
Raw Normal View History

2025-06-24 23:49:13 +08:00
using System.Collections;
using System.Collections.Generic;
using BITKit;
using Microsoft.Extensions.DependencyInjection;
using Net.Project.B.Dialogue;
using NodeCanvas.DialogueTrees;
using NodeCanvas.Framework;
using ParadoxNotion;
using ParadoxNotion.Design;
using UnityEngine;
namespace Net.Project.B.DialogueTrees
{
[Name("Comic")]
[Description(
"Make the selected Dialogue Actor talk. You can make the text more dynamic by using variable names in square brackets\ne.g. [myVarName] or [Global/myVarName]")]
public class ComicNode : DTNode
{
[SerializeField] public Sprite sprite;
[SerializeField] public string text;
protected override Status OnExecute(Component agent, IBlackboard blackboard)
{
var dialogueService = BITApp.ServiceProvider.GetRequiredService<IDialogueService>();
var dialogue = new DialogueData()
{
MetaObject = sprite,
Text=text,
CancellationTokenSource = new()
};
dialogueService.CreateDialogue(dialogue);
dialogue.CancellationTokenSource.Token.Register(Success);
return Status.Running;
}
private void Success()
{
status = Status.Success;
DLGTree.Continue();
}
#if UNITY_EDITOR
protected override void OnNodeGUI() {
GUILayout.BeginVertical(Styles.roundedBox);
GUILayout.Label("\"<i> " + text.CapLength(30) + "</i> \"");
GUILayout.EndVertical();
}
#endif
}
}