新增自定义脚本的Action
This commit is contained in:
parent
5949ba5d04
commit
8e7fc41d4d
@ -191,6 +191,11 @@ public class ActionHelper
|
|||||||
var strAction = (XMLTool.StringListAction)act;
|
var strAction = (XMLTool.StringListAction)act;
|
||||||
return LedAction.Allocate(act.Value, strAction.args[0], strAction.args[1]);
|
return LedAction.Allocate(act.Value, strAction.args[0], strAction.args[1]);
|
||||||
}
|
}
|
||||||
|
case "Script":
|
||||||
|
{
|
||||||
|
var strAction = (XMLTool.StringListAction)act;
|
||||||
|
return ScriptAction.Allocate(act.Name, act.Value, strAction.args[0]);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
||||||
break;
|
break;
|
||||||
|
|||||||
86
Assets/Scripts/Actions/ScriptAction.cs
Normal file
86
Assets/Scripts/Actions/ScriptAction.cs
Normal file
@ -0,0 +1,86 @@
|
|||||||
|
using System;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using Unity.VisualScripting;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace QFramework
|
||||||
|
{
|
||||||
|
internal class ScriptAction : IAction
|
||||||
|
{
|
||||||
|
|
||||||
|
|
||||||
|
public System.Action OnFinished { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
private ScriptAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly SimpleObjectPool<ScriptAction> mPool =
|
||||||
|
new SimpleObjectPool<ScriptAction>(() => new ScriptAction(), null, 10);
|
||||||
|
|
||||||
|
public string prefabPath;
|
||||||
|
string finishedEvent;
|
||||||
|
string name;
|
||||||
|
public static ScriptAction Allocate(string name, string prefabPath, string finishedEvent, System.Action OnFinished = null)
|
||||||
|
{
|
||||||
|
var retNode = mPool.Allocate();
|
||||||
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
||||||
|
retNode.Deinited = false;
|
||||||
|
retNode.Reset();
|
||||||
|
retNode.OnFinished = OnFinished;
|
||||||
|
retNode.finishedEvent = finishedEvent;
|
||||||
|
retNode.prefabPath = prefabPath;
|
||||||
|
retNode.name = name;
|
||||||
|
return retNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ulong ActionID { get; set; }
|
||||||
|
public ActionStatus Status { get; set; }
|
||||||
|
|
||||||
|
public void OnStart()
|
||||||
|
{
|
||||||
|
StringEventSystem.Global.Register(finishedEvent, OnCustomFinished);
|
||||||
|
GameObject obj = GameObject.Instantiate(Resources.Load($"CustomAction/{prefabPath}").As<GameObject>());
|
||||||
|
obj.name = name;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnCustomFinished()
|
||||||
|
{
|
||||||
|
StringEventSystem.Global.UnRegister(finishedEvent, OnCustomFinished);
|
||||||
|
this.Finish();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void OnExecute(float dt)
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
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; }
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
||||||
11
Assets/Scripts/Actions/ScriptAction.cs.meta
Normal file
11
Assets/Scripts/Actions/ScriptAction.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6958205303fbb7541b8272f244747fc0
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
8
Assets/Scripts/CustomAction.meta
Normal file
8
Assets/Scripts/CustomAction.meta
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 6d7f9813c337725468c8739dba68c439
|
||||||
|
folderAsset: yes
|
||||||
|
DefaultImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -869,10 +869,26 @@ namespace XMLTool
|
|||||||
newAction = act;
|
newAction = act;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "Script":
|
||||||
|
{
|
||||||
|
var act = new StringListAction();
|
||||||
|
XAttribute finishedEvent = action.Attribute("finishedEvent");
|
||||||
|
if (finishedEvent != null)
|
||||||
|
{
|
||||||
|
act.args.Add(finishedEvent.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
act.args.Add("");
|
||||||
|
}
|
||||||
|
newAction = act;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
newAction = new Action();
|
newAction = new Action();
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
newAction.Type = action.Attribute("type")?.Value;
|
newAction.Type = action.Attribute("type")?.Value;
|
||||||
newAction.Name = action.Attribute("name")?.Value;
|
newAction.Name = action.Attribute("name")?.Value;
|
||||||
newAction.Value = action.Attribute("value")?.Value;
|
newAction.Value = action.Attribute("value")?.Value;
|
||||||
|
|||||||
@ -85,6 +85,9 @@
|
|||||||
number 是数值 支持 小数点和横线 例如 12.34 3-5 -->
|
number 是数值 支持 小数点和横线 例如 12.34 3-5 -->
|
||||||
<Action type="Led" value="Number" number="12.34" color="255,0,0,255"></Action>
|
<Action type="Led" value="Number" number="12.34" color="255,0,0,255"></Action>
|
||||||
|
|
||||||
|
<!--给程序使用的:自定义脚本 挂空预制体上 预制体放在Resources/CustomAction目录下 执行完毕后记得使用StringEventSystem.Global.Send(finishedEvent)-->
|
||||||
|
<Action type="Script" value="MyAction" finishedEvent="111"/>
|
||||||
|
|
||||||
<!--预加载模块 要在app.xml的Data标签内-->
|
<!--预加载模块 要在app.xml的Data标签内-->
|
||||||
<PreLoad>
|
<PreLoad>
|
||||||
<Action type="Parallel">
|
<Action type="Parallel">
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user