赞
踩
- 插件 Behavior Designer 1.5.7
- 和ue4的行为树极其相似。ue4中的AI和行为树(BluePrint版)
效果图
导入插件 Behavior Designer 1.5.7,打开编辑面板
Tools -> Behavior -> Designer -> Editor
具体各个节点的描述看这个篇文章,写的很全,几乎都是官网翻译过来,http://www.jianshu.com/p/64b5fe01fb1c
选中场景中的一个对象 Capsule,然后在行为树编辑器右键 Add Behavior Tree
Conditional Evaluator 评估节点:判定是否有 Target,里面的 Condictional 脚本是
HasTarget.cs
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks
{
[TaskDescription("Returns success as soon as the event specified by eventName has been received.")]
[HelpURL("http://www.opsive.com/assets/BehaviorDesigner/documentation.php?id=123")]
[TaskIcon("{SkinColor}HasReceivedEventIcon.png")]
[TaskCategory("My")]
public class HasTarget : Conditional
{
public override void OnStart()
{
}
public override TaskStatus OnUpdate()
{
SharedTransform target = (SharedTransform)Owner.GetVariable("target");
if (target.Value == null)
{
Debug.Log("--- HasTarget, false");
return TaskStatus.Failure;
}
else{
Debug.Log("--- HasTarget, true");
return TaskStatus.Success;
}
}
}
Search Target 条件节点:用来寻找敌人,脚本是
SearchTarget.cs
using System.Collections;
using UnityEngine;
namespace BehaviorDesigner.Runtime.Tasks.Basic.UnityTransform
{
[TaskCategory("My")]
public class SearchTarget : Conditional
{
public Transform mTarget = null;
public float mRadius = 2f;
public override void OnStart()
{
Collider[] hits = Physics.OverlapSphere(transform.position, mRadius);
for(int i = 0; i < hits.Length; ++i)
{
if (hits[i].transform.CompareTag("Player"))
{
mTarget = hits[i].transform;
Owner.SetVariableValue("target", mTarget);
break;
}
}
}
public override TaskStatus OnUpdate()
{
return mTarget ? TaskStatus.Success : TaskStatus.Failure;
}
}
}
Wait 动作节点:默认自带的 Action 节点
右键 Add Task -> Actions -> Wait
Range Move 动作节点:范围内随机移动,脚本是
RangeMove.cs
using UnityEngine;
using System.Collections;
using DG.Tweening;
namespace BehaviorDesigner.Runtime.Tasks
{
[TaskDescription("Returns success as soon as the event specified by eventName has been received.")]
[TaskCategory("My")]
[TaskIcon("Assets/bdIcon/aaa.jpg")]
public class RangeMove : Action
{
public bool mIsOver = false;
public float mRange = 2f;
public float mTotalTime = 2f;
public override void OnStart()
{
float x = Random.Range(-mRange, mRange);
float z = Random.Range(-mRange, mRange);
Vector3 dir = transform.position + new Vector3(x, 0, z); //dest world position
transform.LookAt(dir);
transform.DOLocalMoveX(x, mTotalTime).OnComplete(()=> { mIsOver = true; });
transform.DOLocalMoveZ(z, mTotalTime);
}
public override TaskStatus OnUpdate()
{
return mIsOver ? TaskStatus.Success : TaskStatus.Running;
}
}
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。