IndieGame/client/Assets/ParadoxNotion/NodeCanvas/Tasks/Actions/GameObject/RemoveComponent.cs

35 lines
911 B
C#
Raw Normal View History

2024-10-11 10:12:15 +08:00
using NodeCanvas.Framework;
using ParadoxNotion.Design;
using UnityEngine;
namespace NodeCanvas.Tasks.Actions
{
[Category("GameObject")]
public class RemoveComponent<T> : ActionTask<Transform> where T : Component
{
[Tooltip("DestroyImmediately is recomended if you are destroying objects in use of the framework.")]
public bool immediately;
protected override string info {
get { return string.Format("Remove '{0}'", typeof(T).Name); }
}
protected override void OnExecute() {
var o = agent.GetComponent<T>();
if ( o != null ) {
if ( immediately ) {
Object.DestroyImmediate(o);
} else {
Object.Destroy(o);
}
EndAction(true);
return;
}
EndAction(false);
}
}
}