-
Notifications
You must be signed in to change notification settings - Fork 23
Home
- Firstly, download the last release and import it into your Unity Project.
- Create a script MyAIBrain inheriting from AbstractAIBrain.
- Create a script MyAIComponent inheriting from AbstractAIComponent and add it to your GameObject.
- Create scripts inheriting from SimpleActionNode, SimpleEntryNode or CollectionEntryNode.
- Create a MyAIBrain using Unity ScriptableObject contextual menu.
- Add your custom nodes on the Node graph with UtilityNode and OptionNode.
- ...
- Make profit !
The AI Brain allow you to create a graph to link into your AI Component.
[Serializable, CreateAssetMenu(fileName = "CubeAIBrain", menuName = "AI/CubeAIBrain")]
public class CubeAIBrain : AbstractAIBrain {}
When your AI Brain script is created just use the Unity contextual menu to instantiate it Double click on the new file and you will access to the xNode graph window
The AI Component allow you to transfer contextual information to your Entry and Action nodes. Moreover it allow you to retrieve the best choosen option using the ChooseOption() method and to execute the linked action with the ExecuteActions(this) method.
public class CubeAIComponent : AbstractAIComponent {
// Your custom references here
public CubeEntity CubeEntity;
// End of custom references
private void Start() {
InvokeRepeating("ThinkAndAct", 0, 0.1f);
}
private void ThinkAndAct() {
AIOption option = ChooseOption();
if (option == null) return;
option.ExecuteActions(this);
}
}
Add the component to any GameObject (prefab or in scene) associated to this AI (an enemy for exemple).
Finally, add your AI Brain to the Utility Ai Brain of your component
You can create entry node to provide data to your utility AI, for this you can inherit from SimpleEntryNode and override the ValueProvider method :
public class CurrentHpCountNode : SimpleEntryNode {
protected override int ValueProvider(AbstractAIComponent context) {
CubeAIComponent cubeAiComponent = (CubeAIComponent) context;
return cubeAiComponent.CubeEntity.CurrentHp;
}
}
When your SimpleEntryNode script is created you can instantiate the node using the xNode contextual menu in the graph of you AI Brain.
Connect the "Value" output to one of the "X" input of an utility node.
You can create action node to execute action based on your context, for this you can inherit from ActionEntryNode and override the Execute method :
public class HealNode : SimpleActionNode {
public override void Execute(AbstractAIComponent context, AIData aiData) {
CubeAIComponent cubeAiComponent = (CubeAIComponent) context;
cubeAiComponent.CubeEntity.Heal();
}
}
When your SimpleActionNode script is created you can instantiate the node using the xNode contextual menu in the graph of you AI Brain.
Connect the "Linked Option" output to the "Actions" input of an option node, then connect the utility "Utility Y" to the "Utilities" input of the same option node.