How to create the Tutorial scene?
Introduction
We will explain in this article how does the tutorial scene has been created. It will mainly talk about the fivetype and relation creations.
In this part of the tutorial, you will create your own scene using the script from the tutorial.
First steps
First of all, open the scene (Tutorial/Scenes/TutorialCreation). It is composed of one cube and one sphere corresponding to the user.
If you press the button Play in Unity, the object's colors do not change yet and you can move the User by left clicking on the game view.
Then, you have to add the Xareus prefab in the scene. This prefab manage the relation engine and en scenario engine.
By default the scenario engine has not got any scenario, and if you click Play it will generate an error, since it is waiting for a scenario. Go find the scenario EmptyScenario in the Scenarios folder. if you double click on it, it will open the scenario in the editor.
Drag and drop this scenario in the field Scenario Xml in the Scneario Engine Kernel of the Xareus prefab. If you click play, the scene has not changed but it is now Xareus Ready!
We will now add relations to the scene.
Add a behavior
You will find more information on fivetype creation here, before going throught this part.
To add an existing behavior to an object you need to add the component to your object (By dropping it on the object or adding it thought the inspector).
TypeColored
There are three behaviors in the tutorial : Colored, Textured and User. We will start by adding Colored to both object and User to the sphere.
The script in the inspector should look like this when you first compile unity after saving your script. Give it an id and a the color you want.
And that's it ! Your objects got the behavior you need.
Add a Relation
Now we want to create a relation between the cube and the sphere.
You will find more information on relation creation here, before going throught this part.
For a relation to be recognized by the Relation Engine, it has to be present in your scene in a GameObject. So, create an empty GameObject in your scene and add the component to it.
for an example, the relations in the tutorial scene are presented like shown on this image.
From this point, if you play the scene, nothing will happen because we do not ask anything to the Relation Engine.
This is done by doing queries!
Create a Query
Your scene should now have types and relations, unfortunately you are asking nothing the Relation Engine, that is why if you launch the scene they are sleepy.
We will use the code below, and understand it. The script is in the folder Scripts.
Add this script to the User sphere.
public class CollisionBehavior : MonoBehaviour
{
We use the method OnTriggerEnter to get the event of collision between two box collider Trigger. For each collision we check of the collided object is an UFObject, and if it is the case we ask the Relation Engine to execute the realisation if possible.
So, we add to the query both User and collided object for all possible relation.
Then, we ask the relation engine which realization is possible in this query using GetRealizations().
private void OnTriggerEnter(Collider other)
{
UFObject otherObject = other.GetComponent<UFObject>();
if (otherObject != null)
{
UFRealizationQueryParameters query = UFRealizationQueryParameters.GetQueryAllRelation(UFManager.instance.ufIRelationEngine);
query.MandatoryObjects.Add(gameObject.GetComponent<UFObject>());
query.MandatoryObjects.Add(otherObject);
UFManager.instance.ufIRelationEngine.GetRealizations(query, HandleQuery);
}
}
Finally, we execute every possible realization using *ExecuteRealizationIfPossible()*.
private void HandleQuery(List<UFRealization> realizations)
{
foreach (UFRealization realization in realizations)
{
UFManager.instance.ExecuteRealizationIfPossible(realization);
}
}
}
Finally, if you play the scene, when the User enters in collision with another Colored object it swaps their colors.
Your scene is ready! Congratulation! It is all up to you now. Try to do the same for the Textured behavior (some textured are available in the folder Textured), and add as many as objects you want in the scene with the behavior you want.
Release your scenario
Your scene can now be listened by a scenario. Create your own scenario using the scenario editor! Inspire yourself with the Listener Scenario from the tutorial and use the Time for Practice to help you.
Note
Do not forget to apply your scenario in the Xareus prefab for the Relation Engine Kernel. Simply drag and drop your xml file in the Scenario Xml field