Functional Mock-up Interface for Unity
Download and import the Unity package. Select Assets > Import FMU
to import the FMU.
This creates the model description in Resources
that lists the available variables and extracts the FMU to the
StreamingAssets
folder.
Now you can use the FMU the in your scripts (see BouncingBall.cs for a complete example):
public class BouncingBall : MonoBehaviour {
FMU fmu;
void Start () {
fmu = new FMU2("bouncingBall");
fmu.SetupExperiment(Time.time);
fmu.EnterInitializationMode();
fmu.ExitInitializationMode();
}
void FixedUpdate() {
fmu.DoStep(Time.time, Time.deltaTime);
transform.position = Vector3.up * (float)fmu.GetReal("h");
}
}
The example scene SampleScenes/BouncingBall
shows you how to instantiate and reset the model, set input and get output.
Values.cs demonstrates how to use value references and to get and set Real
, Integer
, Boolean
and String
variables.
Currently the FMI add-on supports only a limited subset of FMI 2.0 for co-simulation API. It runs on Mac and 64-bit Windows (make sure you select x86_64
as architecture when exporting the player on Windows).
If you've cloned the repository you need to download dotnetzip.1.11.0.nupgk, extract it (it's a ZIP archive) and copy DotNetZip.dll
in lib/net20
to Unity/Assets/FMI/Editor/Plugins
. This library is required to extract FMUs during the import. DotNetZip.dll is already included in the pre-built Unity package.
You've found a problem? Fantastic, a problem found is a problem fixed. Please take a moment to read the contributing guide before you open an issue.
The code is licensed under the BSD 3-clause license. Copyright © 2018 Dassault Systèmes. All rights reserved.