Fixed issue with unity onMessage listener on unity 2019.3.5
This commit is contained in:
parent
81efbfaf2d
commit
3ff64bc60b
|
@ -10,7 +10,7 @@
|
|||
|
||||
[![Gitter](https://badges.gitter.im/flutter-unity/community.svg)](https://gitter.im/flutter-unity/community?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge)
|
||||
|
||||
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.
|
||||
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: Ihave updated the example for Unity 2019.3.5 an there are some new changes
|
||||
|
||||
## Installation
|
||||
First depend on the library by adding this to your packages `pubspec.yaml`:
|
||||
|
@ -184,6 +184,8 @@ Copy this folder [`JsonDotNet`](https://github.com/snowballdigital/flutter-unity
|
|||
|
||||
Copy [`link.xml`](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/link.xml) to your unity project.
|
||||
|
||||
Copy this folder [`Plugins`](https://github.com/snowballdigital/flutter-unity-view-widget/tree/master/scripts/Plugins) to your unity project.
|
||||
|
||||
<br />
|
||||
|
||||
### Vuforia
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3b653c103f6d2c429c18c8de0d7bce4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,25 @@
|
|||
package com.company.product;
|
||||
import android.os.Bundle;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.unity3d.player.UnityPlayerActivity;
|
||||
|
||||
public abstract class OverrideUnityActivity extends UnityPlayerActivity
|
||||
{
|
||||
public static OverrideUnityActivity instance = null;
|
||||
|
||||
abstract protected void showMainActivity(String setToColor);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
instance = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ee49a075bcb5d54ea2fbe65de86b5b6
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 1
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a56fe9d7dd2434df182894be0b65147e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
// [!] important set UnityFramework in Target Membership for this file
|
||||
// [!] and set Public header visibility
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// NativeCallsProtocol defines protocol with methods you want to be called from managed
|
||||
@protocol NativeCallsProtocol
|
||||
@required
|
||||
- (void) showHostMainWindow:(NSString*)color;
|
||||
// other methods
|
||||
@end
|
||||
|
||||
__attribute__ ((visibility("default")))
|
||||
@interface FrameworkLibAPI : NSObject
|
||||
// call it any time after UnityFrameworkLoad to set object implementing NativeCallsProtocol methods
|
||||
+(void) registerAPIforNativeCalls:(id<NativeCallsProtocol>) aApi;
|
||||
|
||||
@end
|
||||
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf0b26cbc743a4f9584797ec726f0414
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 1
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 0
|
||||
Exclude tvOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "NativeCallProxy.h"
|
||||
|
||||
|
||||
@implementation FrameworkLibAPI
|
||||
|
||||
id<NativeCallsProtocol> api = NULL;
|
||||
+(void) registerAPIforNativeCalls:(id<NativeCallsProtocol>) aApi
|
||||
{
|
||||
api = aApi;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
extern "C" {
|
||||
void showHostMainWindow(const char* color) { return [api showHostMainWindow:[NSString stringWithUTF8String:color]]; }
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd57ecaa04fd244eaaeee41727d10169
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 1
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 0
|
||||
Exclude tvOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -59,12 +59,20 @@ public class UnityMessage
|
|||
public Action<object> callBack;
|
||||
}
|
||||
|
||||
#if UNITY_IOS || UNITY_TVOS
|
||||
public class NativeAPI
|
||||
{
|
||||
[DllImport("__Internal")]
|
||||
public static extern void onUnityMessage(string message);
|
||||
}
|
||||
#endif
|
||||
|
||||
public class UnityMessageManager : MonoBehaviour
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
/* #if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
private static extern void onUnityMessage(string message);
|
||||
#endif
|
||||
#endif */
|
||||
|
||||
public const string MessagePrefix = "@UnityMessage@";
|
||||
|
||||
|
@ -99,20 +107,20 @@ public class UnityMessageManager : MonoBehaviour
|
|||
|
||||
public void SendMessageToFlutter(string message)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
#if UNITY_ANDROID
|
||||
try
|
||||
{
|
||||
using (AndroidJavaClass jc = new AndroidJavaClass("com.rexraphael.flutterunitywidget.UnityUtils"))
|
||||
{
|
||||
jc.CallStatic("onUnityMessage", message);
|
||||
AndroidJavaClass jc = new AndroidJavaClass("com.rexraphael.flutterunitywidget.UnityUtils");
|
||||
jc.Call("onUnityMessage", message);
|
||||
}
|
||||
}
|
||||
else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
catch (Exception e)
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
onUnityMessage(message);
|
||||
print(e.Message);
|
||||
}
|
||||
#elif UNITY_IOS && !UNITY_EDITOR
|
||||
NativeAPI.onUnityMessage(message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMessageToFlutter(UnityMessage message)
|
||||
{
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: c3b653c103f6d2c429c18c8de0d7bce4
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,25 @@
|
|||
package scripts.Plugins.Android;
|
||||
import android.os.Bundle;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import com.unity3d.player.UnityPlayerActivity;
|
||||
|
||||
public abstract class OverrideUnityActivity extends UnityPlayerActivity
|
||||
{
|
||||
public static OverrideUnityActivity instance = null;
|
||||
|
||||
abstract protected void showMainActivity(String setToColor);
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState)
|
||||
{
|
||||
super.onCreate(savedInstanceState);
|
||||
instance = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
instance = null;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,80 @@
|
|||
fileFormatVersion: 2
|
||||
guid: 8ee49a075bcb5d54ea2fbe65de86b5b6
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 1
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 0
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 1
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,8 @@
|
|||
fileFormatVersion: 2
|
||||
guid: a56fe9d7dd2434df182894be0b65147e
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,20 @@
|
|||
// [!] important set UnityFramework in Target Membership for this file
|
||||
// [!] and set Public header visibility
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
// NativeCallsProtocol defines protocol with methods you want to be called from managed
|
||||
@protocol NativeCallsProtocol
|
||||
@required
|
||||
- (void) showHostMainWindow:(NSString*)color;
|
||||
// other methods
|
||||
@end
|
||||
|
||||
__attribute__ ((visibility("default")))
|
||||
@interface FrameworkLibAPI : NSObject
|
||||
// call it any time after UnityFrameworkLoad to set object implementing NativeCallsProtocol methods
|
||||
+(void) registerAPIforNativeCalls:(id<NativeCallsProtocol>) aApi;
|
||||
|
||||
@end
|
||||
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
fileFormatVersion: 2
|
||||
guid: bf0b26cbc743a4f9584797ec726f0414
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 1
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 0
|
||||
Exclude tvOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -0,0 +1,19 @@
|
|||
#import <Foundation/Foundation.h>
|
||||
#import "NativeCallProxy.h"
|
||||
|
||||
|
||||
@implementation FrameworkLibAPI
|
||||
|
||||
id<NativeCallsProtocol> api = NULL;
|
||||
+(void) registerAPIforNativeCalls:(id<NativeCallsProtocol>) aApi
|
||||
{
|
||||
api = aApi;
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
extern "C" {
|
||||
void showHostMainWindow(const char* color) { return [api showHostMainWindow:[NSString stringWithUTF8String:color]]; }
|
||||
}
|
||||
|
|
@ -0,0 +1,86 @@
|
|||
fileFormatVersion: 2
|
||||
guid: fd57ecaa04fd244eaaeee41727d10169
|
||||
PluginImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
iconMap: {}
|
||||
executionOrder: {}
|
||||
defineConstraints: []
|
||||
isPreloaded: 1
|
||||
isOverridable: 0
|
||||
isExplicitlyReferenced: 0
|
||||
validateReferences: 1
|
||||
platformData:
|
||||
- first:
|
||||
: Any
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
Exclude Android: 1
|
||||
Exclude Editor: 1
|
||||
Exclude Linux64: 1
|
||||
Exclude OSXUniversal: 1
|
||||
Exclude Win: 1
|
||||
Exclude Win64: 1
|
||||
Exclude iOS: 0
|
||||
Exclude tvOS: 0
|
||||
- first:
|
||||
Android: Android
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: ARMv7
|
||||
- first:
|
||||
Any:
|
||||
second:
|
||||
enabled: 0
|
||||
settings: {}
|
||||
- first:
|
||||
Editor: Editor
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: AnyCPU
|
||||
DefaultValueInitialized: true
|
||||
OS: AnyOS
|
||||
- first:
|
||||
Standalone: Linux64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: OSXUniversal
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
Standalone: Win
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86
|
||||
- first:
|
||||
Standalone: Win64
|
||||
second:
|
||||
enabled: 0
|
||||
settings:
|
||||
CPU: x86_64
|
||||
- first:
|
||||
iPhone: iOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings:
|
||||
AddToEmbeddedBinaries: false
|
||||
CPU: AnyCPU
|
||||
CompileFlags:
|
||||
FrameworkDependencies:
|
||||
- first:
|
||||
tvOS: tvOS
|
||||
second:
|
||||
enabled: 1
|
||||
settings: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
|
@ -59,12 +59,20 @@ public class UnityMessage
|
|||
public Action<object> callBack;
|
||||
}
|
||||
|
||||
#if UNITY_IOS || UNITY_TVOS
|
||||
public class NativeAPI
|
||||
{
|
||||
[DllImport("__Internal")]
|
||||
public static extern void onUnityMessage(string message);
|
||||
}
|
||||
#endif
|
||||
|
||||
public class UnityMessageManager : MonoBehaviour
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
/* #if UNITY_IOS && !UNITY_EDITOR
|
||||
[DllImport("__Internal")]
|
||||
private static extern void onUnityMessage(string message);
|
||||
#endif
|
||||
#endif */
|
||||
|
||||
public const string MessagePrefix = "@UnityMessage@";
|
||||
|
||||
|
@ -99,20 +107,20 @@ public class UnityMessageManager : MonoBehaviour
|
|||
|
||||
public void SendMessageToFlutter(string message)
|
||||
{
|
||||
if (Application.platform == RuntimePlatform.Android)
|
||||
#if UNITY_ANDROID
|
||||
try
|
||||
{
|
||||
using (AndroidJavaClass jc = new AndroidJavaClass("com.rexraphael.flutterunitywidget.UnityUtils"))
|
||||
{
|
||||
jc.CallStatic("onUnityMessage", message);
|
||||
AndroidJavaClass jc = new AndroidJavaClass("com.rexraphael.flutterunitywidget.UnityUtils");
|
||||
jc.Call("onUnityMessage", message);
|
||||
}
|
||||
}
|
||||
else if (Application.platform == RuntimePlatform.IPhonePlayer)
|
||||
catch (Exception e)
|
||||
{
|
||||
#if UNITY_IOS && !UNITY_EDITOR
|
||||
onUnityMessage(message);
|
||||
print(e.Message);
|
||||
}
|
||||
#elif UNITY_IOS && !UNITY_EDITOR
|
||||
NativeAPI.onUnityMessage(message);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
public void SendMessageToFlutter(UnityMessage message)
|
||||
{
|
||||
|
|
Reference in New Issue