2024-12-14 18:27:59 +08:00
|
|
|
|
using QFramework;
|
|
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
|
using XMLTool;
|
|
|
|
|
|
|
|
|
|
|
|
public class OperationController : MonoSingleton<OperationController>
|
|
|
|
|
|
{
|
2025-02-08 17:27:06 +08:00
|
|
|
|
public struct OnOperationChanged
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
2024-12-14 18:27:59 +08:00
|
|
|
|
public struct StepExecute
|
|
|
|
|
|
{
|
|
|
|
|
|
public int index;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct OnNextStep
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public struct StepStatusOnChange
|
|
|
|
|
|
{
|
|
|
|
|
|
public int curIndex;
|
|
|
|
|
|
public StepStatus status;
|
|
|
|
|
|
}
|
|
|
|
|
|
public enum StepStatus
|
|
|
|
|
|
{
|
|
|
|
|
|
NoStart,
|
|
|
|
|
|
Start,
|
|
|
|
|
|
Finished,
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
OperationController() { }
|
|
|
|
|
|
public Operation operation;
|
2025-02-08 17:27:06 +08:00
|
|
|
|
Dictionary<string, Operation> curOperations = new Dictionary<string, Operation>();
|
2024-12-14 18:27:59 +08:00
|
|
|
|
List<Step> steps = new List<Step>();
|
|
|
|
|
|
|
|
|
|
|
|
int index = -1;
|
|
|
|
|
|
|
|
|
|
|
|
bool isStepRun = false;
|
|
|
|
|
|
IAction curAction;
|
|
|
|
|
|
public override void OnSingletonInit()
|
|
|
|
|
|
{
|
|
|
|
|
|
base.OnSingletonInit();
|
|
|
|
|
|
|
|
|
|
|
|
TypeEventSystem.Global.Register<OnModuleStart>((arg) =>
|
|
|
|
|
|
{
|
|
|
|
|
|
Refresh();
|
|
|
|
|
|
}).UnRegisterWhenGameObjectDestroyed(gameObject);
|
2025-01-09 10:08:22 +08:00
|
|
|
|
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Refresh()
|
|
|
|
|
|
{
|
|
|
|
|
|
Global.AppType operationType = Global.AppType.All;
|
2025-02-08 17:27:06 +08:00
|
|
|
|
int index = 0;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
foreach (var operation in Global.Instance.curModule.Operations)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (string.IsNullOrEmpty(operation.moduleType) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
Enum.TryParse(operation.moduleType, out operationType);
|
|
|
|
|
|
}
|
|
|
|
|
|
if (Global.appTpe == operationType || operationType == Global.AppType.All)
|
|
|
|
|
|
{
|
2025-02-08 17:27:06 +08:00
|
|
|
|
if (string.IsNullOrEmpty(operation.name))
|
|
|
|
|
|
{
|
|
|
|
|
|
curOperations.Add(index.ToString(), operation);
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
2024-12-14 18:27:59 +08:00
|
|
|
|
{
|
2025-02-08 17:27:06 +08:00
|
|
|
|
curOperations.Add(operation.name, operation);
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
2025-02-08 17:27:06 +08:00
|
|
|
|
index++;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2025-02-08 17:27:06 +08:00
|
|
|
|
foreach (var operation in curOperations)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.operation = operation.Value;
|
|
|
|
|
|
foreach (var item in operation.Value.Steps)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddStep(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
TypeEventSystem.Global.Register<StepExecute>(OnExecute);
|
|
|
|
|
|
TypeEventSystem.Global.Register<OnNextStep>(OnNext);
|
|
|
|
|
|
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuitHandler);
|
|
|
|
|
|
break;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
|
|
2025-02-08 17:27:06 +08:00
|
|
|
|
public void ChangeOperation(string name)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (curOperations.ContainsKey(name))
|
|
|
|
|
|
{
|
|
|
|
|
|
index = -1;
|
|
|
|
|
|
curAction?.Deinit();
|
|
|
|
|
|
steps.Clear();
|
|
|
|
|
|
this.operation = curOperations[name];
|
|
|
|
|
|
foreach (var item in this.operation.Steps)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddStep(item);
|
|
|
|
|
|
}
|
|
|
|
|
|
TypeEventSystem.Global.Send<OnOperationChanged>();
|
2025-03-10 17:06:31 +08:00
|
|
|
|
OnNext(default);
|
2025-02-08 17:27:06 +08:00
|
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
2025-01-09 10:08:22 +08:00
|
|
|
|
private void OnModuleQuitHandler(OnModuleQuit quit)
|
|
|
|
|
|
{
|
|
|
|
|
|
Clear();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-14 18:27:59 +08:00
|
|
|
|
public void Clear()
|
|
|
|
|
|
{
|
2025-01-09 10:08:22 +08:00
|
|
|
|
index = -1;
|
2025-03-08 14:42:45 +08:00
|
|
|
|
curAction?.Deinit();
|
2025-02-08 17:27:06 +08:00
|
|
|
|
operation = null;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
steps.Clear();
|
2025-02-08 17:27:06 +08:00
|
|
|
|
curOperations.Clear();
|
2025-01-09 10:08:22 +08:00
|
|
|
|
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnModuleQuitHandler);
|
2024-12-14 18:27:59 +08:00
|
|
|
|
TypeEventSystem.Global.UnRegister<StepExecute>(OnExecute);
|
|
|
|
|
|
TypeEventSystem.Global.UnRegister<OnNextStep>(OnNext);
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnNext(OnNextStep step)
|
|
|
|
|
|
{
|
|
|
|
|
|
Execute(this.index + 1);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void OnExecute(StepExecute execute)
|
|
|
|
|
|
{
|
|
|
|
|
|
Execute(execute.index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void Begin()
|
|
|
|
|
|
{
|
|
|
|
|
|
index = 0;
|
|
|
|
|
|
Execute(index);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public void AddStep(Step step)
|
|
|
|
|
|
{
|
|
|
|
|
|
steps.Add(step);
|
|
|
|
|
|
if (step.SubSteps != null && step.SubSteps.Count > 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
foreach (var subStep in step.SubSteps)
|
|
|
|
|
|
{
|
|
|
|
|
|
AddStep(subStep);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void Execute(int targetIndex)
|
|
|
|
|
|
{
|
2025-01-07 17:12:49 +08:00
|
|
|
|
if (this.index == targetIndex)
|
|
|
|
|
|
{
|
|
|
|
|
|
return;
|
|
|
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
|
if (isStepRun)
|
|
|
|
|
|
{
|
|
|
|
|
|
curAction?.Deinit();
|
|
|
|
|
|
}
|
|
|
|
|
|
if (targetIndex < steps.Count && targetIndex >= 0)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (this.index < targetIndex)
|
|
|
|
|
|
{
|
2024-12-27 19:54:54 +08:00
|
|
|
|
var seq = ActionKit.Sequence();
|
2024-12-27 20:28:53 +08:00
|
|
|
|
if (this.index >= 0)
|
2024-12-14 18:27:59 +08:00
|
|
|
|
{
|
2025-01-07 17:12:49 +08:00
|
|
|
|
int startIndex = this.index;
|
|
|
|
|
|
// <20><>ǰ<EFBFBD>ⲽ <20>Ѿ<EFBFBD><D1BE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD>Ҫfinished
|
|
|
|
|
|
if (curAction != null && curAction.Status == ActionStatus.Finished)
|
|
|
|
|
|
{
|
|
|
|
|
|
startIndex += 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
for (int i = startIndex; i < targetIndex; i++)
|
2024-12-14 18:27:59 +08:00
|
|
|
|
{
|
2024-12-27 20:28:53 +08:00
|
|
|
|
// <20><><EFBFBD>ɶ<EFBFBD><C9B6><EFBFBD> ֱ<><D6B1>ִ<EFBFBD><D6B4>
|
|
|
|
|
|
IAction finishAction = ActionHelper.GetActionAndSub(steps[i].Finished);
|
|
|
|
|
|
TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = i, status = StepStatus.Finished });
|
|
|
|
|
|
if (finishAction != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
seq.Append(finishAction);
|
|
|
|
|
|
}
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
2025-01-13 09:39:11 +08:00
|
|
|
|
TypeEventSystem.Global.Send<OnLoadingShow>();
|
2024-12-27 20:28:53 +08:00
|
|
|
|
seq.Start(this, () =>
|
2024-12-27 19:54:54 +08:00
|
|
|
|
{
|
|
|
|
|
|
curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start);
|
|
|
|
|
|
RunCurAction(curAction, targetIndex);
|
|
|
|
|
|
});
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
else if (this.index > targetIndex)
|
|
|
|
|
|
{
|
2024-12-27 20:28:53 +08:00
|
|
|
|
var seq = ActionKit.Sequence();
|
2024-12-30 15:00:14 +08:00
|
|
|
|
for (int i = this.index; i >= targetIndex; i--)
|
2024-12-14 18:27:59 +08:00
|
|
|
|
{
|
|
|
|
|
|
// <20><><EFBFBD>ö<EFBFBD><C3B6><EFBFBD> ֱ<><D6B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|
|
|
|
|
IAction resetAction = ActionHelper.GetActionAndSub(steps[i].Reset);
|
|
|
|
|
|
if (resetAction != null)
|
|
|
|
|
|
{
|
2024-12-27 20:28:53 +08:00
|
|
|
|
seq.Append(resetAction);
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = i, status = StepStatus.NoStart });
|
|
|
|
|
|
}
|
2025-01-13 09:39:11 +08:00
|
|
|
|
TypeEventSystem.Global.Send<OnLoadingShow>();
|
2024-12-27 20:28:53 +08:00
|
|
|
|
seq.Start(this, () =>
|
|
|
|
|
|
{
|
|
|
|
|
|
curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start);
|
|
|
|
|
|
RunCurAction(curAction, targetIndex);
|
|
|
|
|
|
});
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
curAction = ActionHelper.GetActionAndSub(steps[targetIndex].Start);
|
2024-12-27 19:54:54 +08:00
|
|
|
|
RunCurAction(curAction, targetIndex);
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
2024-12-27 19:54:54 +08:00
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2024-12-27 20:28:53 +08:00
|
|
|
|
public void RunCurAction(IAction curAction, int targetIndex)
|
2024-12-27 19:54:54 +08:00
|
|
|
|
{
|
2025-02-05 14:56:37 +08:00
|
|
|
|
TypeEventSystem.Global.Send<OnLoadingHide>();
|
2024-12-27 19:54:54 +08:00
|
|
|
|
if (curAction != null)
|
|
|
|
|
|
{
|
|
|
|
|
|
this.index = targetIndex;
|
|
|
|
|
|
isStepRun = true;
|
|
|
|
|
|
TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Start });
|
|
|
|
|
|
curAction.Start(this, () =>
|
2024-12-14 18:27:59 +08:00
|
|
|
|
{
|
2024-12-27 19:54:54 +08:00
|
|
|
|
isStepRun = false;
|
2024-12-14 18:27:59 +08:00
|
|
|
|
TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Finished });
|
2025-01-13 09:39:11 +08:00
|
|
|
|
|
2024-12-27 19:54:54 +08:00
|
|
|
|
});
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
this.index = targetIndex;
|
|
|
|
|
|
TypeEventSystem.Global.Send(new StepStatusOnChange() { curIndex = targetIndex, status = StepStatus.Finished });
|
|
|
|
|
|
Execute(this.index + 1);
|
2024-12-14 18:27:59 +08:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|