新增碰撞相关的Action
This commit is contained in:
parent
d395965e60
commit
be7bc8fea4
@ -196,6 +196,11 @@ public class ActionHelper
|
|||||||
var strAction = (XMLTool.StringListAction)act;
|
var strAction = (XMLTool.StringListAction)act;
|
||||||
return ScriptAction.Allocate(act.Name, act.Value, strAction.args[0]);
|
return ScriptAction.Allocate(act.Name, act.Value, strAction.args[0]);
|
||||||
}
|
}
|
||||||
|
case "Collider":
|
||||||
|
{
|
||||||
|
var strAction = (XMLTool.StringListAction)act;
|
||||||
|
return ColliderAction.Allocate(act.Value, strAction.args[0], strAction.args[1], strAction.args[2]);
|
||||||
|
}
|
||||||
default:
|
default:
|
||||||
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
Debug.LogError($"没有找到此Action的类型{act.Type}");
|
||||||
break;
|
break;
|
||||||
|
|||||||
121
Assets/Scripts/Actions/ColliderAction.cs
Normal file
121
Assets/Scripts/Actions/ColliderAction.cs
Normal file
@ -0,0 +1,121 @@
|
|||||||
|
using QFramework.Example;
|
||||||
|
using System;
|
||||||
|
using UnityEngine;
|
||||||
|
|
||||||
|
namespace QFramework
|
||||||
|
{
|
||||||
|
internal class ColliderAction : IAction
|
||||||
|
{
|
||||||
|
|
||||||
|
public System.Action OnFinished { get; set; }
|
||||||
|
|
||||||
|
|
||||||
|
private ColliderAction()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
private static readonly SimpleObjectPool<ColliderAction> mPool =
|
||||||
|
new SimpleObjectPool<ColliderAction>(() => new ColliderAction(), null, 10);
|
||||||
|
string type;
|
||||||
|
string path;
|
||||||
|
string args;
|
||||||
|
string deviceName;
|
||||||
|
public static ColliderAction Allocate(string path, string deviceName, string type, string args, System.Action OnFinished = null)
|
||||||
|
{
|
||||||
|
var retNode = mPool.Allocate();
|
||||||
|
retNode.ActionID = ActionKit.ID_GENERATOR++;
|
||||||
|
retNode.Deinited = false;
|
||||||
|
retNode.Reset();
|
||||||
|
retNode.type = type;
|
||||||
|
retNode.path = path;
|
||||||
|
retNode.args = args;
|
||||||
|
retNode.deviceName = deviceName;
|
||||||
|
return retNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public ulong ActionID { get; set; }
|
||||||
|
public ActionStatus Status { get; set; }
|
||||||
|
|
||||||
|
public void OnStart()
|
||||||
|
{
|
||||||
|
GameObject obj = null;
|
||||||
|
if (string.IsNullOrEmpty(deviceName))
|
||||||
|
{
|
||||||
|
obj = Utility.FindObj(path);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
obj = DeviceController.Instance.GetDeviceObj(deviceName);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (obj != null)
|
||||||
|
{
|
||||||
|
Collider[] colliders = obj.GetComponents<Collider>();
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case "AddBox":
|
||||||
|
string[] args = this.args.Split('|');
|
||||||
|
Vector3 center = Utility.GetVector3FromStrArray(args[0]);
|
||||||
|
Vector3 size = Utility.GetVector3FromStrArray(args[1]);
|
||||||
|
BoxCollider box = obj.AddComponent<BoxCollider>();
|
||||||
|
box.center = center;
|
||||||
|
box.size = size;
|
||||||
|
break;
|
||||||
|
case "AddMesh":
|
||||||
|
obj.AddComponent<MeshCollider>();
|
||||||
|
break;
|
||||||
|
case "Remove":
|
||||||
|
foreach (var item in colliders)
|
||||||
|
{
|
||||||
|
GameObject.Destroy(item);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "Active":
|
||||||
|
bool active = true;
|
||||||
|
bool.TryParse(this.args, out active);
|
||||||
|
foreach (var item in colliders)
|
||||||
|
{
|
||||||
|
item.enabled = active;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
Debug.LogError("ÕÒ²»µ½ÀàÐÍ£º" + type);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
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/ColliderAction.cs.meta
Normal file
11
Assets/Scripts/Actions/ColliderAction.cs.meta
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 3b900729b5bb03b4db0c4b085843ffe4
|
||||||
|
MonoImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
serializedVersion: 2
|
||||||
|
defaultReferences: []
|
||||||
|
executionOrder: 0
|
||||||
|
icon: {instanceID: 0}
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
||||||
@ -897,6 +897,39 @@ namespace XMLTool
|
|||||||
newAction = act;
|
newAction = act;
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
case "Collider":
|
||||||
|
{
|
||||||
|
var act = new StringListAction();
|
||||||
|
XAttribute deviceName = action.Attribute("deviceName");
|
||||||
|
if (deviceName != null)
|
||||||
|
{
|
||||||
|
act.args.Add(deviceName.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
act.args.Add("");
|
||||||
|
}
|
||||||
|
XAttribute colliderType = action.Attribute("colliderType");
|
||||||
|
if (colliderType != null)
|
||||||
|
{
|
||||||
|
act.args.Add(colliderType.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
act.args.Add("¿Õ");
|
||||||
|
}
|
||||||
|
XAttribute arg = action.Attribute("args");
|
||||||
|
if (arg != null)
|
||||||
|
{
|
||||||
|
act.args.Add(arg.Value);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
act.args.Add("");
|
||||||
|
}
|
||||||
|
newAction = act;
|
||||||
|
}
|
||||||
|
break;
|
||||||
default:
|
default:
|
||||||
newAction = new Action();
|
newAction = new Action();
|
||||||
break;
|
break;
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user