Skip to content

Commit 2b1e4d0

Browse files
committed
Merge branch 'experimental/unity_6000' into flutter_unity_widget_2-6000
2 parents d1b3031 + 526cb49 commit 2b1e4d0

27 files changed

+438
-215
lines changed

CHANGELOG.md

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,12 @@
1+
## 6000.1.0
2+
> Includes the same changes as 2022.3.0
3+
* [Web] Switch to `package:web` to support WebAssembly (WASM).
4+
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
5+
* Fix lint warnings to improve static analysis.
6+
* Small ReadMe fixes.
7+
18
## 6000.0.0
2-
* Includes all fixes up to 2022.2.2.
9+
* Includes all fixes up to 2022.2.2.
310

411
**Breaking changes**
512
* [Android] This plugin now requires an export from Unity 6000.0 or newer.
@@ -8,6 +15,14 @@
815
* [Android] [iOS] Exports require unitypackage `fuw-6000.0.x` or newer.
916
* Delete existing export folders like`android/unityLibrary` or `ios/UnityLibrary`when you upgrade your Unity version.
1017

18+
## 2022.3.0 (master branch)
19+
* [Web] Switch to `package:web` to support WebAssembly (WASM).
20+
* Updates minimum supported SDK version to Flutter 3.16/Dart 3.2.
21+
* Fix lint warnings to improve static analysis.
22+
* Small ReadMe fixes.
23+
24+
**Note:**
25+
> This release is unrelated to an old version `2022.3.0-alpha1` of `flutter_unity_widget`.
1126
1227

1328
## 2022.2.2

README.md

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

116116
## Installation
117117

118-
This plugin requires Flutter >= 3.3.0
118+
This plugin requires Flutter >= 3.16.0.
119119

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

144144
## Setup
145145

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

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

158+
### Unity versions for publishing
159+
If you want to publish your app for Android or iOS, you need to satisfy certain Unity version requirements.
160+
161+
**iOS**
162+
Apple's [privacy manifest requirements](https://discussions.unity.com/t/apple-privacy-manifest-updates-for-unity-engine/936052) need a minimal Unity version of:
163+
* 2021.3.35+
164+
* 2022.3.18+
165+
* 6000.0.0+
166+
167+
**Android**
168+
> 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.
169+
170+
This requires [Unity versions](https://discussions.unity.com/t/info-unity-engine-support-for-16-kb-memory-page-sizes-android-15/1589588):
171+
* 2021.3.48+ (Enterprise and Industry only)
172+
* 2022.3.56+
173+
* 6000.0.38+
174+
158175

159176
### Unity project setup
160177
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**.
@@ -223,7 +240,7 @@ After exporting Unity, you will need to make some small changes in your iOS or A
223240
You will likely need to do this **only once**. These changes remain on future Unity exports.
224241

225242
<details>
226-
<summary>:information_source: <b>Android</b></summary>
243+
<summary>ℹ️ <b>Android</b></summary>
227244

228245
1. Setting the Android NDK
229246

@@ -403,10 +420,7 @@ allprojects {
403420

404421

405422
<details>
406-
<summary>:information_source: <b>iOS</b></summary>
407-
408-
> 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.
409-
423+
<summary>ℹ️ <b>iOS</b></summary>
410424

411425
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
412426
the *ios/UnityLibrary/Unity-Iphone.xcodeproj* file.
@@ -476,7 +490,7 @@ allprojects {
476490

477491

478492
<details>
479-
<summary>:information_source: <b>AR Foundation Android</b></summary>
493+
<summary>ℹ️ <b>AR Foundation Android</b></summary>
480494

481495
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.
482496
Make sure to use a version <=`4.2.2` or >=`4.4`.
@@ -505,7 +519,7 @@ allprojects {
505519
</details>
506520
507521
<details>
508-
<summary>:information_source: <b>AR Foundation iOS</b></summary>
522+
<summary>ℹ️ <b>AR Foundation iOS</b></summary>
509523
510524
1. Open the *ios/Runner/Info.plist* and add a camera usage description.
511525
For example:
@@ -519,7 +533,7 @@ For example:
519533
</details>
520534

521535
<details>
522-
<summary>:information_source: <b>Vuforia Android</b></summary>
536+
<summary>ℹ️ <b>Vuforia Android</b></summary>
523537

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

@@ -532,7 +546,7 @@ In case this gets outdated or broken, check the [Vuforia documentation](https://
532546
</details>
533547

534548
<details>
535-
<summary>:information_source: <b>Vuforia iOS</b></summary>
549+
<summary>ℹ️ <b>Vuforia iOS</b></summary>
536550

537551
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)
538552

@@ -566,7 +580,7 @@ We recommend using a physical iOS or Android device, as emulator support is limi
566580
Below are the limited options to use an emulator.
567581

568582
<details>
569-
<summary> <b>iOS Simulators</b> </summary>
583+
<summary>ℹ️ <b>iOS Simulators</b> </summary>
570584

571585
The `Target SDK` option in the Unity player settings is important here.
572586
- `Device SDK` exports an ARM build. (Which does **NOT** work on ARM simulators)
@@ -610,7 +624,7 @@ The rest depends on the type of processor in your mac:
610624
</details>
611625

612626
<details>
613-
<summary> <b>Android emulators</b></summary>
627+
<summary>ℹ️ <b>Android emulators</b></summary>
614628

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

@@ -650,19 +664,40 @@ If you computer does not have an ARM processor, like most computers running on I
650664

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

667+
```dart
668+
// Snippet of postMessage usage in the example project.
669+
_unityWidgetController?.postMessage(
670+
'Cube', // GameObject name
671+
'SetRotationSpeed', // Function name in attached C# script
672+
speed, // Function parameter (string)
673+
);
674+
```
653675
### Unity-Flutter
654676

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

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

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

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

665685

686+
```C#
687+
// Send a basic string to Flutter
688+
SendMessageToFlutter("Hello there!");
689+
```
690+
```C#
691+
// If you want to send multiple parameters or objects, use a JSON string.
692+
// This is a random object serialized to JSON using Json.net.
693+
JObject o = JObject.FromObject(new
694+
{
695+
id = 1,
696+
name = "Object 1",
697+
whatever = 12
698+
});
699+
SendMessageToFlutter(o.ToString());
700+
```
666701

667702

668703
## Examples
@@ -688,34 +723,23 @@ class UnityDemoScreen extends StatefulWidget {
688723
}
689724
690725
class _UnityDemoScreenState extends State<UnityDemoScreen> {
691-
static final GlobalKey<ScaffoldState> _scaffoldKey =
692-
GlobalKey<ScaffoldState>();
726+
693727
UnityWidgetController? _unityWidgetController;
694728
695729
@override
696730
Widget build(BuildContext context) {
697731
return Scaffold(
698-
key: _scaffoldKey,
699-
body: SafeArea(
700-
bottom: false,
701-
child: WillPopScope(
702-
onWillPop: () async {
703-
// Pop the category page if Android back button is pressed.
704-
return true;
705-
},
706-
child: Container(
707-
color: Colors.yellow,
708-
child: UnityWidget(
709-
onUnityCreated: onUnityCreated,
710-
),
711-
),
732+
body: Container(
733+
color: Colors.yellow,
734+
child: UnityWidget(
735+
onUnityCreated: onUnityCreated,
712736
),
713737
),
714738
);
715739
}
716740
717741
// Callback that connects the created controller to the unity controller
718-
void onUnityCreated(controller) {
742+
void onUnityCreated(UnityWidgetController controller) {
719743
_unityWidgetController = controller;
720744
}
721745
}
@@ -729,79 +753,71 @@ class _UnityDemoScreenState extends State<UnityDemoScreen> {
729753
import 'package:flutter/material.dart';
730754
import 'package:flutter_unity_widget_2/flutter_unity_widget_2.dart';
731755
732-
void main() => runApp(const MyApp());
756+
void main() {
757+
runApp(
758+
const MaterialApp(
759+
home: UnityDemoScreen(),
760+
),
761+
);
762+
}
733763
734-
class MyApp extends StatefulWidget {
735-
const MyApp({Key? key}) : super(key: key);
764+
class UnityDemoScreen extends StatefulWidget {
765+
const UnityDemoScreen({Key? key}) : super(key: key);
736766
737767
@override
738-
State<MyApp> createState() => _MyAppState();
768+
State<UnityDemoScreen> createState() => _UnityDemoScreenState();
739769
}
740770
741-
class _MyAppState extends State<MyApp> {
742-
static final GlobalKey<ScaffoldState> _scaffoldKey =
743-
GlobalKey<ScaffoldState>();
771+
class _UnityDemoScreenState extends State<UnityDemoScreen> {
744772
UnityWidgetController? _unityWidgetController;
745773
double _sliderValue = 0.0;
746774
747-
@override
748-
void initState() {
749-
super.initState();
750-
}
751-
752775
@override
753776
Widget build(BuildContext context) {
754-
return MaterialApp(
755-
home: Scaffold(
756-
key: _scaffoldKey,
757-
appBar: AppBar(
758-
title: const Text('Unity Flutter Demo'),
759-
),
760-
body: Card(
761-
margin: const EdgeInsets.all(8),
762-
clipBehavior: Clip.antiAlias,
763-
shape: RoundedRectangleBorder(
764-
borderRadius: BorderRadius.circular(20.0),
777+
return Scaffold(
778+
appBar: AppBar(
779+
title: const Text('Unity Flutter Demo'),
780+
),
781+
body: Stack(
782+
children: <Widget>[
783+
UnityWidget(
784+
onUnityCreated: onUnityCreated,
785+
onUnityMessage: onUnityMessage,
786+
onUnitySceneLoaded: onUnitySceneLoaded,
765787
),
766-
child: Stack(
767-
children: <Widget>[
768-
UnityWidget(
769-
onUnityCreated: onUnityCreated,
770-
onUnityMessage: onUnityMessage,
771-
onUnitySceneLoaded: onUnitySceneLoaded,
772-
fullscreen: false,
773-
),
774-
Positioned(
775-
bottom: 20,
776-
left: 20,
777-
right: 20,
778-
// <You need a PointerInterceptor here on web>
779-
child: Card(
780-
elevation: 10,
781-
child: Column(
782-
children: <Widget>[
783-
const Padding(
784-
padding: EdgeInsets.only(top: 20),
785-
child: Text("Rotation speed:"),
786-
),
787-
Slider(
788-
onChanged: (value) {
789-
setState(() {
790-
_sliderValue = value;
791-
});
792-
setRotationSpeed(value.toString());
793-
},
794-
value: _sliderValue,
795-
min: 0,
796-
max: 20,
797-
),
798-
],
799-
),
788+
789+
// Flutter UI Stacked on top of Unity to demo Flutter -> Unity interactions.
790+
// On web this requires a PointerInterceptor widget.
791+
Positioned(
792+
bottom: 0,
793+
// <You need a PointerInterceptor here on web>
794+
child: SafeArea(
795+
child: Card(
796+
elevation: 10,
797+
child: Column(
798+
children: <Widget>[
799+
const Padding(
800+
padding: EdgeInsets.only(top: 20),
801+
child: Text("Rotation speed:"),
802+
),
803+
Slider(
804+
onChanged: (value) {
805+
setState(() {
806+
_sliderValue = value;
807+
});
808+
// Send value to Unity
809+
setRotationSpeed(value.toString());
810+
},
811+
value: _sliderValue,
812+
min: 0.0,
813+
max: 1.0,
814+
),
815+
],
800816
),
801817
),
802-
],
818+
),
803819
),
804-
),
820+
],
805821
),
806822
);
807823
}
@@ -815,16 +831,16 @@ class _MyAppState extends State<MyApp> {
815831
);
816832
}
817833
818-
// Communication from Unity to Flutter
819-
void onUnityMessage(message) {
820-
print('Received message from unity: ${message.toString()}');
821-
}
822-
823834
// Callback that connects the created controller to the unity controller
824-
void onUnityCreated(controller) {
835+
void onUnityCreated(UnityWidgetController controller) {
825836
_unityWidgetController = controller;
826837
}
827838
839+
// Communication from Unity to Flutter
840+
void onUnityMessage(dynamic message) {
841+
print('Received message from unity: ${message.toString()}');
842+
}
843+
828844
// Communication from Unity when new scene is loaded to Flutter
829845
void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
830846
if (sceneInfo != null) {
@@ -834,7 +850,6 @@ class _MyAppState extends State<MyApp> {
834850
}
835851
}
836852
}
837-
838853
```
839854

840855
## 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)