支持多operation切换

This commit is contained in:
shenjianxing 2025-02-08 17:27:06 +08:00
parent bb0bba3ed4
commit 09a744871f
6 changed files with 148 additions and 7 deletions

View File

@ -258,6 +258,11 @@ public class ActionHelper
var dictAction = (XMLTool.Show3DAction)act;
return QFramework.Show3DAction.Allocate(dictAction.data);
}
case "OperationChange":
{
var dictAction = (XMLTool.DictionaryAction)act;
return QFramework.OperationChangeAction.Allocate(dictAction.args);
}
default:
Debug.LogError($"没有找到此Action的类型{act.Type}");
break;

View File

@ -0,0 +1,76 @@
using System;
using System.Collections.Generic;
using UnityEngine;
namespace QFramework
{
internal class OperationChangeAction : IAction
{
public System.Action OnFinished { get; set; }
private OperationChangeAction()
{
}
private static readonly SimpleObjectPool<OperationChangeAction> mPool =
new SimpleObjectPool<OperationChangeAction>(() => new OperationChangeAction(), null, 10);
Dictionary<string, string> datas;
public static OperationChangeAction Allocate(Dictionary<string, string> datas, System.Action OnFinished = null)
{
var retNode = mPool.Allocate();
retNode.ActionID = ActionKit.ID_GENERATOR++;
retNode.Deinited = false;
retNode.Reset();
retNode.datas = datas;
retNode.OnFinished = OnFinished;
return retNode;
}
public ulong ActionID { get; set; }
public ActionStatus Status { get; set; }
public void OnStart()
{
}
public void OnExecute(float dt)
{
if (datas.ContainsKey("name"))
{
OperationController.Instance.ChangeOperation(datas["name"]);
}
this.Finish();
OnFinished?.Invoke();
}
public void OnFinish()
{
}
public void Reset()
{
Status = ActionStatus.NotStart;
Paused = false;
}
public bool Paused { get; set; }
public void Deinit()
{
if (!Deinited)
{
OnFinished = null;
Deinited = true;
mPool.Recycle(this);
}
}
public bool Deinited { get; set; }
}
}

View File

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 561ce23d686fb5e43aa36c8df69845b9
timeCreated: 1647655796

View File

@ -7,6 +7,12 @@ using XMLTool;
public class OperationController : MonoSingleton<OperationController>
{
public struct OnOperationChanged
{
}
public struct StepExecute
{
public int index;
@ -31,7 +37,7 @@ public class OperationController : MonoSingleton<OperationController>
OperationController() { }
public Operation operation;
Dictionary<string, Operation> curOperations = new Dictionary<string, Operation>();
List<Step> steps = new List<Step>();
int index = -1;
@ -52,6 +58,7 @@ public class OperationController : MonoSingleton<OperationController>
public void Refresh()
{
Global.AppType operationType = Global.AppType.All;
int index = 0;
foreach (var operation in Global.Instance.curModule.Operations)
{
if (string.IsNullOrEmpty(operation.moduleType) == false)
@ -60,18 +67,46 @@ public class OperationController : MonoSingleton<OperationController>
}
if (Global.appTpe == operationType || operationType == Global.AppType.All)
{
this.operation = operation;
foreach (var item in operation.Steps)
if (string.IsNullOrEmpty(operation.name))
{
AddStep(item);
curOperations.Add(index.ToString(), operation);
}
TypeEventSystem.Global.Register<StepExecute>(OnExecute);
TypeEventSystem.Global.Register<OnNextStep>(OnNext);
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuitHandler);
else
{
curOperations.Add(operation.name, operation);
}
index++;
}
}
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;
}
}
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>();
}
}
private void OnModuleQuitHandler(OnModuleQuit quit)
@ -83,7 +118,9 @@ public class OperationController : MonoSingleton<OperationController>
{
index = -1;
curAction.Deinit();
operation = null;
steps.Clear();
curOperations.Clear();
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnModuleQuitHandler);
TypeEventSystem.Global.UnRegister<StepExecute>(OnExecute);
TypeEventSystem.Global.UnRegister<OnNextStep>(OnNext);

View File

@ -21,6 +21,7 @@ namespace QFramework.Example
protected override void OnInit(IUIData uiData = null)
{
mData = uiData as UIOperationListData ?? new UIOperationListData();
TypeEventSystem.Global.Register<OnOperationChanged>((arg) => Refresh()).UnRegisterWhenGameObjectDestroyed(gameObject);
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
}
@ -84,6 +85,11 @@ namespace QFramework.Example
protected override void OnOpen(IUIData uiData = null)
{
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(this);
Refresh();
}
public void Refresh()
{
btns.Clear();
op = OperationController.Instance.operation;
StepContent.RemoveAllChildren();
@ -126,6 +132,7 @@ namespace QFramework.Example
}
}
public void StepItemFactory(Transform content, string txt)
{
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, content.transform);

View File

@ -147,6 +147,7 @@ namespace XMLTool
public class Operation
{
public string name;
public string moduleType { get; set; }
public bool freeStep { get; set; }
public List<Step> Steps { get; set; }
@ -309,6 +310,7 @@ namespace XMLTool
{
Steps = new List<Step>(),
};
op.name = operationNode.Attribute("name")?.Value;
op.moduleType = operationNode.Attribute("moduleType")?.Value;
var free = operationNode.Attribute("freeStep");
bool isFree = true;
@ -1338,6 +1340,17 @@ namespace XMLTool
newAction = act;
}
break;
case "OperationChange":
{
var act = new DictionaryAction();
XAttribute name = action.Attribute("name");
if (name != null)
{
act.args.Add("name", name.Value);
}
newAction = act;
}
break;
default:
newAction = new Action();
break;