-
Notifications
You must be signed in to change notification settings - Fork 23
Home
FBast edited this page Jun 13, 2019
·
45 revisions
- 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
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 MyAIComponent : AbstractAIComponent {
// Your custom references here
public Soldier soldier;
// 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);
}
}
You can create entry node to provide data to your utility AI, for this you can inherit from SimpleEntryNode and override the ValueProvider method :
protected override int ValueProvider(AbstractAIComponent context) {
MyAIComponent myAiComponent= (MyAIComponent) context;
return myAiComponent.soldier.CurrentHp;
}
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 override void Execute(AbstractAIComponent context, AIData aiData) {
MyAIComponent myAiComponent= (MyAIComponent) context;
myAiComponent.soldier.Heal();
}