Introduction
This module builds directly on Module 5: Expanding to Multiple Topics. You will need to complete that module before performing this module. In this module we will be making changes to our topic, extending it to movement in 3 dimensions.
Step 1: Updating ShapeComms
Our classes need to be updated to allow for writing the data from our 3D shape.
- Within the project, add a new class to the ObjectDefs as follows:
public class Shape3D : Shape
{
public int z;
} - Update all instances of Shape to Shape3D (except for the definition of the Shape class in ObjectDefs).
- We will need to add some code to some functions in order to utilize this functionality.
- In ShapeComms, add the following line to the SetShapeData function after the y SetValue call.
data.SetValue("z", shape.z);
- In ShapeComms, add the following line to the ParseShapes function after the y assignment.
z = (Int32)shape.Data.GetAnyValue("z"),
- In ShapeManager, in the MoveShape function, update the new Vector3 call to include shape.z:
m_Shapes[shape.color].GetComponent<Rigidbody>().MovePosition(new Vector3(shape.x, shape.y, shape.z));
- In ShapeManager, in the AddInstance function, update the new Vector3 call to include shape.z:
m_Shapes.Add(shape.color, Instantiate(m_ShapePrefab, new Vector3(shape.x, shape.y, shape.z), new Quaternion()));
Step 2: Test Against RTI Shapes Demo
Here we are using the RTI Shapes Demo shipped with RTI Connext to test our new application.
- Launch the RTI Shapes demo from the RTI Launcher.
- Publish to the Square, Triangle, and Circle topics in the RTI Shapes demo.
- Click OK to use the default settings.
- Run the Unity application. You should see shapes moving across the screen.
If a shape does not appear, check the debug log within Unity to see if there are any problems within your application. Common problems include a missing license or XML file, along with misspellings of references within the XML file.
Also make sure that you didn’t make any mistakes in the conversion process, for example not changing a Shape to a Shape3D.
Conclusion
From this application we have shown that the DDS part of a Unity application is rather straightforward. The key is to map the Data Model used for communication to Unity® objects. Once the mapping is figured out the Unity configuration and DDS code can be done relatively easily.
Module 6 Demo
This video covers the steps for Module 6.
Next Steps
Now that you have completed the Unity and Connext Case + Code tutorial, please visit the RTI Community to share your feedback, ask questions and show the world what you built with Unity and Connext.
The objects and scripts used within this project can be found here in GitHub.
This is only an introduction to this type of integration. You should also check out our Unreal Engine Case + Code, which works using the same data model and behavior as this tutorial. This provides a method for interoperation between the two platforms and the option for tailoring the appropriate game engine to different requirements and/or developer experience.
Visit our Modeling, Simulation & Training web page to learn more about using RTI Connext in simulation environments.