This repository has been archived on 2020-08-22. You can view files and clone it, but cannot push or open issues or pull requests.
flutter-unity-view-widget/ios/Classes/FlutterUnityWidgetPlugin.m

85 lines
2.4 KiB
Mathematica
Raw Normal View History

//
// FlutterUnityWidgetPlugin.m
// FlutterUnityWidgetPlugin
//
// Created by Kris Pypen on 8/1/19.
//
2019-03-09 10:47:09 -05:00
#import "FlutterUnityWidgetPlugin.h"
#import "UnityUtils.h"
#import "FlutterUnityView.h"
#include <UnityFramework/UnityFramework.h>
2019-03-09 10:47:09 -05:00
@implementation FlutterUnityWidgetPlugin
2019-03-26 17:06:17 -04:00
+ (void)registerWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
FUViewFactory* fuviewFactory = [[FUViewFactory alloc] initWithRegistrar:registrar];
[registrar registerViewFactory:fuviewFactory withId:@"unity_view"];
2019-03-26 17:06:17 -04:00
}
@end
2019-03-26 17:06:17 -04:00
@implementation FUViewFactory {
NSObject<FlutterPluginRegistrar>* _registrar;
}
- (instancetype)initWithRegistrar:(NSObject<FlutterPluginRegistrar>*)registrar {
self = [super init];
if (self) {
_registrar = registrar;
}
return self;
}
- (NSObject<FlutterMessageCodec>*)createArgsCodec {
return [FlutterStandardMessageCodec sharedInstance];
}
2019-03-26 17:06:17 -04:00
- (NSObject<FlutterPlatformView>*)createWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args {
FUController* controller = [[FUController alloc] initWithFrame:frame
viewIdentifier:viewId
arguments:args
binaryMessenger:_registrar];
return controller;
}
2019-03-26 17:06:17 -04:00
@end
@implementation FUController {
FlutterUnityView* _uView;
int64_t _viewId;
FlutterMethodChannel* _channel;
}
- (instancetype)initWithFrame:(CGRect)frame
viewIdentifier:(int64_t)viewId
arguments:(id _Nullable)args
binaryMessenger:(NSObject<FlutterBinaryMessenger>*)messenger {
if ([super init]) {
_viewId = viewId;
NSString* channelName = [NSString stringWithFormat:@"unity_view_%lld", viewId];
_channel = [FlutterMethodChannel methodChannelWithName:channelName binaryMessenger:messenger];
}
return self;
}
- (UIView*)view {
_uView = [[FlutterUnityView alloc] init];
if ([UnityUtils isUnityReady]) {
[_uView setUnityView: (UIView*)[GetAppController() unityView]];
} else {
[UnityUtils createPlayer:^{
[_uView setUnityView: (UIView*)[GetAppController() unityView]];
}];
}
return _uView;
2019-03-09 10:47:09 -05:00
}
2019-03-09 10:47:09 -05:00
@end