Skip to content

Instantly share code, notes, and snippets.

@AngryAnt AngryAnt/Abstraction.cs
Last active Nov 7, 2017

Embed
What would you like to do?
The Behave runtime.
public BehaveResult TickShuffleAction (Tree sender)
{
return m_ShuffleTree.Tick ();
}
public void ResetShuffleAction (Tree sender)
{
m_ShuffleTree.Reset ();
}
public class BAMyLibrary_MyAgent : Behave.Runtime.IAgent
{
public static TreeType[] SupportedTrees { get; }
public virtual BehaveResult Tick (Tree sender);
public virtual void Reset (Tree sender);
public virtual int SelectTopPriority (Tree sender, params int[] IDs);
public virtual BehaveResult Init[Name]Action (Tree sender);
public virtual BehaveResult Tick[Name]Action (Tree sender);
public virtual void Reset[Name]Action (Tree sender);
}
public class BLMyLibrary
{
public enum TreeType { Path_To_TreeName = 0, ..., Unknown };
public enum RecordType { Path_To_RecordName, ..., Unknown };
public enum CollectionType { CollectionName, ..., Unknown };
public enum ContextType { ContextName, ..., Unknown };
public enum PriorityType { PriorityName, ..., Unknown };
public enum ActionType { ActionName, ..., Unknown = N };
public static Tree InstantiateTree (TreeType treeType, IAgent agent, ICollection collection = null);
public static ICollection InstantiateCollection (CollectionType collectionType, ICollection fallback = null);
public static bool SetGetForward (ICollection collection, int id, GetForward forward);
public static bool SetSetForward (ICollection collection, int id, SetForward forward);
public static bool ReflectForwards (ICollection collection, object target);
public static bool ResetForwards (ICollection collection, object target = null);
public static TreeType Type (Tree tree);
public static CollectionType Type (ICollection collection);
public static bool DidInstantiate (Tree tree);
public static bool DidInstantiate (ICollection collection);
public static RecordType[] SupportedRecords (ICollection collection);
}
namespace Behave.Debugger
{
public class Debugging
{
public static void Update ();
}
public class DebugUpdater
{
public static void Start (int frequency = 20);
public static void Stop ();
}
}
m_MyTree = BLMyLibrary.InstantiateTree (
BLMyLibrary.TreeType.MyTree,
this
);
m_MyTree.SetTickForward (
(int)BLMyLibrary.ActionType.CanTalk,
DialogueManager.AgentCanTalkHandler
);
m_MyTree.ReflectFowards (m_GroupManager);
public BehaveResult TickInRangeAction (Tree sender)
{
return m_CurrentWeapon.InRangeTree.TickContinuously ();
}
public void ResetInRangeAction (Tree sender)
{
m_CurrentWeapon.InRangeTree.Reset ();
}
public BehaveResult TickAttackAction (Tree sender)
{
return m_CurrentWeapon.AttackTree.Tick ();
}
public void ResetAttackAction (Tree sender)
{
m_CurrentWeapon.AttackTree.Reset ();
}
namespace Behave.Runtime
{
public interface IActionClass
{
bool OnForward (Tree sender);
BehaveResult Init (Tree sender);
BehaveResult Tick (Tree sender);
void Reset (Tree sender);
}
}
namespace Behave.Runtime
{
public interface IAgent
{
BehaveResult Tick (Tree sender);
void Reset (Tree sender);
int SelectTopPriority (Tree sender, params int[] IDs);
}
}
namespace Behave.Runtime
{
public interface ICollection
{
float Get (int id);
bool Set (int id, float value);
}
}
public class Soldier : MonoBehaviour, IAgent
{
// ...
public virtual BehaveResult TickMeleeAction (Tree sender)
{
m_Target.Health -= MeleeDamage;
return BehaveResult.Success;
}
// ...
}
public class JackieChan : Soldier
{
// ...
public override BehaveResult TickMeleeAction (Tree sender)
{
m_Audience.Laugh ();
return base.TickMeleeAction (sender);
}
// ...
}
using UnityEngine;
using System.Collections;
using Behave.Runtime;
using Tree = Behave.Runtime.Tree;
public class MyAgent : MonoBehaviour, IAgent
{
Tree m_MyTree;
IEnumerator Start ()
{
m_MyTree = BLMyLibrary.InstantiateTree (
BLMyLibrary.TreeType.MyTree,
this
);
while (Application.isPlaying)
{
if (m_MyTree.Tick () != BehaveResult.Running)
{
m_MyTree.Reset ();
}
yield return new WaitForSeconds (
1.0f / m_MyTree.Frequency
);
}
}
public BehaveResult Tick (Tree sender)
{
Debug.Log ("Tick: " + (BLMyLibrary.ActionType)sender.ActiveID);
return BehaveResult.Success;
}
public void Reset (Tree sender)
{}
public int SelectTopPriority (Tree sender, params int[] ids)
{
return ids[0];
}
}
public BehaveResult Init[Name]Action (Tree sender);
public BehaveResult Tick[Name]Action (Tree sender);
public void Reset[Name]Action (Tree sender);
public float Get[Name] (ICollection sender, int record);
public bool Set[Name] (ICollection sender, int record, float value);
namespace Behave.Runtime
{
public enum BehaveResult
{
Failure,
Success,
Running
}
public enum ExceptionHandling
{
Throw,
LogAndReset
}
public delegate BehaveResult TickForward (Tree sender);
public delegate void ResetForward (Tree sender);
public delegate float GetForward (ICollection sender, int id);
public delegate bool SetForward (ICollection sender, int id, float f);
}
public BehaveResult TickSetThatThingAction (Tree sender)
{
m_That = ContextToThingIdentifier ((BLMyLibrary.ContextType)sender.ActiveContext);
return BehaveResult.Success;
}
public BehaveResult TickDoThatThingAction (Tree sender)
{
return m_Things[m_That].Tick ();
}
public void ResetDoThatThingAction (Tree sender)
{
m_Things[m_That].Reset ();
}
namespace Behave.Runtime
{
public class Tree
{
public BehaveResult Tick ([IAgent agent, object data]);
public void TickWrapping ([IAgent agent, object data], ExceptionHandling exceptionHandling = ExceptionHandling.Throw);
public BehaveResult TickContinuously ([IAgent agent, object data,] int iterationCap = 1024);
public void Reset ([IAgent agent, object data]);
public bool TickActive {get;}
public int ActiveID {get;}
public int ActiveContext {get;}
public string ActiveStringParameter {get;}
public float ActiveFloatParameter {get;}
public IAgent ActiveAgent {get;}
public object ActiveData {get;}
public ICollection ActiveCollection {get; set;}
public IAgent Owner {get;set}
public int LastTicked {get;}
public float Frequency {get;}
public int[] SupportedActions {get;}
public int DataSize {get;}
public bool DebugAvailable {get;}
public string Name {get;}
public int ActiveComponent {get;}
public bool Plugged {get; set;}
public void SetInitForward (int id, TickForward init);
public void SetTickForward (int id, TickForward tick);
public void SetResetForward (int id, ResetForward reset);
public bool SetForwards (int id, IActionClass actionClass);
public void ReflectForwards (object target);
public void ReflectClassForwards (UnityEngine.GameObject gameObject);
public void ResetForwards (object target = null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.