调整 Directive 逻辑并添加章节之间的承接功能
This commit is contained in:
@@ -1,14 +1,22 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using DataTable;
|
||||
using Event;
|
||||
using GameFramework.DataTable;
|
||||
using GameFramework.Event;
|
||||
using GameFramework.Fsm;
|
||||
using GameFramework.Procedure;
|
||||
using UnityEngine;
|
||||
using UI;
|
||||
using UnityGameFramework.Runtime;
|
||||
|
||||
namespace Procedure
|
||||
{
|
||||
public class ProcedureMain : ProcedureBase
|
||||
{
|
||||
private const int InitialChapterId = 1;
|
||||
private const int InitialDialogId = 1001;
|
||||
private const int DialogChapterDivisor = 1000;
|
||||
|
||||
private IDataTable<DRDialog> _dtDialog;
|
||||
|
||||
public override bool UseNativeDialog => false;
|
||||
|
||||
protected override void OnEnter(IFsm<IProcedureManager> procedureOwner)
|
||||
@@ -16,8 +24,104 @@ namespace Procedure
|
||||
base.OnEnter(procedureOwner);
|
||||
AIChatEntryRuntime.EnsureOpen();
|
||||
|
||||
GameEntry.Dialog.Init(1);
|
||||
GameEntry.Dialog.StartDialog(1001);
|
||||
GameEntry.Event.Subscribe(StoryChapterEndedEventArgs.EventId, OnStoryChapterEnded);
|
||||
|
||||
GameEntry.Dialog.Init(InitialChapterId);
|
||||
GameEntry.Dialog.StartDialog(InitialDialogId);
|
||||
}
|
||||
|
||||
protected override void OnLeave(IFsm<IProcedureManager> procedureOwner, bool isShutdown)
|
||||
{
|
||||
GameEntry.Event.Unsubscribe(StoryChapterEndedEventArgs.EventId, OnStoryChapterEnded);
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
}
|
||||
|
||||
private void OnStoryChapterEnded(object sender, GameEventArgs e)
|
||||
{
|
||||
if (!(e is StoryChapterEndedEventArgs args))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
int currentChapterId = args.ChapterId > 0
|
||||
? args.ChapterId
|
||||
: (GameEntry.Dialog != null ? GameEntry.Dialog.CurrentChapterId : 0);
|
||||
int nextChapterId = currentChapterId + 1;
|
||||
if (nextChapterId <= 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!TryResolveFirstDialogId(nextChapterId, out int nextDialogId))
|
||||
{
|
||||
Log.Info("ProcedureMain chapter switch stopped. No dialog found for chapter '{0}'.",
|
||||
nextChapterId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (GameEntry.Dialog == null)
|
||||
{
|
||||
Log.Warning("ProcedureMain chapter switch failed. Dialog component is missing.");
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameEntry.Dialog.Init(nextChapterId))
|
||||
{
|
||||
Log.Warning("ProcedureMain chapter switch failed. Init chapter '{0}' failed.",
|
||||
nextChapterId.ToString());
|
||||
return;
|
||||
}
|
||||
|
||||
if (!GameEntry.Dialog.StartDialog(nextDialogId))
|
||||
{
|
||||
Log.Warning("ProcedureMain chapter switch failed. Start dialog '{0}' failed.",
|
||||
nextDialogId.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
private bool TryResolveFirstDialogId(int chapterId, out int dialogId)
|
||||
{
|
||||
dialogId = 0;
|
||||
if (chapterId <= 0)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (_dtDialog == null)
|
||||
{
|
||||
_dtDialog = GameEntry.DataTable.GetDataTable<DRDialog>();
|
||||
}
|
||||
|
||||
if (_dtDialog == null)
|
||||
{
|
||||
Log.Warning("ProcedureMain chapter switch failed. Data table DRDialog is missing.");
|
||||
return false;
|
||||
}
|
||||
|
||||
DRDialog[] dialogRows = _dtDialog.GetDataRows((a, b) => a.Id.CompareTo(b.Id));
|
||||
for (int i = 0; i < dialogRows.Length; i++)
|
||||
{
|
||||
DRDialog row = dialogRows[i];
|
||||
if (row == null)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
if (ParseChapterIdFromDialogId(row.Id) != chapterId)
|
||||
{
|
||||
continue;
|
||||
}
|
||||
|
||||
dialogId = row.Id;
|
||||
return dialogId > 0;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static int ParseChapterIdFromDialogId(int dialogId)
|
||||
{
|
||||
return dialogId / DialogChapterDivisor;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user