Sarama Demsas

Sarama Demsas

1595487260

Embeddable Unity Game Engine View for Flutter

flutter_unity_widget

Flutter unity 3D widget for embedding unity in flutter. Now you can make awesome gamified features of your app in Unity and get it rendered in a Flutter app both in fullscreen and embeddable mode. Works great on Android and iOS. There are now two unity app examples in the unity folder, one with the default scene and another based on Unity AR foundation samples.

Note: I have updated the example for Unity 2019.3.5 and there are some new changes in the scripts folder. Please replace your already copied files and folders in your unity project

Installation

First depend on the library by adding this to your packages pubspec.yaml:

dependencies:
  flutter_unity_widget: ^0.1.6+8

Now inside your Dart code you can import it.

import 'package:flutter_unity_widget/flutter_unity_widget.dart';

Preview

30 fps gifs, showcasing communication between Flutter and Unity:

gif gif

Setup Project

For this, there is also a video tutorial, which you can find a here.

Add Unity Project

  1. Create an unity project, Example: ‘UnityDemoApp’.
  2. Create a folder named unity in flutter project folder.
  3. Move unity project folder to unity folder.

Now your project files should look like this.

.
├── android
├── ios
├── lib
├── test
├── unity
│   └── <Your Unity Project>    // Example: UnityDemoApp
├── pubspec.yml
├── README.md

Configure Player Settings

  1. First Open Unity Project.

  2. Click Menu: File => Build Settings

Be sure you have at least one scene added to your build.

  1. => Player Settings

  2. Android Platform:

  3. Make sure your Graphics APIs are set to OpenGLES3 with a fallback to OpenGLES2 (no Vulkan)

  4. Change Scripting Backend to IL2CPP.

  5. Mark the following Target Architectures :

  • ARMv7 ✅
  • ARM64 ✅
  • x86 ✅ (In Unity Version 2019.2+, this feature is not avaliable due to the lack of Unity Official Support)

iOS Platform: 1. This only works with Unity version >=2019.3 because uses Unity as a library! 2. Depending on where you want to test or run your app, (simulator or physical device), you should select the appropriate SDK on Target SDK.

Add Unity Build Scripts and Export

Copy [Build.cs](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/Editor/Build.cs) and [XCodePostBuild.cs](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/Editor/XCodePostBuild.cs) to unity/<Your Unity Project>/Assets/Scripts/Editor/

Open your unity project in Unity Editor. Now you can export the Unity project with Flutter/Export Android (for Unity versions up to 2019.2), Flutter/Export Android (Unity 2019.3.*) (for Unity versions 2019.3 and up, which uses the new Unity as a Library export format), or Flutter/Export IOS menu.

Android will export unity project to android/UnityExport.

IOS will export unity project to ios/UnityExport.

Android Platform Only

  1. After exporting the unity game, open Android Studio and and add the Unity Classes Java .jar file as a module to the unity project. You just need to do this once if you are exporting from the same version of Unity everytime. The .jar file is located in the <Your Flutter Project>/android/UnityExport/lib folder
  2. Add the following to your <Your Flutter Project>/android/settings.gradlefile:
include ":UnityExport"
project(":UnityExport").projectDir = file("./UnityExport")
  1. If using Unity 2019.2 or older, open build.gradle of UnityExport module and replace the dependencies with
    dependencies {
        implementation project(':unity-classes') // the unity classes module you added from step 1
    }
  1. To build a release package, you need to add signconfig in UnityExport/build.gradle. The code below use the debug signConfig for all buildTypes, which can be changed as you well if you need specify signConfig.
    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
        debug {
            signingConfig signingConfigs.debug
        }
        profile{
            signingConfig signingConfigs.debug
        }
        innerTest {
            //...
            matchingFallbacks = ['debug', 'release']
        }
    }
  1. If you found the duplicate app icons on your launcher after installing the app, you can just open UnityExport Manifest file and comment the codes below
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
//      <intent-filter>
//        <action android:name="android.intent.action.MAIN" />
//        <category android:name="android.intent.category.LAUNCHER" />
//        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
//      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>

iOS Platform Only

  1. open your ios/Runner.xcworkspace (workspace!, not the project) in Xcode and add the exported project in the workspace root (with a right click in the Navigator, not on an item -> Add Files to “Runner” -> add the UnityExport/Unity-Iphone.xcodeproj file

2. Select the Unity-iPhone/Data folder and change the Target Membership for Data folder to UnityFramework

3. Add this to your Runner/Runner/Runner-Bridging-Header.h

#import "UnityUtils.h"
  1. Add to Runner/Runner/AppDelegate.swift before the GeneratedPluginRegistrant call:
InitArgs(CommandLine.argc, CommandLine.unsafeArgv)

Or when using Objective-C your main.m should look like this:

#import "UnityUtils.h"

int main(int argc, char * argv[]) {
  @autoreleasepool {
    InitArgs(argc, argv);
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  }
}
  1. Opt-in to the embedded views preview by adding a boolean property to the app’s Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

  2. Add UnityFramework.framework as a Library to the Runner project

AR Foundation ( requires Unity 2019.3.*)

gif

Check out the Unity AR Foundation Samples Demo Repository

The Demo Repository is not guaranteed to be up-to-date with the latest flutter-unity-view-widget master. Make sure to follow the steps listed below for setting up AR Foundation on iOS and Android in your projects.

iOS

Go to target info list on Xcode and add this key and value;

key: Privacy - Camera Usage Description value: $(PRODUCT_NAME) uses Cameras

Android

If you want to use Unity for integrating Augmented Reality in your Flutter app, a few more changes are required:

  1. Export the Unity Project as previously stated (using the Editor Build script).
  2. Check if the exported project includes all required Unity libraries (.so) files (lib/\<architecture\>/libUnityARCore.so and libarpresto_api.so). There seems to be a bug where a Unity export does not include all lib files. If they are missing, use Unity to build a standalone .apk of your AR project, unzip the resulting apk, and copy over the missing .lib files to the UnityExport module.
  3. Similar to how you’ve created the unity-classes module in Android Studio, create similar modules for all exported .aar and .jar files in the UnityExport/libs folder (arcore_client.aarunityandroidpermissions.aarUnityARCore.aar).
  4. Update the build.gradle script of the UnityExport module to depend on the new modules (again, similar to how it depends on unity-classes).
  5. Finally, update your Dart code build method where you include the UnityWidget and add isARScene: true,. Sadly, this does have the side effect of making your Flutter activity act in full screen, as Unity requires control of your Activity for running in AR, and it makes several modifications to your Activity as a result (including setting it to full screen).

Add UnityMessageManager Support

Copy [UnityMessageManager.cs](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/UnityMessageManager.cs) to your unity project.

Copy this folder [JsonDotNet](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/JsonDotNet) to your unity project.

Copy [link.xml](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/link.xml) to your unity project.

(2019.3.5* only) Copy this folder [Plugins](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/Plugins) to your unity project.

Vuforia

Android

Similar to setting up AR Foundation, but creating a module for the VuforiaWrapper instead.

Thanks to @PiotrxKolasinski for writing down the exact steps:

  1. Change in build.gradle: implementation(name: 'VuforiaWrapper', ext:'aar') to implementation project(':VuforiaWrapper')
  2. In settings.gradle in the first line at the end add: ':VuforiaWrapper'
  3. From menu: File -> New -> New Module choose “import .JAR/.AAR Package” and add lib VuforiaWrapper.arr. Move generated folder to android/
  4. In Widget UnityWidget add field: isARScene: true
  5. Your App need camera permission (you can set in settings on mobile)

Examples

Simple Example

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

class UnityDemoScreen extends StatefulWidget {

  UnityDemoScreen({Key key}) : super(key: key);

  @override
  _UnityDemoScreenState createState() => _UnityDemoScreenState();
}

class _UnityDemoScreenState extends State<UnityDemoScreen>{
  static final GlobalKey<ScaffoldState> _scaffoldKey =
      GlobalKey<ScaffoldState>();
  UnityWidgetController _unityWidgetController;

  Widget build(BuildContext context) {

    return Scaffold(
      key: _scaffoldKey,
      body: SafeArea(
        bottom: false,
        child: WillPopScope(
          onWillPop: () {
            // Pop the category page if Android back button is pressed.
          },
          child: Container(
            color: colorYellow,
            child: UnityWidget(
              onUnityViewCreated: onUnityCreated,
            ),
          ),
        ),
      ),
    );
  }

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;
  }
}

Communicating with and from Unity

import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  static final GlobalKey<ScaffoldState> _scaffoldKey =
      GlobalKey<ScaffoldState>();
  UnityWidgetController _unityWidgetController;
  double _sliderValue = 0.0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: const Text('Unity Flutter Demo'),
        ),
        body: Card(
          margin: const EdgeInsets.all(8),
          clipBehavior: Clip.antiAlias,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20.0),
          ),
          child: Stack(
            children: <Widget>[
              UnityWidget(
                onUnityViewCreated: onUnityCreated,
                isARScene: false,
                onUnityMessage: onUnityMessage,
              ),
              Positioned(
                bottom: 20,
                left: 20,
                right: 20,
                child: Card(
                  elevation: 10,
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.only(top: 20),
                        child: Text("Rotation speed:"),
                      ),
                      Slider(
                        onChanged: (value) {
                          setState(() {
                            _sliderValue = value;
                          });
                          setRotationSpeed(value.toString());
                        },
                        value: _sliderValue,
                        min: 0,
                        max: 20,
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  // Communcation from Flutter to Unity
  void setRotationSpeed(String speed) {
    _unityWidgetController.postMessage(
      'Cube',
      'SetRotationSpeed',
      speed,
    );
  }

  // Communication from Unity to Flutter
  void onUnityMessage(controller, message) {
    print('Received message from unity: ${message.toString()}');
  }

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;
  }
}

API

  • pause() (Use this to pause unity player)
  • resume() (Use this to resume unity player)
  • postMessage(String gameObject, methodName, message) (Allows you invoke commands in Unity from flutter)
  • onUnityMessage(data) (Unity to flutter bindding and listener)

Known issues

  • Android Export requires several manual changes
  • Using AR will make the activity run in full screen (hiding status and navigation bar).

Download Details:

Author: snowballdigital

GitHub: https://github.com/snowballdigital/flutter-unity-view-widget

#flutter #unity #game #dart #mobile-apps

What is GEEK

Buddha Community

Embeddable Unity Game Engine View for Flutter

Google's Flutter 1.20 stable announced with new features - Navoki

Flutter Google cross-platform UI framework has released a new version 1.20 stable.

Flutter is Google’s UI framework to make apps for Android, iOS, Web, Windows, Mac, Linux, and Fuchsia OS. Since the last 2 years, the flutter Framework has already achieved popularity among mobile developers to develop Android and iOS apps. In the last few releases, Flutter also added the support of making web applications and desktop applications.

Last month they introduced the support of the Linux desktop app that can be distributed through Canonical Snap Store(Snapcraft), this enables the developers to publish there Linux desktop app for their users and publish on Snap Store.  If you want to learn how to Publish Flutter Desktop app in Snap Store that here is the tutorial.

Flutter 1.20 Framework is built on Google’s made Dart programming language that is a cross-platform language providing native performance, new UI widgets, and other more features for the developer usage.

Here are the few key points of this release:

Performance improvements for Flutter and Dart

In this release, they have got multiple performance improvements in the Dart language itself. A new improvement is to reduce the app size in the release versions of the app. Another performance improvement is to reduce junk in the display of app animation by using the warm-up phase.

sksl_warm-up

If your app is junk information during the first run then the Skia Shading Language shader provides for pre-compilation as part of your app’s build. This can speed it up by more than 2x.

Added a better support of mouse cursors for web and desktop flutter app,. Now many widgets will show cursor on top of them or you can specify the type of supported cursor you want.

Autofill for mobile text fields

Autofill was already supported in native applications now its been added to the Flutter SDK. Now prefilled information stored by your OS can be used for autofill in the application. This feature will be available soon on the flutter web.

flutter_autofill

A new widget for interaction

InteractiveViewer is a new widget design for common interactions in your app like pan, zoom drag and drop for resizing the widget. Informations on this you can check more on this API documentation where you can try this widget on the DartPad. In this release, drag-drop has more features added like you can know precisely where the drop happened and get the position.

Updated Material Slider, RangeSlider, TimePicker, and DatePicker

In this new release, there are many pre-existing widgets that were updated to match the latest material guidelines, these updates include better interaction with Slider and RangeSliderDatePicker with support for date range and time picker with the new style.

flutter_DatePicker

New pubspec.yaml format

Other than these widget updates there is some update within the project also like in pubspec.yaml file format. If you are a flutter plugin publisher then your old pubspec.yaml  is no longer supported to publish a plugin as the older format does not specify for which platform plugin you are making. All existing plugin will continue to work with flutter apps but you should make a plugin update as soon as possible.

Preview of embedded Dart DevTools in Visual Studio Code

Visual Studio code flutter extension got an update in this release. You get a preview of new features where you can analyze that Dev tools in your coding workspace. Enable this feature in your vs code by _dart.previewEmbeddedDevTools_setting. Dart DevTools menu you can choose your favorite page embed on your code workspace.

Network tracking

The updated the Dev tools comes with the network page that enables network profiling. You can track the timings and other information like status and content type of your** network calls** within your app. You can also monitor gRPC traffic.

Generate type-safe platform channels for platform interop

Pigeon is a command-line tool that will generate types of safe platform channels without adding additional dependencies. With this instead of manually matching method strings on platform channel and serializing arguments, you can invoke native class and pass nonprimitive data objects by directly calling the Dartmethod.

There is still a long list of updates in the new version of Flutter 1.2 that we cannot cover in this blog. You can get more details you can visit the official site to know more. Also, you can subscribe to the Navoki newsletter to get updates on these features and upcoming new updates and lessons. In upcoming new versions, we might see more new features and improvements.

You can get more free Flutter tutorials you can follow these courses:

#dart #developers #flutter #app developed #dart devtools in visual studio code #firebase local emulator suite in flutter #flutter autofill #flutter date picker #flutter desktop linux app build and publish on snapcraft store #flutter pigeon #flutter range slider #flutter slider #flutter time picker #flutter tutorial #flutter widget #google flutter #linux #navoki #pubspec format #setup flutter desktop on windows

Terry  Tremblay

Terry Tremblay

1598396940

What is Flutter and why you should learn it?

Flutter is an open-source UI toolkit for mobile developers, so they can use it to build native-looking** Android and iOS** applications from the same code base for both platforms. Flutter is also working to make Flutter apps for Web, PWA (progressive Web-App) and Desktop platform (Windows,macOS,Linux).

flutter-mobile-desktop-web-embedded_min

Flutter was officially released in December 2018. Since then, it has gone a much stronger flutter community.

There has been much increase in flutter developers, flutter packages, youtube tutorials, blogs, flutter examples apps, official and private events, and more. Flutter is now on top software repos based and trending on GitHub.

Flutter meaning?

What is Flutter? this question comes to many new developer’s mind.

humming_bird_dart_flutter

Flutter means flying wings quickly, and lightly but obviously, this doesn’t apply in our SDK.

So Flutter was one of the companies that were acquired by **Google **for around $40 million. That company was based on providing gesture detection and recognition from a standard webcam. But later when the Flutter was going to release in alpha version for developer it’s name was Sky, but since Google already owned Flutter name, so they rename it to Flutter.

Where Flutter is used?

Flutter is used in many startup companies nowadays, and even some MNCs are also adopting Flutter as a mobile development framework. Many top famous companies are using their apps in Flutter. Some of them here are

Dream11

Dream11

NuBank

NuBank

Reflectly app

Reflectly app

Abbey Road Studios

Abbey Road Studios

and many more other apps. Mobile development companies also adopted Flutter as a service for their clients. Even I was one of them who developed flutter apps as a freelancer and later as an IT company for mobile apps.

Flutter as a service

#dart #flutter #uncategorized #flutter framework #flutter jobs #flutter language #flutter meaning #flutter meaning in hindi #google flutter #how does flutter work #what is flutter

Autumn  Blick

Autumn Blick

1602565700

Game Development with .NET

We’ve launched a new Game Development with .NET section on our site. It’s designed for current .NET developers to explore all the choices available to them when developing games. It’s also designed for new developers trying to learn how to use .NET by making games. We’ve also launched a new game development Learn portal for .NET filled with tutorials, videos, and documentation provided by Microsoft and others in the .NET game development community. Finally, we launched a step-by-step Unity get-started tutorial that will get you started with Unity and writing C## scripts for it in no time. We are excited to show you what .NET has to offer to you when making games. .NET is also part of Microsoft Game Stack, a comprehensive suite of tools and services just for game development.

A picture of a game controller

.NET for game developers

.NET is cross-platform. With .NET you can target over 25+ different platforms with a single code base. You can make games for, but not limited to, Windows, macOS, Linux, Android, iOS, Xbox, PlayStation, Nintendo, and mixed reality devices.

C## is the most popular programming language in game development. The wider .NET community is also big. There is no lack of expertise and support you can find from individuals and user groups, locally or online.

.NET does not just cover building your game. You can also use it to build your game’s website with ASP.NET, your mobile app using Xamarin, and even do remote rendering with Microsoft Azure. Your skills will transfer across the entire game development pipeline.

logos of some gaming platforms supported by .NET

Available game engines

The first step to developing games in .NET is to choose a game engine. You can think of engines as the frameworks and tools you use for developing your game. There are many game engines that use .NET and they differ widely. Some of the engines are commercial and some are completely royalty free and open source. I am excited to see some of them planning to adopt .NET 5 soon. Just choose the engine that better works for you and your game. Would you like to read a blog post to help you learn about .NET game engines, and which one would be best for you?

#.net #.net core #azure #c# #game development #azure #cryengine #game developers #game development #game development with .net #game engines #games #monogame #playfab #stride #unity #visual studio #waveengine

Sarama Demsas

Sarama Demsas

1595487260

Embeddable Unity Game Engine View for Flutter

flutter_unity_widget

Flutter unity 3D widget for embedding unity in flutter. Now you can make awesome gamified features of your app in Unity and get it rendered in a Flutter app both in fullscreen and embeddable mode. Works great on Android and iOS. There are now two unity app examples in the unity folder, one with the default scene and another based on Unity AR foundation samples.

Note: I have updated the example for Unity 2019.3.5 and there are some new changes in the scripts folder. Please replace your already copied files and folders in your unity project

Installation

First depend on the library by adding this to your packages pubspec.yaml:

dependencies:
  flutter_unity_widget: ^0.1.6+8

Now inside your Dart code you can import it.

import 'package:flutter_unity_widget/flutter_unity_widget.dart';

Preview

30 fps gifs, showcasing communication between Flutter and Unity:

gif gif

Setup Project

For this, there is also a video tutorial, which you can find a here.

Add Unity Project

  1. Create an unity project, Example: ‘UnityDemoApp’.
  2. Create a folder named unity in flutter project folder.
  3. Move unity project folder to unity folder.

Now your project files should look like this.

.
├── android
├── ios
├── lib
├── test
├── unity
│   └── <Your Unity Project>    // Example: UnityDemoApp
├── pubspec.yml
├── README.md

Configure Player Settings

  1. First Open Unity Project.

  2. Click Menu: File => Build Settings

Be sure you have at least one scene added to your build.

  1. => Player Settings

  2. Android Platform:

  3. Make sure your Graphics APIs are set to OpenGLES3 with a fallback to OpenGLES2 (no Vulkan)

  4. Change Scripting Backend to IL2CPP.

  5. Mark the following Target Architectures :

  • ARMv7 ✅
  • ARM64 ✅
  • x86 ✅ (In Unity Version 2019.2+, this feature is not avaliable due to the lack of Unity Official Support)

iOS Platform: 1. This only works with Unity version >=2019.3 because uses Unity as a library! 2. Depending on where you want to test or run your app, (simulator or physical device), you should select the appropriate SDK on Target SDK.

Add Unity Build Scripts and Export

Copy [Build.cs](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/Editor/Build.cs) and [XCodePostBuild.cs](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/Editor/XCodePostBuild.cs) to unity/<Your Unity Project>/Assets/Scripts/Editor/

Open your unity project in Unity Editor. Now you can export the Unity project with Flutter/Export Android (for Unity versions up to 2019.2), Flutter/Export Android (Unity 2019.3.*) (for Unity versions 2019.3 and up, which uses the new Unity as a Library export format), or Flutter/Export IOS menu.

Android will export unity project to android/UnityExport.

IOS will export unity project to ios/UnityExport.

Android Platform Only

  1. After exporting the unity game, open Android Studio and and add the Unity Classes Java .jar file as a module to the unity project. You just need to do this once if you are exporting from the same version of Unity everytime. The .jar file is located in the <Your Flutter Project>/android/UnityExport/lib folder
  2. Add the following to your <Your Flutter Project>/android/settings.gradlefile:
include ":UnityExport"
project(":UnityExport").projectDir = file("./UnityExport")
  1. If using Unity 2019.2 or older, open build.gradle of UnityExport module and replace the dependencies with
    dependencies {
        implementation project(':unity-classes') // the unity classes module you added from step 1
    }
  1. To build a release package, you need to add signconfig in UnityExport/build.gradle. The code below use the debug signConfig for all buildTypes, which can be changed as you well if you need specify signConfig.
    buildTypes {
        release {
            signingConfig signingConfigs.debug
        }
        debug {
            signingConfig signingConfigs.debug
        }
        profile{
            signingConfig signingConfigs.debug
        }
        innerTest {
            //...
            matchingFallbacks = ['debug', 'release']
        }
    }
  1. If you found the duplicate app icons on your launcher after installing the app, you can just open UnityExport Manifest file and comment the codes below
    <activity android:name="com.unity3d.player.UnityPlayerActivity" android:theme="@style/UnityThemeSelector" android:screenOrientation="fullSensor" android:launchMode="singleTask" android:configChanges="mcc|mnc|locale|touchscreen|keyboard|keyboardHidden|navigation|orientation|screenLayout|uiMode|screenSize|smallestScreenSize|fontScale|layoutDirection|density" android:hardwareAccelerated="false">
//      <intent-filter>
//        <action android:name="android.intent.action.MAIN" />
//        <category android:name="android.intent.category.LAUNCHER" />
//        <category android:name="android.intent.category.LEANBACK_LAUNCHER" />
//      </intent-filter>
      <meta-data android:name="unityplayer.UnityActivity" android:value="true" />
    </activity>

iOS Platform Only

  1. open your ios/Runner.xcworkspace (workspace!, not the project) in Xcode and add the exported project in the workspace root (with a right click in the Navigator, not on an item -> Add Files to “Runner” -> add the UnityExport/Unity-Iphone.xcodeproj file

2. Select the Unity-iPhone/Data folder and change the Target Membership for Data folder to UnityFramework

3. Add this to your Runner/Runner/Runner-Bridging-Header.h

#import "UnityUtils.h"
  1. Add to Runner/Runner/AppDelegate.swift before the GeneratedPluginRegistrant call:
InitArgs(CommandLine.argc, CommandLine.unsafeArgv)

Or when using Objective-C your main.m should look like this:

#import "UnityUtils.h"

int main(int argc, char * argv[]) {
  @autoreleasepool {
    InitArgs(argc, argv);
    return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
  }
}
  1. Opt-in to the embedded views preview by adding a boolean property to the app’s Info.plist file with the key io.flutter.embedded_views_preview and the value YES.

  2. Add UnityFramework.framework as a Library to the Runner project

AR Foundation ( requires Unity 2019.3.*)

gif

Check out the Unity AR Foundation Samples Demo Repository

The Demo Repository is not guaranteed to be up-to-date with the latest flutter-unity-view-widget master. Make sure to follow the steps listed below for setting up AR Foundation on iOS and Android in your projects.

iOS

Go to target info list on Xcode and add this key and value;

key: Privacy - Camera Usage Description value: $(PRODUCT_NAME) uses Cameras

Android

If you want to use Unity for integrating Augmented Reality in your Flutter app, a few more changes are required:

  1. Export the Unity Project as previously stated (using the Editor Build script).
  2. Check if the exported project includes all required Unity libraries (.so) files (lib/\<architecture\>/libUnityARCore.so and libarpresto_api.so). There seems to be a bug where a Unity export does not include all lib files. If they are missing, use Unity to build a standalone .apk of your AR project, unzip the resulting apk, and copy over the missing .lib files to the UnityExport module.
  3. Similar to how you’ve created the unity-classes module in Android Studio, create similar modules for all exported .aar and .jar files in the UnityExport/libs folder (arcore_client.aarunityandroidpermissions.aarUnityARCore.aar).
  4. Update the build.gradle script of the UnityExport module to depend on the new modules (again, similar to how it depends on unity-classes).
  5. Finally, update your Dart code build method where you include the UnityWidget and add isARScene: true,. Sadly, this does have the side effect of making your Flutter activity act in full screen, as Unity requires control of your Activity for running in AR, and it makes several modifications to your Activity as a result (including setting it to full screen).

Add UnityMessageManager Support

Copy [UnityMessageManager.cs](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/UnityMessageManager.cs) to your unity project.

Copy this folder [JsonDotNet](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/JsonDotNet) to your unity project.

Copy [link.xml](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/link.xml) to your unity project.

(2019.3.5* only) Copy this folder [Plugins](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/unity_2019_3_5_later/Plugins) to your unity project.

Vuforia

Android

Similar to setting up AR Foundation, but creating a module for the VuforiaWrapper instead.

Thanks to @PiotrxKolasinski for writing down the exact steps:

  1. Change in build.gradle: implementation(name: 'VuforiaWrapper', ext:'aar') to implementation project(':VuforiaWrapper')
  2. In settings.gradle in the first line at the end add: ':VuforiaWrapper'
  3. From menu: File -> New -> New Module choose “import .JAR/.AAR Package” and add lib VuforiaWrapper.arr. Move generated folder to android/
  4. In Widget UnityWidget add field: isARScene: true
  5. Your App need camera permission (you can set in settings on mobile)

Examples

Simple Example

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

class UnityDemoScreen extends StatefulWidget {

  UnityDemoScreen({Key key}) : super(key: key);

  @override
  _UnityDemoScreenState createState() => _UnityDemoScreenState();
}

class _UnityDemoScreenState extends State<UnityDemoScreen>{
  static final GlobalKey<ScaffoldState> _scaffoldKey =
      GlobalKey<ScaffoldState>();
  UnityWidgetController _unityWidgetController;

  Widget build(BuildContext context) {

    return Scaffold(
      key: _scaffoldKey,
      body: SafeArea(
        bottom: false,
        child: WillPopScope(
          onWillPop: () {
            // Pop the category page if Android back button is pressed.
          },
          child: Container(
            color: colorYellow,
            child: UnityWidget(
              onUnityViewCreated: onUnityCreated,
            ),
          ),
        ),
      ),
    );
  }

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;
  }
}

Communicating with and from Unity

import 'package:flutter/material.dart';
import 'package:flutter_unity_widget/flutter_unity_widget.dart';

void main() => runApp(MyApp());

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  static final GlobalKey<ScaffoldState> _scaffoldKey =
      GlobalKey<ScaffoldState>();
  UnityWidgetController _unityWidgetController;
  double _sliderValue = 0.0;

  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        key: _scaffoldKey,
        appBar: AppBar(
          title: const Text('Unity Flutter Demo'),
        ),
        body: Card(
          margin: const EdgeInsets.all(8),
          clipBehavior: Clip.antiAlias,
          shape: RoundedRectangleBorder(
            borderRadius: BorderRadius.circular(20.0),
          ),
          child: Stack(
            children: <Widget>[
              UnityWidget(
                onUnityViewCreated: onUnityCreated,
                isARScene: false,
                onUnityMessage: onUnityMessage,
              ),
              Positioned(
                bottom: 20,
                left: 20,
                right: 20,
                child: Card(
                  elevation: 10,
                  child: Column(
                    children: <Widget>[
                      Padding(
                        padding: const EdgeInsets.only(top: 20),
                        child: Text("Rotation speed:"),
                      ),
                      Slider(
                        onChanged: (value) {
                          setState(() {
                            _sliderValue = value;
                          });
                          setRotationSpeed(value.toString());
                        },
                        value: _sliderValue,
                        min: 0,
                        max: 20,
                      ),
                    ],
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
  }

  // Communcation from Flutter to Unity
  void setRotationSpeed(String speed) {
    _unityWidgetController.postMessage(
      'Cube',
      'SetRotationSpeed',
      speed,
    );
  }

  // Communication from Unity to Flutter
  void onUnityMessage(controller, message) {
    print('Received message from unity: ${message.toString()}');
  }

  // Callback that connects the created controller to the unity controller
  void onUnityCreated(controller) {
    this._unityWidgetController = controller;
  }
}

API

  • pause() (Use this to pause unity player)
  • resume() (Use this to resume unity player)
  • postMessage(String gameObject, methodName, message) (Allows you invoke commands in Unity from flutter)
  • onUnityMessage(data) (Unity to flutter bindding and listener)

Known issues

  • Android Export requires several manual changes
  • Using AR will make the activity run in full screen (hiding status and navigation bar).

Download Details:

Author: snowballdigital

GitHub: https://github.com/snowballdigital/flutter-unity-view-widget

#flutter #unity #game #dart #mobile-apps

Adobe XD plugin for Flutter with CodePen Tutorial

Recently Adobe XD releases a new version of the plugin that you can use to export designs directly into flutter widgets or screens. Yes, you read it right, now you can make and export your favorite design in Adobe XD and export all the design in the widget form or as a full-screen design, this can save you a lot of time required in designing.

What we will do?
I will make a simple design of a dialogue box with a card design with text over it as shown below. After you complete this exercise you can experiment with the UI. You can make your own components or import UI kits available with the Adobe XD.

#developers #flutter #adobe xd design export to flutter #adobe xd flutter code #adobe xd flutter code generator - plugin #adobe xd flutter plugin #adobe xd flutter plugin tutorial #adobe xd plugins #adobe xd to flutter #adobe xd tutorial #codepen for flutter.