In the AI Tree you can easily create your own task by using scripting API. In this page we will show how you can do it.
In this context, we believe that you have already read the previous pages of User Scripting section.
In the previous section, we created a task for the platform moving. Let's create unique key for defining point A, B and speed.
Create new script and call it PlatformKey, after creation open it script in you scripts editor tool.
Create -> MonoBehaviour Script
Default Unity MonoBehaviour script template.
using UnityEngine;
public class PlatformKey : MonoBehaviour
{
// Start is called once before the first execution of Update
// after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
First of all we need to decide what we will define as key. Let's create new struct PlatformData. Don't forget to add [Serializable] attribute for custom types.
using UnityEngine;
using System;
[Serializable]
public struct PlatformData
{
public Vector3 pointA;
public Vector3 pointB;
public float speed;
}
public class PlatformKey : MonoBehaviour
{
// Start is called once before the first execution of Update
// after the MonoBehaviour is created
void Start()
{
}
// Update is called once per frame
void Update()
{
}
}
Now we are ready to define our PlatformData key. We need to change the PlatformKey class.
Remove all methods.
Change MonoBehaviour parent class to Key<PlatformData>
using RenownedGames.AITree;
using System;
using UnityEngine;
[Serializable]
public struct PlatformData
{
public Vector3 pointA;
public Vector3 pointB;
public float speed;
}
public class PlatformKey : Key<PlatformData> { }
Done. It's all required steps to define your our key in AITree. Any other type can be used instead of the PlatformData type.
We can improve displaying of PlatformKey in editor. For that we will use Apexlibrary what included in AITree out of box.
All editor classes, tasks, keys, decorators, components in AI Tree powered by Apex.
Open PlatformKey class add following attributes on field of PlatformData struct.
using RenownedGames.AITree;
using RenownedGames.Apex;
using System;
using UnityEngine;
[Serializable]
public struct PlatformData
{
[HideLabel]
public Vector3 pointA;
[HideLabel]
public Vector3 pointB;
[LabelWidth(100)]
public float speed;
}
public class PlatformKey : Key<PlatformData> { }