Behavior Designer自带的一个Conditional节点:
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityGameObject
{
[TaskCategory("Basic/GameObject")]
[TaskDescription("Returns Success if the GameObject is active in the hierarchy, otherwise Failure.")]
public class ActiveInHierarchy : Conditional
{
[Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
public SharedGameObject targetGameObject;
public override TaskStatus OnUpdate()
{
return GetDefaultGameObject(targetGameObject.Value).activeInHierarchy ? TaskStatus.Success : TaskStatus.Failure;
}
public override void OnReset()
{
targetGameObject = null;
}
}
}
TaskCategory:把该类放在"Add Task/Conditionals/Basic/GameObject"
TaskDescription:选中节点后显示的描述性文字
Tooltip:对字段的描述性文字
重点就是重写OnUpdate方法了:
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityGameObject
{
[TaskCategory("Basic/GameObject")]
[TaskDescription("是否有BoxCollider组件")]
public class HasBoxCollider : Conditional
{
[Tooltip("The GameObject that the task operates on. If null the task GameObject is used.")]
public SharedGameObject targetGameObject;
public override TaskStatus OnUpdate()
{
return GetDefaultGameObject(targetGameObject.Value).GetComponent<BoxCollider>() ? TaskStatus.Success : TaskStatus.Failure;
}
public override void OnReset()
{
targetGameObject = null;
}
}
}
以上要注意的是即使物体有BoxCollider组件,但组件前的勾是取消的,也会返回Success。
GetDefaultGameObject默认的是该节点的GameObject,当然也可以指定其他的。