Skip to content

Commit b6b22c5

Browse files
committed
Merge branch 'master' into flutter_unity_widget_2
2 parents 2af831e + f681ba4 commit b6b22c5

27 files changed

+431
-214
lines changed

CHANGELOG.md

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,12 @@
1+
## 2022.3.0
2+
* [Web] Switch to `package:web` to support WebAssembly (WASM).
3+
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
4+
* Fix lint warnings to improve static analysis.
5+
* Small ReadMe fixes.
6+
7+
**Note:**
8+
> This release is unrelated to an old version `2022.3.0-alpha1` of `flutter_unity_widget`.
9+
110
## 2022.2.2
211
* [Android] Fix touch detection when using Unity's New Input System. [#938](https://github.com/juicycleff/flutter-unity-view-widget/pull/938)
312
* [Android] Workaround for mUnityplayer error in Unity plugins using the AndroidJavaProxy. [#908](https://github.com/juicycleff/flutter-unity-view-widget/pull/908)

README.md

Lines changed: 113 additions & 98 deletions
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ is not compatible with other versions, it just mean it's been tested to work wit
9090

9191
## Installation
9292

93-
This plugin requires Flutter >= 3.3.0
93+
This plugin requires Flutter >= 3.16.0.
9494

9595
First depend on the library by adding this to your packages `pubspec.yaml`:
9696
```yaml
@@ -118,7 +118,7 @@ You will need to open and export a Unity project, even for running the example.
118118

119119
## Setup
120120

121-
In the tutorial below, there are steps specific to each platform, denoted by a :information_source: icon followed by
121+
In the tutorial below, there are steps specific to each platform, denoted by a ℹ️ icon followed by
122122
the platform name (Android or iOS). You can click on its icon to expand it.
123123

124124
### Prerequisites
@@ -130,6 +130,23 @@ the platform name (Android or iOS). You can click on its icon to expand it.
130130
- A `fuw-XXXX.unitypackage` file, found in the [*unitypackages*](https://github.com/juicycleff/flutter-unity-view-widget/tree/master/unitypackages) folder.
131131
Try to use the most recent unitypackage available.
132132

133+
### Unity versions for publishing
134+
If you want to publish your app for Android or iOS, you need to satisfy certain Unity version requirements.
135+
136+
**iOS**
137+
Apple's [privacy manifest requirements](https://discussions.unity.com/t/apple-privacy-manifest-updates-for-unity-engine/936052) need a minimal Unity version of:
138+
* 2021.3.35+
139+
* 2022.3.18+
140+
* 6000.0.0+
141+
142+
**Android**
143+
> Starting November 1st, 2025, all new apps and updates to existing apps submitted to Google Play and targeting Android 15+ devices must support 16 KB page sizes.
144+
145+
This requires [Unity versions](https://discussions.unity.com/t/info-unity-engine-support-for-16-kb-memory-page-sizes-android-15/1589588):
146+
* 2021.3.48+ (Enterprise and Industry only)
147+
* 2022.3.56+
148+
* 6000.0.38+
149+
133150

134151
### Unity project setup
135152
These instructions assume you are using a new Unity project. If you open the example project from this repository, you can move on to the next section **Unity Exporting**.
@@ -198,7 +215,7 @@ After exporting Unity, you will need to make some small changes in your iOS or A
198215
You will likely need to do this **only once**. These changes remain on future Unity exports.
199216

200217
<details>
201-
<summary>:information_source: <b>Android</b></summary>
218+
<summary>ℹ️ <b>Android</b></summary>
202219

203220
1. Setting the Android NDK
204221

@@ -378,10 +395,7 @@ allprojects {
378395

379396

380397
<details>
381-
<summary>:information_source: <b>iOS</b></summary>
382-
383-
> Because of Apple's privacy manifest requirements, you need a minimal Unity version of 2021.3.35 or 2022.3.18 to publish an app.
384-
398+
<summary>ℹ️ <b>iOS</b></summary>
385399

386400
1. Open the *ios/Runner.xcworkspace* (workspace, not the project) file in Xcode, right-click on the Navigator (not on an item), go to **Add Files to "Runner"** and add
387401
the *ios/UnityLibrary/Unity-Iphone.xcodeproj* file.
@@ -451,7 +465,7 @@ allprojects {
451465

452466

453467
<details>
454-
<summary>:information_source: <b>AR Foundation Android</b></summary>
468+
<summary>ℹ️ <b>AR Foundation Android</b></summary>
455469

456470
1. Check the version of the `XR Plugin Management` in the Unity package manager. Versions `4.3.1 - 4.3.3` contain a bug that breaks Android exports.
457471
Make sure to use a version <=`4.2.2` or >=`4.4`.
@@ -480,7 +494,7 @@ allprojects {
480494
</details>
481495
482496
<details>
483-
<summary>:information_source: <b>AR Foundation iOS</b></summary>
497+
<summary>ℹ️ <b>AR Foundation iOS</b></summary>
484498
485499
1. Open the *ios/Runner/Info.plist* and add a camera usage description.
486500
For example:
@@ -494,7 +508,7 @@ For example:
494508
</details>
495509

496510
<details>
497-
<summary>:information_source: <b>Vuforia Android</b></summary>
511+
<summary>ℹ️ <b>Vuforia Android</b></summary>
498512

499513
1. Your export should contain a Vuforia library in the `android/unityLibrary/libs/` folder. Currently named `VuforiaEngine.aar`.
500514

@@ -507,7 +521,7 @@ In case this gets outdated or broken, check the [Vuforia documentation](https://
507521
</details>
508522

509523
<details>
510-
<summary>:information_source: <b>Vuforia iOS</b></summary>
524+
<summary>ℹ️ <b>Vuforia iOS</b></summary>
511525

512526
These steps are based on these [Vuforia docs](https://developer.vuforia.com/library/unity-extension/using-vuforia-engine-unity-library-uaal#ios-specific-steps) and [this comment](https://github.com/juicycleff/flutter-unity-view-widget/issues/314#issuecomment-785302253)
513527

@@ -541,7 +555,7 @@ We recommend using a physical iOS or Android device, as emulator support is limi
541555
Below are the limited options to use an emulator.
542556

543557
<details>
544-
<summary> <b>iOS Simulators</b> </summary>
558+
<summary>ℹ️ <b>iOS Simulators</b> </summary>
545559

546560
The `Target SDK` option in the Unity player settings is important here.
547561
- `Device SDK` exports an ARM build. (Which does **NOT** work on ARM simulators)
@@ -585,7 +599,7 @@ The rest depends on the type of processor in your mac:
585599
</details>
586600

587601
<details>
588-
<summary> <b>Android emulators</b></summary>
602+
<summary>ℹ️ <b>Android emulators</b></summary>
589603

590604
Unity only supports ARM build targets for Android. However most Android emulators are x86 which means they simply won't work.
591605

@@ -625,19 +639,40 @@ If you computer does not have an ARM processor, like most computers running on I
625639

626640
2. Use the method `postMessage` to send a string, using the GameObject name and the name of a behaviour method that should be called.
627641

642+
```dart
643+
// Snippet of postMessage usage in the example project.
644+
_unityWidgetController?.postMessage(
645+
'Cube', // GameObject name
646+
'SetRotationSpeed', // Function name in attached C# script
647+
speed, // Function parameter (string)
648+
);
649+
```
628650
### Unity-Flutter
629651

630652
1. Select the GameObject that should execute the communication and go to **Inspector > Add Component > Unity Message Manager**.
631653

632-
<img src="https://i.stack.imgur.com/1gSOy.png" width="400" />
633-
634654
2. Create a new `MonoBehaviour` subclass and add to the same GameObject as a script.
635655

636656
3. On this new behaviour, call `GetComponent<UnityMessageManager>()` to get a `UnityMessageManager`.
637657

638658
4. Use the method `SendMessageToFlutter` to send a string. Receive this message using the `onUnityMessage` callback of a `UnityWidget`.
639659

640660

661+
```C#
662+
// Send a basic string to Flutter
663+
SendMessageToFlutter("Hello there!");
664+
```
665+
```C#
666+
// If you want to send multiple parameters or objects, use a JSON string.
667+
// This is a random object serialized to JSON using Json.net.
668+
JObject o = JObject.FromObject(new
669+
{
670+
id = 1,
671+
name = "Object 1",
672+
whatever = 12
673+
});
674+
SendMessageToFlutter(o.ToString());
675+
```
641676

642677

643678
## Examples
@@ -663,34 +698,23 @@ class UnityDemoScreen extends StatefulWidget {
663698
}
664699
665700
class _UnityDemoScreenState extends State<UnityDemoScreen> {
666-
static final GlobalKey<ScaffoldState> _scaffoldKey =
667-
GlobalKey<ScaffoldState>();
701+
668702
UnityWidgetController? _unityWidgetController;
669703
670704
@override
671705
Widget build(BuildContext context) {
672706
return Scaffold(
673-
key: _scaffoldKey,
674-
body: SafeArea(
675-
bottom: false,
676-
child: WillPopScope(
677-
onWillPop: () async {
678-
// Pop the category page if Android back button is pressed.
679-
return true;
680-
},
681-
child: Container(
682-
color: Colors.yellow,
683-
child: UnityWidget(
684-
onUnityCreated: onUnityCreated,
685-
),
686-
),
707+
body: Container(
708+
color: Colors.yellow,
709+
child: UnityWidget(
710+
onUnityCreated: onUnityCreated,
687711
),
688712
),
689713
);
690714
}
691715
692716
// Callback that connects the created controller to the unity controller
693-
void onUnityCreated(controller) {
717+
void onUnityCreated(UnityWidgetController controller) {
694718
_unityWidgetController = controller;
695719
}
696720
}
@@ -704,79 +728,71 @@ class _UnityDemoScreenState extends State<UnityDemoScreen> {
704728
import 'package:flutter/material.dart';
705729
import 'package:flutter_unity_widget_2/flutter_unity_widget_2.dart';
706730
707-
void main() => runApp(const MyApp());
731+
void main() {
732+
runApp(
733+
const MaterialApp(
734+
home: UnityDemoScreen(),
735+
),
736+
);
737+
}
708738
709-
class MyApp extends StatefulWidget {
710-
const MyApp({Key? key}) : super(key: key);
739+
class UnityDemoScreen extends StatefulWidget {
740+
const UnityDemoScreen({Key? key}) : super(key: key);
711741
712742
@override
713-
State<MyApp> createState() => _MyAppState();
743+
State<UnityDemoScreen> createState() => _UnityDemoScreenState();
714744
}
715745
716-
class _MyAppState extends State<MyApp> {
717-
static final GlobalKey<ScaffoldState> _scaffoldKey =
718-
GlobalKey<ScaffoldState>();
746+
class _UnityDemoScreenState extends State<UnityDemoScreen> {
719747
UnityWidgetController? _unityWidgetController;
720748
double _sliderValue = 0.0;
721749
722-
@override
723-
void initState() {
724-
super.initState();
725-
}
726-
727750
@override
728751
Widget build(BuildContext context) {
729-
return MaterialApp(
730-
home: Scaffold(
731-
key: _scaffoldKey,
732-
appBar: AppBar(
733-
title: const Text('Unity Flutter Demo'),
734-
),
735-
body: Card(
736-
margin: const EdgeInsets.all(8),
737-
clipBehavior: Clip.antiAlias,
738-
shape: RoundedRectangleBorder(
739-
borderRadius: BorderRadius.circular(20.0),
752+
return Scaffold(
753+
appBar: AppBar(
754+
title: const Text('Unity Flutter Demo'),
755+
),
756+
body: Stack(
757+
children: <Widget>[
758+
UnityWidget(
759+
onUnityCreated: onUnityCreated,
760+
onUnityMessage: onUnityMessage,
761+
onUnitySceneLoaded: onUnitySceneLoaded,
740762
),
741-
child: Stack(
742-
children: <Widget>[
743-
UnityWidget(
744-
onUnityCreated: onUnityCreated,
745-
onUnityMessage: onUnityMessage,
746-
onUnitySceneLoaded: onUnitySceneLoaded,
747-
fullscreen: false,
748-
),
749-
Positioned(
750-
bottom: 20,
751-
left: 20,
752-
right: 20,
753-
// <You need a PointerInterceptor here on web>
754-
child: Card(
755-
elevation: 10,
756-
child: Column(
757-
children: <Widget>[
758-
const Padding(
759-
padding: EdgeInsets.only(top: 20),
760-
child: Text("Rotation speed:"),
761-
),
762-
Slider(
763-
onChanged: (value) {
764-
setState(() {
765-
_sliderValue = value;
766-
});
767-
setRotationSpeed(value.toString());
768-
},
769-
value: _sliderValue,
770-
min: 0,
771-
max: 20,
772-
),
773-
],
774-
),
763+
764+
// Flutter UI Stacked on top of Unity to demo Flutter -> Unity interactions.
765+
// On web this requires a PointerInterceptor widget.
766+
Positioned(
767+
bottom: 0,
768+
// <You need a PointerInterceptor here on web>
769+
child: SafeArea(
770+
child: Card(
771+
elevation: 10,
772+
child: Column(
773+
children: <Widget>[
774+
const Padding(
775+
padding: EdgeInsets.only(top: 20),
776+
child: Text("Rotation speed:"),
777+
),
778+
Slider(
779+
onChanged: (value) {
780+
setState(() {
781+
_sliderValue = value;
782+
});
783+
// Send value to Unity
784+
setRotationSpeed(value.toString());
785+
},
786+
value: _sliderValue,
787+
min: 0.0,
788+
max: 1.0,
789+
),
790+
],
775791
),
776792
),
777-
],
793+
),
778794
),
779-
),
795+
],
780796
),
781797
);
782798
}
@@ -790,16 +806,16 @@ class _MyAppState extends State<MyApp> {
790806
);
791807
}
792808
793-
// Communication from Unity to Flutter
794-
void onUnityMessage(message) {
795-
print('Received message from unity: ${message.toString()}');
796-
}
797-
798809
// Callback that connects the created controller to the unity controller
799-
void onUnityCreated(controller) {
810+
void onUnityCreated(UnityWidgetController controller) {
800811
_unityWidgetController = controller;
801812
}
802813
814+
// Communication from Unity to Flutter
815+
void onUnityMessage(dynamic message) {
816+
print('Received message from unity: ${message.toString()}');
817+
}
818+
803819
// Communication from Unity when new scene is loaded to Flutter
804820
void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
805821
if (sceneInfo != null) {
@@ -809,7 +825,6 @@ class _MyAppState extends State<MyApp> {
809825
}
810826
}
811827
}
812-
813828
```
814829

815830
## Props

analysis_options.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
1-
analyzer:
1+
include: package:flutter_lints/flutter.yaml
2+

0 commit comments

Comments
 (0)