As mentioned in Assemblies section the logical nodes of execution graph represented as Action
and Order
derived classes instances are separated on two parts:
- Runtime part that contains execution logic.
- Editor part that provides editor GUI and debug\tracking logic.
Runtime part implementation
Following example shows sample Action
implementation within a Runtime assembly.
namespace Doloro.AI.YOUR_MODULE_NAMESPACE
{
using UnityEngine;
using Doloro.AI.Core;
[System.Serializable]
public class YOUR_NODE_NAME : Action
{
// Some variable defined for the node instance.
public string STR_VAR_0 = "";
// Some variable defined for the node instance.
public int INT_VAR_0 = 0;
/// <summary>
/// Calling one time when AI initializing.
/// </summary>
/// <param name="ai">Source AI entity.</param>
public override void Init(Brain ai)
{
base.Init(ai);
// ------------------------------------------------------------------
// Initialize anything you need here.
// That handler will be called when the node instance will be created.
// ------------------------------------------------------------------
}
/// <summary>
/// Implements runtime execution logic for the logical node.
/// </summary>
/// <param name="ai">Reference to AI entity.</param>
/// <returns>Result of operation. Success, Fail or In progress.</returns>
public override Result Pass(Brain ai)
{
// ------------------------------------------------------------------
// Do something that should affect the world of character itself here.
// ------------------------------------------------------------------
// ------------------------------------------------------------------
// Conclude the result of operation.
// ------------------------------------------------------------------
return Result.Success;
}
/// <summary>
/// Occurs when action execution is ended.
/// Calls each time the node got an explicit result as a
/// <see cref="Result.Success"/> or <see cref="Result.Fail"/>
/// </summary>
/// <param name="ai">Source AI entity.</param>
public override void End(Brain ai)
{
base.End(ai);
// ------------------------------------------------------------------
// Use to release session data outside the mode lost its purpose
// till a next action call.
// ------------------------------------------------------------------
}
}
}
Namespace meaning
YOUR_MODULE_NAMESPACE
is a part of namespace after avoiding Doloro.AI.
part of namespace that will be used as directory to your logical node within tools like a Doloro AI Studio
in menus (like Create
, etc.).
Namespace using example
Doloro.AI.Checks.Wallet
will locate your node called CheckUSD
in virtual directory by path Actions\Checks\Wallet\CheckUSD\
, if not implemented in other way.
Editor part implementation
Following example implements simple editor for the YOUR_NODE_NAME
Action
implemented at previous section.
namespace Doloro.AI.YOUR_MODULE_NAMESPACE
{
// Editor class that will be used for the `YOUR_NODE_NAME` instances.
[CustomActionEditor(typeof(YOUR_NODE_NAME))]
public class YOUR_NODE_NAME_Editor : ActionEditor
{
/// <summary>
/// Draw the custom interface in editor
/// </summary>
/// <param name="action">Source action.</param>
/// <param name="ai">Source entity.</param>
public override void OnGUI(Action action, Brain ai)
{
var self = action as YOUR_NODE_NAME;
// ---------------------------------------------------
// Implement your cusom UI here.
// ---------------------------------------------------
// EXAMPLE ------------------------------------------
// Providing access to the STR_VAR_0 at the origin.
self.STR_VAR_0 = EditorGUILayout.TextField(
new GUIContent("Text variable"),
self.STR_VAR_0);
// Providing access to the INT_VAR_0 at the origin.
self.INT_VAR_0 = EditorGUILayout.IntField(
new GUIContent("Int variable"),
self.INT_VAR_0);
// ---------------------------------------------------
}
/// <summary>
/// Draws the custom interface in debug tab.
/// </summary>
/// <param name="action">Source action.</param>
/// <param name="ai">Source entity.</param>
public override void DebugGUI(Action action, Brain ai)
{
var self = action as YOUR_NODE_NAME;
// ---------------------------------------------------
// Implement your custom GUI UI here.
// ---------------------------------------------------
}
}
}
See also
See also followed advanced pre-implemented editors and it's using within GDK: