Behavior-designer 的基本使用
各种节点就不说了...这种文章太多了
https://www.jianshu.com/p/5033daf85fda
随便搬运个自己看
用法主要是在
OnStart里面写入执行的条件
在OnUpdate里面写入跳出的条件
自定义的共享类
using UnityEngine; using BehaviorDesigner.Runtime; [System.Serializable] public class GuestAi { public BaseNpc baseNpc; public NpcMoveType moveType; public int moveIndex; // 移动次数,用于循环多次后离开 } [System.Serializable] public class SharedGusetAi : SharedVariable<GuestAi> { public override string ToString() { return mValue == null ? "null" : mValue.ToString(); } public static implicit operator SharedGusetAi(GuestAi value) { return new SharedGusetAi { mValue = value }; } }
一个自定义的共享类,需要定义一个名称,我这边是在初始化的时候叫他为
"NpcData"
if (ai == null) { ai = new GuestAi(); ai.baseNpc = npc; } tree.Group = npc.PlayerData.id; ai.moveType = NpcMoveType.等待; ai.moveIndex = 0; tree.SetVariableValue("NpcData", ai);
取出来的时候
public static GuestAi GetNpcAIData(this Behavior behavior) { GuestAi ai = behavior.GetVariable(m_NpcDataStr).GetValue() as GuestAi; return ai; }
装箱,就是AS转换下就可以了
基本上新手的误区就这些,我一开始把逻辑放update里面跑了
对了,因为start里面只跑一遍,大部分的行为树都是循环调用的
顶层挂个 Repeater 就可以一直循环了,.~