diff --git a/Assets/Scripts/Actions/ActionHelper.cs b/Assets/Scripts/Actions/ActionHelper.cs index 422aa893..db93bdee 100644 --- a/Assets/Scripts/Actions/ActionHelper.cs +++ b/Assets/Scripts/Actions/ActionHelper.cs @@ -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; diff --git a/Assets/Scripts/Actions/OperationChangeAction.cs b/Assets/Scripts/Actions/OperationChangeAction.cs new file mode 100644 index 00000000..0ccf2a97 --- /dev/null +++ b/Assets/Scripts/Actions/OperationChangeAction.cs @@ -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 mPool = + new SimpleObjectPool(() => new OperationChangeAction(), null, 10); + + Dictionary datas; + public static OperationChangeAction Allocate(Dictionary 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; } + } + + +} \ No newline at end of file diff --git a/Assets/Scripts/Actions/OperationChangeAction.cs.meta b/Assets/Scripts/Actions/OperationChangeAction.cs.meta new file mode 100644 index 00000000..02a99107 --- /dev/null +++ b/Assets/Scripts/Actions/OperationChangeAction.cs.meta @@ -0,0 +1,3 @@ +fileFormatVersion: 2 +guid: 561ce23d686fb5e43aa36c8df69845b9 +timeCreated: 1647655796 \ No newline at end of file diff --git a/Assets/Scripts/Controller/OperationController.cs b/Assets/Scripts/Controller/OperationController.cs index b6817979..44b39142 100644 --- a/Assets/Scripts/Controller/OperationController.cs +++ b/Assets/Scripts/Controller/OperationController.cs @@ -7,6 +7,12 @@ using XMLTool; public class OperationController : MonoSingleton { + public struct OnOperationChanged + { + + } + + public struct StepExecute { public int index; @@ -31,7 +37,7 @@ public class OperationController : MonoSingleton OperationController() { } public Operation operation; - + Dictionary curOperations = new Dictionary(); List steps = new List(); int index = -1; @@ -52,6 +58,7 @@ public class OperationController : MonoSingleton 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 } 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(OnExecute); - TypeEventSystem.Global.Register(OnNext); - TypeEventSystem.Global.Register(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(OnExecute); + TypeEventSystem.Global.Register(OnNext); + TypeEventSystem.Global.Register(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(); + } } private void OnModuleQuitHandler(OnModuleQuit quit) @@ -83,7 +118,9 @@ public class OperationController : MonoSingleton { index = -1; curAction.Deinit(); + operation = null; steps.Clear(); + curOperations.Clear(); TypeEventSystem.Global.UnRegister(OnModuleQuitHandler); TypeEventSystem.Global.UnRegister(OnExecute); TypeEventSystem.Global.UnRegister(OnNext); diff --git a/Assets/Scripts/UI/UIOperationList.cs b/Assets/Scripts/UI/UIOperationList.cs index 5384d58d..8240de84 100644 --- a/Assets/Scripts/UI/UIOperationList.cs +++ b/Assets/Scripts/UI/UIOperationList.cs @@ -21,6 +21,7 @@ namespace QFramework.Example protected override void OnInit(IUIData uiData = null) { mData = uiData as UIOperationListData ?? new UIOperationListData(); + TypeEventSystem.Global.Register((arg) => Refresh()).UnRegisterWhenGameObjectDestroyed(gameObject); TypeEventSystem.Global.Register((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject); } @@ -84,6 +85,11 @@ namespace QFramework.Example protected override void OnOpen(IUIData uiData = null) { TypeEventSystem.Global.Register(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); diff --git a/Assets/Scripts/Xml/XmlParser.cs b/Assets/Scripts/Xml/XmlParser.cs index 0535d963..4886009a 100644 --- a/Assets/Scripts/Xml/XmlParser.cs +++ b/Assets/Scripts/Xml/XmlParser.cs @@ -147,6 +147,7 @@ namespace XMLTool public class Operation { + public string name; public string moduleType { get; set; } public bool freeStep { get; set; } public List Steps { get; set; } @@ -309,6 +310,7 @@ namespace XMLTool { Steps = new List(), }; + 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;