[Unity插件]Behavior Designer

给物体添加Behavior Tree组件,点击Open Behavior Designer进行行为树的编辑。


1.编辑器


第1-5个按钮用于选择要编辑的行为树

Referenced Behaviors可以查看当前行为树引用的行为树(可以通过Actions节点下的Behavior Tree Reference引用行为树)

-   :删除当前行为树

+   :为当前物体添加一个新的行为树组件

Lock   :锁定当前行为树,即使选择其他的游戏物体也不会改变当前的视图


2.生命周期



3.常用API

using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using BehaviorDesigner.Runtime.Tasks;
using BehaviorDesigner.Runtime;
using BehaviorDesigner.Runtime.Tasks.Basic.UnityDebug;

[TaskCategory("Custom")]
[TaskDescription("AITest")]
public class AITest : Action {

    public SharedString ss;
    public string s;

    public override void OnStart()
    {
        //1.同一行为树下的task之间的通信
        BehaviorTree bt = GetComponent<BehaviorTree>();
        var v = bt.FindTask<Log>();
        v.text = "!!";

        //2.访问shared变量
        Debug.Log(bt.GetVariable("AA"));
        bt.SetVariable("AA", ss);
        Debug.Log(bt.GetVariable("AA"));
        bt.SetVariableValue("AA", s);
        Debug.Log(bt.GetVariable("AA"));

        //3.访问global变量
        Debug.Log(GlobalVariables.Instance.GetVariable("BB"));
        GlobalVariables.Instance.SetVariableValue("BB", s);
        Debug.Log(GlobalVariables.Instance.GetVariable("BB"));
    }

}

4.

a.如何停止AI

直接将BehaviorTree组件禁用掉并不能停止AI。先要将预制的BehaviorTree组件禁用掉,然后将PauseWhenDisable勾选。此时通过脚本enabled行为树即可自由控制行为树的开启和关闭了。


b.如何引用另一棵行为树

在行为树编辑界面上,右键Save XXX,即可将当前行为树保存为一个文件。然后建一个Action节点,选择BehaviorTree Reference即可引用行为树。


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值