Unity用Behavior TreesのライブラリBehave
サイトは
Behavior Treesの説明は
使い方はCollectionを作って
中にTreeを作ると
エディタでツリーをいじれる
ツリーはBuild libraryボタンを押して吐き出せば
スクリプトから使えるようになる
スクリプトはこんな感じ
using UnityEngine;
using System.Collections;
using Behave.Runtime;
using Tree = Behave.Runtime.Tree;
public class NewBehaviourScript : MonoBehaviour, IAgent
{
Tree m_Tree;
// Use this for initialization
IEnumerator Start () {
m_Tree = BLNewBehaveLibrary0.InstantiateTree (
BLNewBehaveLibrary0.TreeType.NewCollection1_NewTree2 ,
this
);
while (Application.isPlaying && m_Tree != null)
{
Debug.Log( m_Tree.Frequency );
//~ yield return new WaitForSeconds( 1.0f / m_Tree.Frequency );
yield return new WaitForSeconds( 1.0f / 1 );
AIUpdate();
}
}
void AIUpdate ()
{
Debug.Log( "update" );
// one action been ticked.
m_Tree.Tick();
}
public BehaveResult Tick (Tree sender, bool init)
{
Debug.Log ( "got ticked" );
Debug.Log (
(BLNewBehaveLibrary0.IsAction (sender.ActiveID) ? "action" : "decorator" )
);
return BehaveResult.Success;
}
public void Reset (Tree sender)
{
}
public int SelectTopPriority (Tree sender, params int[] IDs)
{
return IDs[0];
}
public BehaveResult TickFirstAction (Tree sender)
{
Debug.Log("First!");
return BehaveResult.Success;
}
}

0 件のコメント:
コメントを投稿