Skip to content

Commit 526cb49

Browse files
committed
Merge branch 'master' into experimental/unity_6000
2 parents e10960b + f681ba4 commit 526cb49

27 files changed

+437
-214
lines changed

CHANGELOG.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
## 6000.1.0 (experimental/unity_6000 branch)
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 (experimental/unity_6000 branch)
29
* Includes all fixes up to 2022.2.2.
310

@@ -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`, which was based on the `feat/global_unity_controller` git branch.
1126
1227
## 2022.2.2 (master branch)
1328
* [Android] Fix touch detection when using Unity's New Input System. [#938](https://github.com/juicycleff/flutter-unity-view-widget/pull/938)

README.md

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

3535
## Installation
3636

37-
This plugin requires Flutter >= 3.3.0
37+
This plugin requires Flutter >= 3.16.0.
3838

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

6363
## Setup
6464

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

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

77+
### Unity versions for publishing
78+
If you want to publish your app for Android or iOS, you need to satisfy certain Unity version requirements.
79+
80+
**iOS**
81+
Apple's [privacy manifest requirements](https://discussions.unity.com/t/apple-privacy-manifest-updates-for-unity-engine/936052) need a minimal Unity version of:
82+
* 2021.3.35+
83+
* 2022.3.18+
84+
* 6000.0.0+
85+
86+
**Android**
87+
> 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.
88+
89+
This requires [Unity versions](https://discussions.unity.com/t/info-unity-engine-support-for-16-kb-memory-page-sizes-android-15/1589588):
90+
* 2021.3.48+ (Enterprise and Industry only)
91+
* 2022.3.56+
92+
* 6000.0.38+
93+
7794

7895
### Unity project setup
7996
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**.
@@ -142,7 +159,7 @@ After exporting Unity, you will need to make some small changes in your iOS or A
142159
You will likely need to do this **only once**. These changes remain on future Unity exports.
143160

144161
<details>
145-
<summary>:information_source: <b>Android</b></summary>
162+
<summary>ℹ️ <b>Android</b></summary>
146163

147164
1. Setting the Android NDK
148165

@@ -323,10 +340,7 @@ allprojects {
323340

324341

325342
<details>
326-
<summary>:information_source: <b>iOS</b></summary>
327-
328-
> 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.
329-
343+
<summary>ℹ️ <b>iOS</b></summary>
330344

331345
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
332346
the *ios/UnityLibrary/Unity-Iphone.xcodeproj* file.
@@ -396,7 +410,7 @@ allprojects {
396410

397411

398412
<details>
399-
<summary>:information_source: <b>AR Foundation Android</b></summary>
413+
<summary>ℹ️ <b>AR Foundation Android</b></summary>
400414

401415
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.
402416
Make sure to use a version <=`4.2.2` or >=`4.4`.
@@ -425,7 +439,7 @@ allprojects {
425439
</details>
426440
427441
<details>
428-
<summary>:information_source: <b>AR Foundation iOS</b></summary>
442+
<summary>ℹ️ <b>AR Foundation iOS</b></summary>
429443
430444
1. Open the *ios/Runner/Info.plist* and add a camera usage description.
431445
For example:
@@ -439,7 +453,7 @@ For example:
439453
</details>
440454

441455
<details>
442-
<summary>:information_source: <b>Vuforia Android</b></summary>
456+
<summary>ℹ️ <b>Vuforia Android</b></summary>
443457

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

@@ -452,7 +466,7 @@ In case this gets outdated or broken, check the [Vuforia documentation](https://
452466
</details>
453467

454468
<details>
455-
<summary>:information_source: <b>Vuforia iOS</b></summary>
469+
<summary>ℹ️ <b>Vuforia iOS</b></summary>
456470

457471
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)
458472

@@ -486,7 +500,7 @@ We recommend using a physical iOS or Android device, as emulator support is limi
486500
Below are the limited options to use an emulator.
487501

488502
<details>
489-
<summary> <b>iOS Simulators</b> </summary>
503+
<summary>ℹ️ <b>iOS Simulators</b> </summary>
490504

491505
The `Target SDK` option in the Unity player settings is important here.
492506
- `Device SDK` exports an ARM build. (Which does **NOT** work on ARM simulators)
@@ -530,7 +544,7 @@ The rest depends on the type of processor in your mac:
530544
</details>
531545

532546
<details>
533-
<summary> <b>Android emulators</b></summary>
547+
<summary>ℹ️ <b>Android emulators</b></summary>
534548

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

@@ -570,19 +584,40 @@ If you computer does not have an ARM processor, like most computers running on I
570584

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

587+
```dart
588+
// Snippet of postMessage usage in the example project.
589+
_unityWidgetController?.postMessage(
590+
'Cube', // GameObject name
591+
'SetRotationSpeed', // Function name in attached C# script
592+
speed, // Function parameter (string)
593+
);
594+
```
573595
### Unity-Flutter
574596

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

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

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

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

585605

606+
```C#
607+
// Send a basic string to Flutter
608+
SendMessageToFlutter("Hello there!");
609+
```
610+
```C#
611+
// If you want to send multiple parameters or objects, use a JSON string.
612+
// This is a random object serialized to JSON using Json.net.
613+
JObject o = JObject.FromObject(new
614+
{
615+
id = 1,
616+
name = "Object 1",
617+
whatever = 12
618+
});
619+
SendMessageToFlutter(o.ToString());
620+
```
586621

587622

588623
## Examples
@@ -608,34 +643,23 @@ class UnityDemoScreen extends StatefulWidget {
608643
}
609644
610645
class _UnityDemoScreenState extends State<UnityDemoScreen> {
611-
static final GlobalKey<ScaffoldState> _scaffoldKey =
612-
GlobalKey<ScaffoldState>();
646+
613647
UnityWidgetController? _unityWidgetController;
614648
615649
@override
616650
Widget build(BuildContext context) {
617651
return Scaffold(
618-
key: _scaffoldKey,
619-
body: SafeArea(
620-
bottom: false,
621-
child: WillPopScope(
622-
onWillPop: () async {
623-
// Pop the category page if Android back button is pressed.
624-
return true;
625-
},
626-
child: Container(
627-
color: Colors.yellow,
628-
child: UnityWidget(
629-
onUnityCreated: onUnityCreated,
630-
),
631-
),
652+
body: Container(
653+
color: Colors.yellow,
654+
child: UnityWidget(
655+
onUnityCreated: onUnityCreated,
632656
),
633657
),
634658
);
635659
}
636660
637661
// Callback that connects the created controller to the unity controller
638-
void onUnityCreated(controller) {
662+
void onUnityCreated(UnityWidgetController controller) {
639663
_unityWidgetController = controller;
640664
}
641665
}
@@ -649,79 +673,71 @@ class _UnityDemoScreenState extends State<UnityDemoScreen> {
649673
import 'package:flutter/material.dart';
650674
import 'package:flutter_unity_widget/flutter_unity_widget.dart';
651675
652-
void main() => runApp(const MyApp());
676+
void main() {
677+
runApp(
678+
const MaterialApp(
679+
home: UnityDemoScreen(),
680+
),
681+
);
682+
}
653683
654-
class MyApp extends StatefulWidget {
655-
const MyApp({Key? key}) : super(key: key);
684+
class UnityDemoScreen extends StatefulWidget {
685+
const UnityDemoScreen({Key? key}) : super(key: key);
656686
657687
@override
658-
State<MyApp> createState() => _MyAppState();
688+
State<UnityDemoScreen> createState() => _UnityDemoScreenState();
659689
}
660690
661-
class _MyAppState extends State<MyApp> {
662-
static final GlobalKey<ScaffoldState> _scaffoldKey =
663-
GlobalKey<ScaffoldState>();
691+
class _UnityDemoScreenState extends State<UnityDemoScreen> {
664692
UnityWidgetController? _unityWidgetController;
665693
double _sliderValue = 0.0;
666694
667-
@override
668-
void initState() {
669-
super.initState();
670-
}
671-
672695
@override
673696
Widget build(BuildContext context) {
674-
return MaterialApp(
675-
home: Scaffold(
676-
key: _scaffoldKey,
677-
appBar: AppBar(
678-
title: const Text('Unity Flutter Demo'),
679-
),
680-
body: Card(
681-
margin: const EdgeInsets.all(8),
682-
clipBehavior: Clip.antiAlias,
683-
shape: RoundedRectangleBorder(
684-
borderRadius: BorderRadius.circular(20.0),
697+
return Scaffold(
698+
appBar: AppBar(
699+
title: const Text('Unity Flutter Demo'),
700+
),
701+
body: Stack(
702+
children: <Widget>[
703+
UnityWidget(
704+
onUnityCreated: onUnityCreated,
705+
onUnityMessage: onUnityMessage,
706+
onUnitySceneLoaded: onUnitySceneLoaded,
685707
),
686-
child: Stack(
687-
children: <Widget>[
688-
UnityWidget(
689-
onUnityCreated: onUnityCreated,
690-
onUnityMessage: onUnityMessage,
691-
onUnitySceneLoaded: onUnitySceneLoaded,
692-
fullscreen: false,
693-
),
694-
Positioned(
695-
bottom: 20,
696-
left: 20,
697-
right: 20,
698-
// <You need a PointerInterceptor here on web>
699-
child: Card(
700-
elevation: 10,
701-
child: Column(
702-
children: <Widget>[
703-
const Padding(
704-
padding: EdgeInsets.only(top: 20),
705-
child: Text("Rotation speed:"),
706-
),
707-
Slider(
708-
onChanged: (value) {
709-
setState(() {
710-
_sliderValue = value;
711-
});
712-
setRotationSpeed(value.toString());
713-
},
714-
value: _sliderValue,
715-
min: 0,
716-
max: 20,
717-
),
718-
],
719-
),
708+
709+
// Flutter UI Stacked on top of Unity to demo Flutter -> Unity interactions.
710+
// On web this requires a PointerInterceptor widget.
711+
Positioned(
712+
bottom: 0,
713+
// <You need a PointerInterceptor here on web>
714+
child: SafeArea(
715+
child: Card(
716+
elevation: 10,
717+
child: Column(
718+
children: <Widget>[
719+
const Padding(
720+
padding: EdgeInsets.only(top: 20),
721+
child: Text("Rotation speed:"),
722+
),
723+
Slider(
724+
onChanged: (value) {
725+
setState(() {
726+
_sliderValue = value;
727+
});
728+
// Send value to Unity
729+
setRotationSpeed(value.toString());
730+
},
731+
value: _sliderValue,
732+
min: 0.0,
733+
max: 1.0,
734+
),
735+
],
720736
),
721737
),
722-
],
738+
),
723739
),
724-
),
740+
],
725741
),
726742
);
727743
}
@@ -735,16 +751,16 @@ class _MyAppState extends State<MyApp> {
735751
);
736752
}
737753
738-
// Communication from Unity to Flutter
739-
void onUnityMessage(message) {
740-
print('Received message from unity: ${message.toString()}');
741-
}
742-
743754
// Callback that connects the created controller to the unity controller
744-
void onUnityCreated(controller) {
755+
void onUnityCreated(UnityWidgetController controller) {
745756
_unityWidgetController = controller;
746757
}
747758
759+
// Communication from Unity to Flutter
760+
void onUnityMessage(dynamic message) {
761+
print('Received message from unity: ${message.toString()}');
762+
}
763+
748764
// Communication from Unity when new scene is loaded to Flutter
749765
void onUnitySceneLoaded(SceneLoaded? sceneInfo) {
750766
if (sceneInfo != null) {
@@ -754,7 +770,6 @@ class _MyAppState extends State<MyApp> {
754770
}
755771
}
756772
}
757-
758773
```
759774

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