121 lines
3.4 KiB
C#
121 lines
3.4 KiB
C#
|
|
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("<22>Ҳ<EFBFBD><D2B2><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͣ<EFBFBD>" + 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; }
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
|
|||
|
|
}
|