Example: Cube

Navigation:  Toolboxes > Unity Toolbox >

Example: Cube

Previous pageReturn to chapter overviewNext page

GameObjects

 

When you have installed the 20-sim Unity Toolbox correctly, it should be visible in Unity in the Hierarchy at the left. You can insert all kinds of Game Objects and connect them with variables coming from the 20-sim model. Let's start with a Cube.

1.From the GameObject menu select 3D Object - Cube.

 

Now Cube object is visibe in the Hierachy.

 

UnityToolbox_CreateCube

Creating a Cube.

2.In the Hierachy select the Cube object.
3.In the Inspector at the bottom right click Add Component - 20-sim Unity Toolbox - 20-sim coordinates.

 

Now you will see a 20-sim Variable component in the Inspector. Here you can connect the properties of the Cube with variables in your 20-sim model. If our 20-sim model contains a Submodel named Cube with three variables x, y and z, we can connect these with the position of the cube.

4.In the 20-sim Variable component keep the Input/Output button on Input.
5.Add the variable names to the x-, y- and z-axis as shown in the next figure.

UnityToolbox_ConnectCube

Connecting the position of the Cube with 20-sim variables.

In a similar manner you can create many more Game Objects and connect them with 20-sim variables.

Building a Unity Animation

When all objects have been defined we can generate a Unity Animation. Unity Animations are stored in an .fmu file.

6.In the Hierarchy at the left select 20-sim Unity Toolbox.
7.In the Inspector at the right go to 20-sim Unity Toolbox and Build Unity Animation.
8.Enter the Export Location (a folder where you have read and write access) and Animation Name (e.g. Cube) and click Build Unity Animation.

UnityToolbox_BuildUnityAnimation

Building a Unity Animation.

Now the file Cube.fmu will be created in the export location that you have chosen.

Importing the Unity Animation in 20-sim

We will drag and drop the Cube.fmu file into 20-sim and connect the x,y and z input with signal generators.

9.Open 20-sim
10.From the export location, drag and drop the file Cube.fmu to the Editor.
11.From the Signal/Sources library drag and drop the following submodels in the Editor:
WaveGenerator-Sine
WaveGenerator-Cosine
WaveGenerator-Saw
12.Connect the sine model with the Cube model (x), the cosine model with Cube (y) and the saw model with Cube (z).

UnityToolbox_ConnectingFMU

Connecting the FMU.

Running the Unity Animation

When you simulate the 20-sim model, a Unity Animation will pop up and run with the simulation. Generally the simulation will be much too fast to follow. Therefore we must force the simulation to run in real-time.

13.In the Editor, from the Model menu select Start Simulator.
14.In the Simulator from the Properties Menu select Run.

UnityToolbox_RealTimeSimulation

Forcing a real-time simulation.

15.In the Run Properties dialog click the More button and select Attempting Realtime Simulation On.
16.Click Ok to close the Run Properties dialog.
17.From the Simulation menu select Run.

Now you will see a Unity Animation window appear showing the cube moving.

UnityToolbox_CubeUnityAnimation

The unity Animation with the cube.

18.In case Unity Animation Window is displayed in windowed mode, Click Alt-Enter to change the full screen mode.