A Flutter plugin for embedding Unity projects in Flutter projects.
iOS is currently not supported.
To use this plugin, add flutter_unity
as a dependency in your pubspec.yaml file.
Refer to the example project and the included Unity project. Both projects are fully configured.
- Go to File > Build Settings... to open the Build Settings window.
- Select Android and click Switch Platform.
- Click Add Open Scenes.
- Check Export Project.
- Click Player Settings... to open the Player Settings window.
- In the Player Settings window, configure the following:
Setting | Value |
---|---|
Other Settings > Rendering > Graphics APIs | OpenGLES3 |
Other Settings > Configuration > Scripting Backend | IL2CPP |
Other Settings > Configuration > Target Architectures | ARMv7, ARM64 |
- Close the Player Settings window.
- Click Export and save as
unityExport
.
- Copy the
unityExport
folder to<your_flutter_project>/android/unityExport
. - Run
flutter pub run flutter_unity:unity_export_transmogrify
. - Open
<your_flutter_project>/android/build.gradle
and, underallprojects { repositories {} }
, add the following:
flatDir {
dirs "${project(':unityExport').projectDir}/libs"
}
Refer to the example project's build.gradle.
- Open
<your_flutter_project>/android/settings.gradle
and add the following:
include ':unityExport'
Refer to the example project's settings.gradle.
To send a message, define the onCreated
callback in your UnityView
widget, and use the send
method from the received controller
.
To receive a message, define the onMessage
callback in your UnityView
widget.
To send and receive messages, include FlutterUnityPlugin.cs in your project, and use the Messages.Send
and Messages.Receive
methods.
A Message
object has the following members:
- id (
int
)
A non-negative number representing the source view when receiving a message, and the destination view when sending a message. When sending a message, it can also be set to a negative number, indicating that the message is intended for any existing view.
- data (
string
)
The actual message.
Refer to the included Unity project's Rotate.cs.