Code Monkey home page Code Monkey logo

flutter-unity's Introduction

flutter_unity

A Flutter plugin for embedding Unity projects in Flutter projects.

iOS is currently not supported.

Usage

To use this plugin, add flutter_unity as a dependency in your pubspec.yaml file.

Example

Refer to the example project and the included Unity project. Both projects are fully configured.

Configuring your Unity project (Android)

  1. Go to File > Build Settings... to open the Build Settings window.
  2. Select Android and click Switch Platform.
  3. Click Add Open Scenes.
  4. Check Export Project.
  5. Click Player Settings... to open the Player Settings window.
  6. 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
  1. Close the Player Settings window.
  2. Click Export and save as unityExport.

Configuring your Flutter project (Android)

  1. Copy the unityExport folder to <your_flutter_project>/android/unityExport.
  2. Run flutter pub run flutter_unity:unity_export_transmogrify.
  3. Open <your_flutter_project>/android/build.gradle and, under allprojects { repositories {} }, add the following:
flatDir {
    dirs "${project(':unityExport').projectDir}/libs"
}

Refer to the example project's build.gradle.

  1. Open <your_flutter_project>/android/settings.gradle and add the following:
include ':unityExport'

Refer to the example project's settings.gradle.

Exchanging messages between Flutter and Unity

Flutter

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.

Unity

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.

flutter-unity's People

Contributors

cookiejarlid avatar marcotuna avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.