对话系统第一次修改
This commit is contained in:
@@ -19,9 +19,6 @@ namespace AibisDream
|
||||
|
||||
# endregion
|
||||
|
||||
public static UnityAction OnDialogueStart;
|
||||
public static UnityAction OnDialogueComplete;
|
||||
|
||||
private void Start()
|
||||
{
|
||||
_dialogueRunner = GetComponentInChildren<DialogueRunner>();
|
||||
@@ -29,16 +26,16 @@ namespace AibisDream
|
||||
|
||||
_dialogueRunner.onDialogueStart.AddListener(() =>
|
||||
{
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.End);
|
||||
OnDialogueStart?.Invoke();
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.DialogEnd);
|
||||
});
|
||||
_dialogueRunner.onDialogueComplete.AddListener(() =>
|
||||
{
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.Start);
|
||||
OnDialogueComplete?.Invoke();
|
||||
EnumEventSystem.Global.Send(InteractionEventEnum.DialogStart);
|
||||
});
|
||||
}
|
||||
|
||||
#region Yarn控制
|
||||
|
||||
/// <summary>
|
||||
/// 开启对话
|
||||
/// </summary>
|
||||
@@ -49,12 +46,7 @@ namespace AibisDream
|
||||
_lineProvider.InitStringTable(yarnProject.name);
|
||||
_dialogueRunner.StartDialogue("Start");
|
||||
}
|
||||
|
||||
public string GetCurLocalizedTableName()
|
||||
{
|
||||
return _lineProvider.GetStringTableName();
|
||||
}
|
||||
|
||||
|
||||
public void StopDialog()
|
||||
{
|
||||
_dialogueRunner.Stop();
|
||||
@@ -84,7 +76,7 @@ namespace AibisDream
|
||||
_dialogueRunner.StartDialogue(nodeName);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private bool CheckIfNodeExistInCurrentYarnProject(string nodeName)
|
||||
{
|
||||
YarnProject currentProject = _dialogueRunner.yarnProject;
|
||||
@@ -100,6 +92,8 @@ namespace AibisDream
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
/// <summary>
|
||||
/// 跳到下一句
|
||||
/// </summary>
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class LineAdvanceInput : MonoBehaviour
|
||||
{
|
||||
#region 状态
|
||||
|
||||
private bool _inGame;
|
||||
private bool _isDialog;
|
||||
private LineSyncToken _curSyncToken;
|
||||
|
||||
#endregion
|
||||
|
||||
[SerializeField] private KeyCode advanceKey;
|
||||
|
||||
private void OnEnable()
|
||||
{
|
||||
RegisterEvents();
|
||||
}
|
||||
|
||||
private void OnDisable()
|
||||
{
|
||||
UnRegisterEvents();
|
||||
}
|
||||
|
||||
public void RunLine(LineSyncToken lineSyncEvent)
|
||||
{
|
||||
_curSyncToken = lineSyncEvent;
|
||||
}
|
||||
|
||||
private bool IsInputAvailable()
|
||||
{
|
||||
return _inGame && _isDialog && _curSyncToken != null && _curSyncToken.state != LineSyncState.Advanced;
|
||||
}
|
||||
|
||||
private void OnAdvanceInput()
|
||||
{
|
||||
if (!IsInputAvailable())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (_curSyncToken.state)
|
||||
{
|
||||
case LineSyncState.PlayText:
|
||||
_curSyncToken.TrySkip();
|
||||
break;
|
||||
case LineSyncState.WaitForAdvance:
|
||||
_curSyncToken.TryAdvance();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
private void Update()
|
||||
{
|
||||
if (Input.GetMouseButtonDown(0) || Input.GetKeyDown(KeyCode.Space))
|
||||
{
|
||||
OnAdvanceInput();
|
||||
}
|
||||
}
|
||||
|
||||
#region 事件处理
|
||||
|
||||
private IUnRegister[] _unRegisters;
|
||||
|
||||
private void RegisterEvents()
|
||||
{
|
||||
_unRegisters = new IUnRegister[6];
|
||||
|
||||
_unRegisters[0] = EnumEventSystem.Global.Register(GameLoopEnum.GameStart, () => _inGame = true);
|
||||
_unRegisters[1] = EnumEventSystem.Global.Register(GameLoopEnum.UnPauseGame, () => _inGame = true);
|
||||
|
||||
_unRegisters[2] = EnumEventSystem.Global.Register(GameLoopEnum.GameQuit, () => _inGame = false);
|
||||
_unRegisters[3] = EnumEventSystem.Global.Register(GameLoopEnum.PauseGame, () => _inGame = false);
|
||||
|
||||
_unRegisters[4] = EnumEventSystem.Global.Register(InteractionEventEnum.DialogStart, () => _isDialog = true);
|
||||
_unRegisters[5] = EnumEventSystem.Global.Register(InteractionEventEnum.DialogEnd, () => _isDialog = true);
|
||||
}
|
||||
|
||||
private void UnRegisterEvents()
|
||||
{
|
||||
foreach (var unRegister in _unRegisters)
|
||||
{
|
||||
unRegister.UnRegister();
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4269da1f8c364e319da84b5fee61bafe
|
||||
timeCreated: 1761032421
|
||||
@@ -6,6 +6,9 @@ using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
/// <summary>
|
||||
/// 对话View,仅用于处理对话文本
|
||||
/// </summary>
|
||||
public class LineView : DialogueViewBase
|
||||
{
|
||||
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using AibisDream.Kit;
|
||||
using AibisDream.Utility;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class LineViewNew : DialogueViewBase
|
||||
{
|
||||
[SerializeField] private LineAdvanceInput advanceInput;
|
||||
// [SerializeField] private BubbleCenter bubbleCenter;
|
||||
|
||||
public override void RunLine(LocalizedLine dialogueLine, Action onDialogueLineFinished)
|
||||
{
|
||||
// 预处理Line和Event
|
||||
var lineSyncEvent = new LineSyncToken(dialogueLine, onDialogueLineFinished);
|
||||
// bubbleCenter.RunLine(lineSyncEvent);
|
||||
advanceInput.RunLine(lineSyncEvent);
|
||||
}
|
||||
}
|
||||
|
||||
public class LineSyncToken
|
||||
{
|
||||
public LineInfo lineInfo;
|
||||
public LineSyncState state;
|
||||
|
||||
public Action nextStep;
|
||||
public event Action SkipTextAnima;
|
||||
|
||||
public LineSyncToken(LocalizedLine lineInfo, Action nextStep)
|
||||
{
|
||||
this.lineInfo = LineInfo.Generate(lineInfo);
|
||||
this.nextStep = nextStep;
|
||||
state = LineSyncState.PlayText;
|
||||
}
|
||||
|
||||
public bool TrySkip()
|
||||
{
|
||||
if (state == LineSyncState.PlayText)
|
||||
{
|
||||
SkipTextAnima?.Invoke();
|
||||
SkipTextAnima = null;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"line{lineInfo.lineId} 状态为{state.ToString()}, 不能跳过文本");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public bool TryAdvance()
|
||||
{
|
||||
if (state == LineSyncState.WaitForAdvance)
|
||||
{
|
||||
nextStep?.Invoke();
|
||||
state = LineSyncState.Advanced;
|
||||
Dispose();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.Log($"line{lineInfo.lineId} 状态为{state.ToString()}, 不能向前推进");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void Dispose()
|
||||
{
|
||||
nextStep = null;
|
||||
SkipTextAnima = null;
|
||||
}
|
||||
|
||||
public void TextStart()
|
||||
{
|
||||
state = LineSyncState.PlayText;
|
||||
}
|
||||
|
||||
public void TextShown()
|
||||
{
|
||||
state = LineSyncState.AdvanceDelay;
|
||||
// 延时
|
||||
|
||||
state = LineSyncState.WaitForAdvance;
|
||||
}
|
||||
}
|
||||
|
||||
public struct LineInfo
|
||||
{
|
||||
public string lineId;
|
||||
public string lineText;
|
||||
public CharacterVo character;
|
||||
public bool isAutoSkip;
|
||||
|
||||
public static LineInfo Generate(LocalizedLine dialogueLine)
|
||||
{
|
||||
return new LineInfo
|
||||
{
|
||||
lineId = dialogueLine.TextID,
|
||||
lineText = dialogueLine.TextWithoutCharacterName.Text,
|
||||
character = dialogueLine.GetCharacterVo(),
|
||||
isAutoSkip = dialogueLine.IsAutoSkipLine()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
public enum LineSyncState
|
||||
{
|
||||
PlayText,
|
||||
AdvanceDelay,
|
||||
WaitForAdvance,
|
||||
Advanced
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f0d1630fcebe4fb38afd0a2bc7b3112b
|
||||
timeCreated: 1761032402
|
||||
@@ -0,0 +1,33 @@
|
||||
using System;
|
||||
using AibisDream.Framework;
|
||||
using UnityEngine;
|
||||
using Yarn.Unity;
|
||||
|
||||
namespace AibisDream
|
||||
{
|
||||
public class OptionView : DialogueViewBase
|
||||
{
|
||||
[SerializeField] private DefaultOptions defaultOptions;
|
||||
[SerializeField] private CenterOptions centerOptions;
|
||||
|
||||
public override void RunOptions(DialogueOption[] dialogueOptions, Action<int> onOptionSelected)
|
||||
{
|
||||
EnumEventSystem.Global.Send(DialogEventEnum.OptionShow);
|
||||
var options = DialogOption.GeneOptions(dialogueOptions, onOptionSelected);
|
||||
var viewType = options[0].Character.dialogViewType;
|
||||
|
||||
switch (viewType)
|
||||
{
|
||||
case DialogViewType.Default:
|
||||
defaultOptions.ShowOptions(options);
|
||||
break;
|
||||
case DialogViewType.CenterOption:
|
||||
centerOptions.ShowOptions(options);
|
||||
break;
|
||||
default:
|
||||
Debug.Log($"选项{options[0].Character.key}没有找到选项框");
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 56ee480f25a146839afa8ff058ddfc7a
|
||||
timeCreated: 1761032377
|
||||
Reference in New Issue
Block a user