迁移测试文件,建立主程序集
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
{
|
||||
"name": "GeometryTD.Editor",
|
||||
"rootNamespace": "GeometryTD.Editor",
|
||||
"references": [
|
||||
"GeometryTD.Runtime",
|
||||
"UnityGameFramework.Editor"
|
||||
],
|
||||
"includePlatforms": [
|
||||
"Editor"
|
||||
],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": false,
|
||||
"precompiledReferences": [],
|
||||
"autoReferenced": true,
|
||||
"defineConstraints": [],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 739d2e9771244fc8af6c8d8636eade79
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -8,6 +8,44 @@ using UnityGameFramework.Runtime;
|
||||
|
||||
namespace GeometryTD.Procedure
|
||||
{
|
||||
public enum ProcedureMainFlowPhase
|
||||
{
|
||||
Hub = 0,
|
||||
NodeActive = 1,
|
||||
RunCompletedPendingFinish = 2
|
||||
}
|
||||
|
||||
public enum ProcedureMainRunAdvanceResult
|
||||
{
|
||||
NoChange = 0,
|
||||
NodeFailed = 1,
|
||||
AdvancedToNextNode = 2,
|
||||
RunCompleted = 3
|
||||
}
|
||||
|
||||
public static class ProcedureMainRunFlowService
|
||||
{
|
||||
public static ProcedureMainRunAdvanceResult TryAdvanceRun(
|
||||
RunState runState,
|
||||
bool succeeded,
|
||||
BackpackInventoryData snapshot)
|
||||
{
|
||||
if (!RunStateAdvanceService.TryCompleteCurrentNode(runState, succeeded, snapshot))
|
||||
{
|
||||
return ProcedureMainRunAdvanceResult.NoChange;
|
||||
}
|
||||
|
||||
if (runState != null && runState.IsCompleted)
|
||||
{
|
||||
return ProcedureMainRunAdvanceResult.RunCompleted;
|
||||
}
|
||||
|
||||
return succeeded
|
||||
? ProcedureMainRunAdvanceResult.AdvancedToNextNode
|
||||
: ProcedureMainRunAdvanceResult.NodeFailed;
|
||||
}
|
||||
}
|
||||
|
||||
public class ProcedureMain : ProcedureBase
|
||||
{
|
||||
public override bool UseNativeDialog => false;
|
||||
@@ -15,6 +53,7 @@ namespace GeometryTD.Procedure
|
||||
private RepoFormUseCase _repoFormUseCase;
|
||||
private NodeMapFormUseCase _nodeMapFormUseCase;
|
||||
private RunState _currentRunState;
|
||||
private ProcedureMainFlowPhase _flowPhase = ProcedureMainFlowPhase.Hub;
|
||||
|
||||
#region FSM
|
||||
|
||||
@@ -45,7 +84,7 @@ namespace GeometryTD.Procedure
|
||||
_nodeMapFormUseCase.SetRunState(_currentRunState);
|
||||
GameEntry.UIRouter.BindUIUseCase(UIFormType.NodeMapForm, _nodeMapFormUseCase);
|
||||
|
||||
OpenHubUI();
|
||||
EnterHubFlow();
|
||||
}
|
||||
|
||||
protected override void OnUpdate(IFsm<IProcedureManager> procedureOwner, float elapseSeconds,
|
||||
@@ -69,6 +108,7 @@ namespace GeometryTD.Procedure
|
||||
_repoFormUseCase = null;
|
||||
_nodeMapFormUseCase = null;
|
||||
_currentRunState = null;
|
||||
_flowPhase = ProcedureMainFlowPhase.Hub;
|
||||
|
||||
base.OnLeave(procedureOwner, isShutdown);
|
||||
}
|
||||
@@ -117,8 +157,7 @@ namespace GeometryTD.Procedure
|
||||
args.NodeType,
|
||||
args.SequenceIndex);
|
||||
|
||||
GameEntry.UIRouter.CloseUI(UIFormType.NodeMapForm);
|
||||
GameEntry.UIRouter.CloseUI(UIFormType.MainForm);
|
||||
EnterNodeFlow();
|
||||
}
|
||||
|
||||
private void OnNodeComplete(object sender, GameEventArgs e)
|
||||
@@ -145,8 +184,7 @@ namespace GeometryTD.Procedure
|
||||
snapshot = GameEntry.PlayerInventory.GetInventorySnapshot();
|
||||
}
|
||||
|
||||
AdvanceRunState(args.Succeeded, snapshot);
|
||||
OpenHubUI();
|
||||
HandleRunAdvanceResult(ProcedureMainRunFlowService.TryAdvanceRun(_currentRunState, args.Succeeded, snapshot));
|
||||
}
|
||||
|
||||
private void OnCombatFailureReturn(object sender, GameEventArgs e)
|
||||
@@ -159,8 +197,7 @@ namespace GeometryTD.Procedure
|
||||
BackpackInventoryData snapshot = GameEntry.PlayerInventory != null
|
||||
? GameEntry.PlayerInventory.GetInventorySnapshot()
|
||||
: null;
|
||||
AdvanceRunState(false, snapshot);
|
||||
OpenHubUI();
|
||||
HandleRunAdvanceResult(ProcedureMainRunFlowService.TryAdvanceRun(_currentRunState, false, snapshot));
|
||||
}
|
||||
|
||||
private void OnNodeMapNodeEnterRequested(object sender, GameEventArgs e)
|
||||
@@ -171,9 +208,15 @@ namespace GeometryTD.Procedure
|
||||
}
|
||||
|
||||
RunNodeState currentNode = _currentRunState?.CurrentNode;
|
||||
if (_currentRunState == null || !_currentRunState.CanEnterCurrentNode || currentNode == null)
|
||||
if (_currentRunState == null ||
|
||||
_flowPhase != ProcedureMainFlowPhase.Hub ||
|
||||
!_currentRunState.CanEnterCurrentNode ||
|
||||
currentNode == null)
|
||||
{
|
||||
Log.Warning("ProcedureMain.OnNodeMapNodeEnterRequested() ignored. Current run has no enterable node.");
|
||||
Log.Warning(
|
||||
"ProcedureMain.OnNodeMapNodeEnterRequested() ignored. FlowPhase={0}, HasEnterableNode={1}.",
|
||||
_flowPhase,
|
||||
_currentRunState != null && _currentRunState.CanEnterCurrentNode);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -226,33 +269,30 @@ namespace GeometryTD.Procedure
|
||||
}
|
||||
}
|
||||
|
||||
private void AdvanceRunState(bool succeeded, BackpackInventoryData snapshot)
|
||||
private void HandleRunAdvanceResult(ProcedureMainRunAdvanceResult result)
|
||||
{
|
||||
if (_currentRunState == null)
|
||||
switch (result)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (!RunStateAdvanceService.TryCompleteCurrentNode(_currentRunState, succeeded, snapshot))
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
if (_currentRunState.IsCompleted)
|
||||
{
|
||||
Log.Info("ProcedureMain run completed. RunId={0}", _currentRunState.RunId);
|
||||
return;
|
||||
}
|
||||
|
||||
RunNodeState nextNode = _currentRunState.CurrentNode;
|
||||
if (nextNode != null)
|
||||
{
|
||||
Log.Info(
|
||||
"ProcedureMain advanced run. RunId={0}, NextNodeType={1}, SequenceIndex={2}, LevelId={3}.",
|
||||
_currentRunState.RunId,
|
||||
nextNode.NodeType,
|
||||
nextNode.SequenceIndex,
|
||||
nextNode.LinkedLevelId);
|
||||
case ProcedureMainRunAdvanceResult.NoChange:
|
||||
return;
|
||||
case ProcedureMainRunAdvanceResult.NodeFailed:
|
||||
Log.Info(
|
||||
"ProcedureMain current node failed. RunId={0}, NodeId={1}, NodeType={2}, SequenceIndex={3}.",
|
||||
_currentRunState?.RunId,
|
||||
_currentRunState?.CurrentNode?.NodeId ?? 0,
|
||||
_currentRunState?.CurrentNode?.NodeType ?? RunNodeType.None,
|
||||
_currentRunState?.CurrentNode?.SequenceIndex ?? -1);
|
||||
EnterHubFlow();
|
||||
return;
|
||||
case ProcedureMainRunAdvanceResult.AdvancedToNextNode:
|
||||
LogNextNode();
|
||||
EnterHubFlow();
|
||||
return;
|
||||
case ProcedureMainRunAdvanceResult.RunCompleted:
|
||||
EnterRunCompletedPendingFinish();
|
||||
return;
|
||||
default:
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -262,11 +302,48 @@ namespace GeometryTD.Procedure
|
||||
GameEntry.PlayerInventory.GetParticipantTowerSnapshot().Count > 0;
|
||||
}
|
||||
|
||||
private void OpenHubUI()
|
||||
private void EnterHubFlow()
|
||||
{
|
||||
_flowPhase = ProcedureMainFlowPhase.Hub;
|
||||
_nodeMapFormUseCase?.SetRunState(_currentRunState);
|
||||
GameEntry.UIRouter.OpenUI(UIFormType.NodeMapForm);
|
||||
GameEntry.UIRouter.OpenUI(UIFormType.MainForm);
|
||||
}
|
||||
|
||||
private void EnterNodeFlow()
|
||||
{
|
||||
_flowPhase = ProcedureMainFlowPhase.NodeActive;
|
||||
CloseHubUI();
|
||||
}
|
||||
|
||||
private void EnterRunCompletedPendingFinish()
|
||||
{
|
||||
_flowPhase = ProcedureMainFlowPhase.RunCompletedPendingFinish;
|
||||
_nodeMapFormUseCase?.SetRunState(_currentRunState);
|
||||
CloseHubUI();
|
||||
Log.Info("ProcedureMain run completed. RunId={0}", _currentRunState?.RunId);
|
||||
}
|
||||
|
||||
private void CloseHubUI()
|
||||
{
|
||||
GameEntry.UIRouter.CloseUI(UIFormType.NodeMapForm);
|
||||
GameEntry.UIRouter.CloseUI(UIFormType.MainForm);
|
||||
}
|
||||
|
||||
private void LogNextNode()
|
||||
{
|
||||
RunNodeState nextNode = _currentRunState?.CurrentNode;
|
||||
if (nextNode == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Log.Info(
|
||||
"ProcedureMain advanced run. RunId={0}, NextNodeType={1}, SequenceIndex={2}, LevelId={3}.",
|
||||
_currentRunState.RunId,
|
||||
nextNode.NodeType,
|
||||
nextNode.SequenceIndex,
|
||||
nextNode.LinkedLevelId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user