feat(save): 添加可存点判定器与节点事件触发机制
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.SaveSystem;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Events;
|
||||
using AibisDream.Framework;
|
||||
@@ -16,20 +17,30 @@ namespace AibisDream
|
||||
|
||||
[SerializeField] private LineAdvanceInput lineAdvanceInput;
|
||||
|
||||
private string _currentNodeName;
|
||||
private string[] _currentNodeTags;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
_dialogueRunner.onDialogueStart ??= new UnityEvent();
|
||||
_dialogueRunner.onDialogueComplete ??= new UnityEvent();
|
||||
_dialogueRunner.onNodeStart ??= new UnityEventString();
|
||||
_dialogueRunner.onNodeComplete ??= new UnityEventString();
|
||||
|
||||
_dialogueRunner.onDialogueStart.AddListener(() =>
|
||||
{
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.DialogStart);
|
||||
});
|
||||
|
||||
_dialogueRunner.onDialogueComplete.AddListener(() =>
|
||||
{
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.DialogEnd);
|
||||
ClearCurrentNodeContext();
|
||||
});
|
||||
|
||||
_dialogueRunner.onNodeStart.AddListener(OnNodeStart);
|
||||
_dialogueRunner.onNodeComplete.AddListener(OnNodeComplete);
|
||||
}
|
||||
|
||||
private void OnEnable()
|
||||
@@ -140,30 +151,45 @@ namespace AibisDream
|
||||
/// </summary>
|
||||
public (string nodeName, IReadOnlyList<string> tags) GetCurrentNodeContext()
|
||||
{
|
||||
if (_dialogueRunner == null)
|
||||
if (string.IsNullOrEmpty(_currentNodeName))
|
||||
{
|
||||
return (null, Array.Empty<string>());
|
||||
}
|
||||
|
||||
var dialogue = _dialogueRunner.Dialogue;
|
||||
if (dialogue == null)
|
||||
return (_currentNodeName, _currentNodeTags ?? Array.Empty<string>());
|
||||
}
|
||||
|
||||
private void OnNodeStart(string nodeName)
|
||||
{
|
||||
UpdateCurrentNodeContext(nodeName);
|
||||
SaveRestoreOrchestrator.TryAutoSave();
|
||||
}
|
||||
|
||||
private void OnNodeComplete(string nodeName)
|
||||
{
|
||||
ClearCurrentNodeContext();
|
||||
}
|
||||
|
||||
private void UpdateCurrentNodeContext(string nodeName)
|
||||
{
|
||||
if (_dialogueRunner == null || _dialogueRunner.Dialogue == null)
|
||||
{
|
||||
return (null, Array.Empty<string>());
|
||||
ClearCurrentNodeContext();
|
||||
return;
|
||||
}
|
||||
|
||||
var nodeName = dialogue.CurrentNode;
|
||||
if (string.IsNullOrEmpty(nodeName))
|
||||
{
|
||||
return (null, Array.Empty<string>());
|
||||
}
|
||||
_currentNodeName = nodeName;
|
||||
|
||||
var tagsHeader = dialogue.GetHeaderValue(nodeName, "tags");
|
||||
if (string.IsNullOrWhiteSpace(tagsHeader))
|
||||
{
|
||||
return (nodeName, Array.Empty<string>());
|
||||
}
|
||||
var tagsHeader = _dialogueRunner.Dialogue.GetHeaderValue(nodeName, "tags");
|
||||
_currentNodeTags = string.IsNullOrWhiteSpace(tagsHeader)
|
||||
? Array.Empty<string>()
|
||||
: tagsHeader.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries);
|
||||
}
|
||||
|
||||
return (nodeName, tagsHeader.Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries));
|
||||
private void ClearCurrentNodeContext()
|
||||
{
|
||||
_currentNodeName = null;
|
||||
_currentNodeTags = null;
|
||||
}
|
||||
|
||||
#region 推进方式修改
|
||||
|
||||
Reference in New Issue
Block a user