Using Angry Ant’s Behave Library in UnityScript

I have been learning how to use Unity3D recently, and I really wanted to use the Behave library without having to use C#. It took me a little while, but here is an example of doing it:

#pragma strict

 

// Where we store our new Behave Tree

var BTree : Behave.Runtime.Tree;

 

// Where we store our Behave IAgent

var Agent : BSIAgent;

 

// Where we implement all of our Behave level functions

public class BSIAgent implements Behave.Runtime.IAgent {

 

public function Tick (sender : Behave.Runtime.Tree, init : System.Boolean) {

Debug.Log(“Tick”);

return Behave.Runtime.BehaveResult.Success;

}

 

public function Reset (sender : Behave.Runtime.Tree) {

}

 

public function SelectTopPriority (sender : Behave.Runtime.Tree, IDs : int[]){

return IDs[0];

}

}

 

function Start() {

// Create a new agent

Agent = new BSIAgent();

// Create our tree

BTree = BLBasicMiner.InstantiateTree( BLBasicMiner.TreeType.Task_Systems_BasicTS,   Agent   );

// While the application is running and our tree exists

while (Application.isPlaying && minerTree != null) {

// Wait for a certain amount of time

yield new WaitForSeconds(1.0f / minerTree.Frequency);

// Tick the tree

AIUpdate();

}

}

 

function AIUpdate() {

BTree.Tick();

}

Yes, this is a bit of a hack, but I haven’t had much time to refine it. Hopefully in the future I will be able to provide a more readable version.

2 responses to “Using Angry Ant’s Behave Library in UnityScript

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s