initialPrefabs logo
  • Home 
  • Blog 
  • Tags 
  1. Home
  2. Tools
  3. DANI AI
  4. Dani AI API

Dani AI API

Share via
initialPrefabs
Link copied to clipboard

API for Dani AI

On this page
  • Action
  • ActionState
  • AIBrain
  • AINode
  • AITemplate
  • BrainManager
  • Condition
  • Connection
  • ConnectionType
  • CustomMenuPathAttribute
  • DaniAIRuntimeBridge
  • Decision
  • DecisionRunType
  • ExecutionType
  • GenericCondition T
  • GenericObserver T
  • GenericVariable T
  • HideCompareValueAttribute
  • IAIBrain
  • Observer
  • RunningState
  • Variable

All classes and types belong in the IntialPrefabs.DaniAI namespace.

Action  

A customizable task that can agent can perform.

public abstract class InitialPrefabs.DaniAI.Action : AINode

Properties  

Type Name Summary
ActionState CurrentState The current status of the action.

Methods  

Type Name Summary
void OnActionEnd(ActionState state) Overridable method that is called when the action completes.
void OnActionStart() Overridable method that is called when the action begins.
ActionState OnActionUpdate() Overridable method that is called when the action is currently running. Actions will run continously until this method returns ActionState.Success or ActionState.Fail.

ActionState  

Describes the current running state of an action.

  • Running = The action is still running
  • Success = The action is done, and was successful
  • Fail = The action is done, but failed
public enum InitialPrefabs.DaniAI.ActionState : Enum, IComparable, IFormattable, IConvertible

Enum  

Value Name Summary
0 Pending The Action is waiting to be run.
1 Running The Action is currently running.
2 Success The Action ran successfully.
4 Fail The Action has failed.

AIBrain  

The main runtime component of DaniAI. Creates and runs a copy of an AITemplate instance.

public class InitialPrefabs.DaniAI.AIBrain : MonoBehaviour, IAIBrain, IBrainRunnable

Properties  

Type Name Summary
ExecutionType ExecutionOrder When the brain should run its AI Step (during Update, OnUpdate, etc.).
RunningState RunningStatus The current running state of the brain. The brain will only run when its running status is set to RunningState.Running (via StartBrain()).
AITemplate RuntimeTemplate The local copy of the template used to perform AI-related actions.
AITemplate Template The template that this brain is using to perform AI-related actions.

Events  

Type Name Summary
DrawGizmosHandler OnDrawGizmosEvent A gizmos event that is called during OnDrawGizmos().
DrawGizmosHandler OnDrawGizmosSelectedEvent A gizmos event that is called when the AIBrain is selected in the editor.
PauseHandler OnPauseEvent An event that is called when the brain pauses. Register a method here if you want your AINode to pause when the brain pauses.
ResumeHandler OnResumeEvent An event that is called when the brain resumes. Register a method here if you want your AINode to resume when the brain resumes.

Methods  

Type Name Summary
float GetCurrentDecisionScore(Decision decision) Gets the current score of a decision
void Pause() Pauses the brain and its AI nodes.
void RestartBrain() Restarts the brain and runs all AI steps from scratch.
void Resume() Attempts to resume the brain from its paused state.
void RunActionStep() Runs the appropriate set of actions as defined by the active decision.
void RunAIStep() Plays all AI Steps (observation, decision, action) together in one go.
void RunDecisionStep() Updates the decision to the next active decision.
void RunObservationStep() Updates all enabled Observers’ values.
void StartBrain() Starts the brain by picking a decision and running the observer step.
void StopBrain() Stops the brain from running all functions

AINode  

The base node class to reference all components in the AITemplate.

public abstract class InitialPrefabs.DaniAI.AINode : ScriptableObject

Properties  

Type Name Summary
AIBrain Brain The brain that this node is running in. This value is initialized when the node is a local copy in an AIBrain.
String Comments Custom notes and descriptions that describe this node. Useful for adding reminders on what the node does.
GameObject GameObject The game object that the AIBrain is attached to. This value is initialized when the node is a local copy in an AIBrain.
int Id The id of the node.
Boolean IsEnabled Determines whether or not the node is active. The brain will not run this node if it is disabled.
AITemplate Template The template that this node belongs to.
Transform Transform The transform component of the brain. This value is initialized when the node is a local copy in an AIBrain.

Methods  

Type Name Summary
T GetComponent<T>() Finds a component of type T on the game object that the AIBrain is attached to.
T GetComponentInChildren<T>() Finds a component of type T on the game object and its children that the AIBrain is attached to.
T GetComponentInParent<T>() Finds a component of type T on the game object and its parents that the AIBrain is attached to.
T[] GetComponents<T>() Finds all components of type T on the game object that the AIBrain is attached to.
T[] GetComponentsInChildren<T>() Finds all components of type T on the game object and its children that the AIBrain is attached to.
T[] GetComponentsInParent<T>() Finds all components of type T on the game object and its parents that the AIBrain is attached to.
void OnDestroy() Overridable method that is called when the brain is destroyed or is restarted.
void OnPause() Overridable method that is called when the brain is paused.
void OnResume() Overridable method that is called when the brain resumes.
void OnStart() Overridable method to initialize tasks. Called during AIBrain’s Start() method.

AITemplate  

A container of AINodes that dictate how the agent should observer, decide, and enact.

public class InitialPrefabs.DaniAI.AITemplate : ScriptableObject

Properties  

Type Name Summary
Action[] Actions A collection of actions required to run the template.
String Comments Any notes and decriptions of the AITemplate. Useful for reminders on what the template does.
Condition[] Conditions A collection of conditions required to run the template.
Connection[] Connections A collection of connections required to run the template.
Decision[] Decisions A collection of decisions required to run the template.
String Id The ID of the template as a 32-character guid.
Observer[] Observers A collection of observer nodes required to run the template.
Variable[] Variables A collection of variables required to run the template.

Methods  

Type Name Summary
T GetAction<T>(String name) Finds an action of type T with a matching name.
T GetDecision<T>(String name) Finds a decision of type T with a matching name.
T GetObserver<T>(String name) Finds an observer of type T with a matching name.
T GetVariable<T>(String name) Finds a variable of type T with a matching name.

BrainManager  

A manager that runs all brains in a batch to improve performance.

public class InitialPrefabs.DaniAI.BrainManager : MonoBehaviour

Static Properties  

Type Name Summary
BrainManager Instance The current instance of BrainManager.

Condition  

Defines a threshold which must be met for decisions to be selected to the current decision.

public abstract class InitialPrefabs.DaniAI.Condition : ScriptableObject

Properties  

Type Name Summary
String Comments Notes and descriptions related to the condition.
Object CompareValue The value that the condition uses to generate a weight.
int Id The condition’s unique id.

Methods  

Type Name Summary
float CalculateLocalWeight() Overridable method that translates the observer’s output into a weight usable by the Decision. Weights should be in the range [0, 1], where 1 is true and 0 is false.

Connection  

A node that represents a relation between two AINodes, depicted by a bezier curve in the editor.

public class InitialPrefabs.DaniAI.Connection : ScriptableObject

Properties  

Type Name Summary
int ConditionId The id of the attached condition. This value is 0 if the connection type is simple.
ConnectionType ConnectionType The type of connection.
int SourceId The id of the AI node on the left side of the connection.
int TargetId The id of the AI node on the right side of the connection.
AITemplate Template The template that this connection belongs to.
float Weight The maximum weight of the connection. Used to determine how much influence the connection has on the decision if it is a conditional type. Otherwise it is used to determine the order of which the actions will run.

ConnectionType  

Enum describing the type of connection involved in the link between two nodes.

public enum InitialPrefabs.DaniAI.ConnectionType : Enum, IComparable, IFormattable, IConvertible

Enum  

Value Name Summary
0 Simple The connection is a simple link between two AI nodes e.g. Decision to Action.
1 Conditional The connection contains a condition between two AI nodes e.g. Observer to Decision.

CustomMenuPathAttribute  

Attribute used for positioning custom scripts in the node editor’s dropdown menu.

public class InitialPrefabs.DaniAI.CustomMenuPathAttribute : Attribute, _Attribute

Fields  

Type Name Summary
String path The local path of the script e.g. ‘Humanoid Actions/Talk’.

DaniAIRuntimeBridge  

The runtime bridge between the editor and runtime. Allows the ability to display and edit runtime diagram in realtime.

public class InitialPrefabs.DaniAI.DaniRuntimeBridge

Static Fields  

Type Name Summary
OnTemplateSelectDelegate OnTemplateSelectEvent An event that is called when a brain with a working runtime AITemplate is selected

Static Properties  

Type Name Summary
AIBrain SelectedBrain The brain as selected by clicking on an AIBrain in the hierarchy
Decision SelectedDecision The selected decision as decided by the AIBrain
AITemplate SelectedTemplate The selected AITemplate decided by the AIBrain

Static Methods  

Type Name Summary
void SelectBrain(AIBrain brain) Selects the brain to display in the editor
void SelectDecision(Decision decision, AIBrain brain) Selects the decision to be displayed in the editor

Decision  

The “thoughts” of the agent. Generates a score based on the connected conditions for the brain to consider which Decision to run. Additionally selects which actions to run when the Decision is selected by the AIBrain.

public abstract class InitialPrefabs.DaniAI.Decision : AINode

Properties  

Type Name Summary
DecisionRunType CurrentRunType Indicates how the decision should run the connected actions.
Boolean FocusWhenSelected When set to true, artificially boosts the current Decision’s score to prevent other decisions of similar scores from overriding the current Decision.
Boolean IsInterruptable Can the AIBrain stop this Decision in place of another Decision with a higher score?
float Priority A multiplier that determines the decision’s importance in relation to other decisions.
float ScoreBoostOnFocus The bonus score that the decision recieves when it is selected by the AIBrain. This value is only applied when FocusWhenSelected is set to true.

DecisionRunType  

Enum describing how the decision should run its actions.

public enum InitialPrefabs.DaniAI.DecisionRunType : Enum, IComparable, IFormattable, IConvertible

Enum  

Value Name Summary
0 Sequential All actions are placed in the order that they are presented in the decision.
1 Random One action will be randomly selected to run.
2 Concurrent All actions are run at the same time.

ExecutionType  

Decribes when the brain should run its AI steps.

public enum InitialPrefabs.DaniAI.ExecutionType : Enum, IComparable, IFormattable, IConvertible

Enum  

Value Name Summary
0 OnUpdate The AIBrain will run during the Update() step.
1 OnFixedUpdate The AIBrain will run during the FixedUpdate() step.
2 ByScript The AIBrain will not run automatically. Use this if you want to control when the brain should run its steps e.g. for a turn-based AI.

GenericCondition T  

A generic representation of a condition. Used to create conditions for specific data types e.g. floats.

public abstract class InitialPrefabs.DaniAI.GenericCondition<T> : Condition

Fields  

Type Name Summary
T compareValue
GenericObserver observer

Properties  

Type Name Summary
Object CompareValue The value to compare with.

GenericObserver T  

A generic version of an observer. Handles any serializable type, like floats, ints, string, etc.

public class InitialPrefabs.DaniAI.GenericObserver<T> : Observer

Properties  

Type Name Summary
T Output The current output value.
Type OutputType The current type of the output.

Methods  

Type Name Summary
object GetOutput() The Observer’s output value as an object type.
T OnObserverUpdate() Updates the observer’s value and returns an output value as a result. Override this method to provide an up-to-date output value for the observer.

GenericVariable T  

A variable that contains a generic type.

public abstract class InitialPrefabs.DaniAI.GenericVariable<T> : Variable

Properties  

Type Name Summary
T Value The variable’s current value.
Type ValueType The variable’s type.

Methods  

Type Name Summary
Object GetValue() Gets the variable’s current value as an object type.
String ToString() Outputs a formatted value of the variable.

HideCompareValueAttribute  

A utility class used to hide the compareValue field in the Condition. Mainly used for Conditions where the compare value is not useful or confusing, such as BoolCondition.

public class InitialPrefabs.DaniAI.HideCompareValueAttribute : Attribute, _Attribute

IAIBrain  

An interface that describes a brain that can run AI actions via AITemplates

public interface InitialPrefabs.DaniAI.IAIBrain

Properties  

Type Name Summary
ExecutionType ExecutionOrder When the brain should run its AI Step (during Update, OnUpdate, etc.).
RunningState RunningStatus The current running state of the brain. The brain will only run when its status is set to running (via StartBrain()).
AITemplate RuntimeTemplate The runtime version of the template used to perform AI-related actions.
AITemplate Template The template that this brain is using to perform actions.

Methods  

Type Name Summary
void Pause() Pauses the brain and its AI nodes.
void RestartBrain() Restarts the brain and runs all AI steps from scratch.
void Resume() Attempts to resume the brain from its paused state.
void RunActionStep() Runs the appropriate set of actions as defined by the active decision.
void RunAIStep() Plays all AI Steps (observation, decision, action) together in one go.
void RunDecisionStep() Updates the decision to the next active decision.
void RunObservationStep() Updates observervation values.
void StartBrain() Starts the brain by picking a decision and running the observer step.
void StopBrain() Stops the brain from running all functions.

Observer  

The senses of the AI. Outputs the information for the AI to reference with.

public abstract class InitialPrefabs.DaniAI.Observer : AINode

Properties  

Type Name Summary
Type OutputType The current type of the output.

Methods  

Type Name Summary
Object GetOutput() The current output value as an object type.

RunningState  

Decribes the brain’s ability to run its AI steps.

public enum InitialPrefabs.DaniAI.RunningState : Enum, IComparable, IFormattable, IConvertible

Enum  

Value Name Summary
0 NotInitialized The initial state of the brain. No AI steps are running at this point in time.
1 Running The normal running state of the brain. OnResume is called if the previous state was paused.
2 Paused The brain has paused. OnPause is called once the brain enters this state.
3 Stopped The brain has ceased functioning.

Variable  

A value-storing object that is local to the template. They are like Parameters in the Animator.

public abstract class InitialPrefabs.DaniAI.Variable : ScriptableObject

Properties  

Type Name Summary
Type ValueType The variable’s type

Methods  

Type Name Summary
Object GetValue() Gets the variable’s current value.
On this page:
  • Action
  • ActionState
  • AIBrain
  • AINode
  • AITemplate
  • BrainManager
  • Condition
  • Connection
  • ConnectionType
  • CustomMenuPathAttribute
  • DaniAIRuntimeBridge
  • Decision
  • DecisionRunType
  • ExecutionType
  • GenericCondition T
  • GenericObserver T
  • GenericVariable T
  • HideCompareValueAttribute
  • IAIBrain
  • Observer
  • RunningState
  • Variable
Follow Us!

Contact us if you want to work with us for your games and art projects!

     
Copyright © 2016-2025 InitialPrefabs
initialPrefabs
Code copied to clipboard