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 mPool = new SimpleObjectPool(() => 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(); 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(); box.center = center; box.size = size; break; case "AddMesh": obj.AddComponent(); 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; } } }