支持多operation切换
This commit is contained in:
parent
bb0bba3ed4
commit
09a744871f
@ -258,6 +258,11 @@ public class ActionHelper
|
|||||||
var dictAction = (XMLTool.Show3DAction)act;
|
var dictAction = (XMLTool.Show3DAction)act;
|
||||||
return QFramework.Show3DAction.Allocate(dictAction.data);
|
return QFramework.Show3DAction.Allocate(dictAction.data);
|
||||||
}
|
}
|
||||||
|
case "OperationChange":
|
||||||
|
{
|
||||||
|
var dictAction = (XMLTool.DictionaryAction)act;
|
||||||
|
return QFramework.OperationChangeAction.Allocate(dictAction.args);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
||||||
break;
|
break;
|
||||||
|
|||||||
76
Assets/Scripts/Actions/OperationChangeAction.cs
Normal file
76
Assets/Scripts/Actions/OperationChangeAction.cs
Normal 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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
3
Assets/Scripts/Actions/OperationChangeAction.cs.meta
Normal file
3
Assets/Scripts/Actions/OperationChangeAction.cs.meta
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 561ce23d686fb5e43aa36c8df69845b9
|
||||||
|
timeCreated: 1647655796
|
||||||
@ -7,6 +7,12 @@ using XMLTool;
|
|||||||
|
|
||||||
public class OperationController : MonoSingleton<OperationController>
|
public class OperationController : MonoSingleton<OperationController>
|
||||||
{
|
{
|
||||||
|
public struct OnOperationChanged
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
public struct StepExecute
|
public struct StepExecute
|
||||||
{
|
{
|
||||||
public int index;
|
public int index;
|
||||||
@ -31,7 +37,7 @@ public class OperationController : MonoSingleton<OperationController>
|
|||||||
|
|
||||||
OperationController() { }
|
OperationController() { }
|
||||||
public Operation operation;
|
public Operation operation;
|
||||||
|
Dictionary<string, Operation> curOperations = new Dictionary<string, Operation>();
|
||||||
List<Step> steps = new List<Step>();
|
List<Step> steps = new List<Step>();
|
||||||
|
|
||||||
int index = -1;
|
int index = -1;
|
||||||
@ -52,6 +58,7 @@ public class OperationController : MonoSingleton<OperationController>
|
|||||||
public void Refresh()
|
public void Refresh()
|
||||||
{
|
{
|
||||||
Global.AppType operationType = Global.AppType.All;
|
Global.AppType operationType = Global.AppType.All;
|
||||||
|
int index = 0;
|
||||||
foreach (var operation in Global.Instance.curModule.Operations)
|
foreach (var operation in Global.Instance.curModule.Operations)
|
||||||
{
|
{
|
||||||
if (string.IsNullOrEmpty(operation.moduleType) == false)
|
if (string.IsNullOrEmpty(operation.moduleType) == false)
|
||||||
@ -60,18 +67,46 @@ public class OperationController : MonoSingleton<OperationController>
|
|||||||
}
|
}
|
||||||
if (Global.appTpe == operationType || operationType == Global.AppType.All)
|
if (Global.appTpe == operationType || operationType == Global.AppType.All)
|
||||||
{
|
{
|
||||||
this.operation = operation;
|
if (string.IsNullOrEmpty(operation.name))
|
||||||
foreach (var item in operation.Steps)
|
{
|
||||||
|
curOperations.Add(index.ToString(), operation);
|
||||||
|
}
|
||||||
|
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);
|
AddStep(item);
|
||||||
}
|
}
|
||||||
TypeEventSystem.Global.Register<StepExecute>(OnExecute);
|
TypeEventSystem.Global.Register<StepExecute>(OnExecute);
|
||||||
TypeEventSystem.Global.Register<OnNextStep>(OnNext);
|
TypeEventSystem.Global.Register<OnNextStep>(OnNext);
|
||||||
TypeEventSystem.Global.Register<OnModuleQuit>(OnModuleQuitHandler);
|
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)
|
private void OnModuleQuitHandler(OnModuleQuit quit)
|
||||||
@ -83,7 +118,9 @@ public class OperationController : MonoSingleton<OperationController>
|
|||||||
{
|
{
|
||||||
index = -1;
|
index = -1;
|
||||||
curAction.Deinit();
|
curAction.Deinit();
|
||||||
|
operation = null;
|
||||||
steps.Clear();
|
steps.Clear();
|
||||||
|
curOperations.Clear();
|
||||||
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnModuleQuitHandler);
|
TypeEventSystem.Global.UnRegister<OnModuleQuit>(OnModuleQuitHandler);
|
||||||
TypeEventSystem.Global.UnRegister<StepExecute>(OnExecute);
|
TypeEventSystem.Global.UnRegister<StepExecute>(OnExecute);
|
||||||
TypeEventSystem.Global.UnRegister<OnNextStep>(OnNext);
|
TypeEventSystem.Global.UnRegister<OnNextStep>(OnNext);
|
||||||
|
|||||||
@ -21,6 +21,7 @@ namespace QFramework.Example
|
|||||||
protected override void OnInit(IUIData uiData = null)
|
protected override void OnInit(IUIData uiData = null)
|
||||||
{
|
{
|
||||||
mData = uiData as UIOperationListData ?? new UIOperationListData();
|
mData = uiData as UIOperationListData ?? new UIOperationListData();
|
||||||
|
TypeEventSystem.Global.Register<OnOperationChanged>((arg) => Refresh()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||||||
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
TypeEventSystem.Global.Register<OnModuleQuit>((arg) => Hide()).UnRegisterWhenGameObjectDestroyed(gameObject);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -84,6 +85,11 @@ namespace QFramework.Example
|
|||||||
protected override void OnOpen(IUIData uiData = null)
|
protected override void OnOpen(IUIData uiData = null)
|
||||||
{
|
{
|
||||||
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(this);
|
TypeEventSystem.Global.Register<StepStatusOnChange>(OnStepChanged).UnRegisterWhenDisabled(this);
|
||||||
|
Refresh();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void Refresh()
|
||||||
|
{
|
||||||
btns.Clear();
|
btns.Clear();
|
||||||
op = OperationController.Instance.operation;
|
op = OperationController.Instance.operation;
|
||||||
StepContent.RemoveAllChildren();
|
StepContent.RemoveAllChildren();
|
||||||
@ -126,6 +132,7 @@ namespace QFramework.Example
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void StepItemFactory(Transform content, string txt)
|
public void StepItemFactory(Transform content, string txt)
|
||||||
{
|
{
|
||||||
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, content.transform);
|
GameObject subObj = GameObject.Instantiate(SubStep.gameObject, content.transform);
|
||||||
|
|||||||
@ -147,6 +147,7 @@ namespace XMLTool
|
|||||||
|
|
||||||
public class Operation
|
public class Operation
|
||||||
{
|
{
|
||||||
|
public string name;
|
||||||
public string moduleType { get; set; }
|
public string moduleType { get; set; }
|
||||||
public bool freeStep { get; set; }
|
public bool freeStep { get; set; }
|
||||||
public List<Step> Steps { get; set; }
|
public List<Step> Steps { get; set; }
|
||||||
@ -309,6 +310,7 @@ namespace XMLTool
|
|||||||
{
|
{
|
||||||
Steps = new List<Step>(),
|
Steps = new List<Step>(),
|
||||||
};
|
};
|
||||||
|
op.name = operationNode.Attribute("name")?.Value;
|
||||||
op.moduleType = operationNode.Attribute("moduleType")?.Value;
|
op.moduleType = operationNode.Attribute("moduleType")?.Value;
|
||||||
var free = operationNode.Attribute("freeStep");
|
var free = operationNode.Attribute("freeStep");
|
||||||
bool isFree = true;
|
bool isFree = true;
|
||||||
@ -1338,6 +1340,17 @@ namespace XMLTool
|
|||||||
newAction = act;
|
newAction = act;
|
||||||
}
|
}
|
||||||
break;
|
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:
|
default:
|
||||||
newAction = new Action();
|
newAction = new Action();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user