Commit fb3f3ce2 cgx

优化unity

1 个父辈 5d1f390f
......@@ -10,6 +10,7 @@
// APP和KeyWindow
#define DSApplication [UIApplication sharedApplication]
#define DSKeyWindow DSApplication.keyWindow
#define DSDelegateWindow DSApplication.delegate.window
// 系统及APP版本
#define DSSystemVersion ([[[UIDevice currentDevice] systemVersion] floatValue])
......
......@@ -7,10 +7,6 @@
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
/// 三分钟即刻入睡VC(哄睡界面、Unity界面)
@interface ThreeMinuteController : UIViewController
@end
NS_ASSUME_NONNULL_END
......@@ -7,8 +7,10 @@
#import "ThreeMinuteController.h"
#import "AppDelegate.h"
#import <UnityFramework/UnityFramework.h>
@interface ThreeMinuteController ()
@interface ThreeMinuteController () <UnityFrameworkListener>
@property (nonatomic, strong) UnityFramework* ufw;
@end
@implementation ThreeMinuteController
......@@ -18,9 +20,7 @@
self.view.backgroundColor = DSBlack;
// 加载unity
AppDelegate *appDelegate = (AppDelegate *)[UIApplication sharedApplication].delegate;
[appDelegate showUnityView];
[self showUnityView];
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(exitCoaxSleep) name:ExitCoaxSleep object:nil];
}
......@@ -42,4 +42,50 @@
return YES;
}
#pragma mark - Unity
UnityFramework* UnityFrameworkLoad(void) {
NSString* bundlePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Frameworks/UnityFramework.framework"];
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
if ([bundle isLoaded] == false) { [bundle load]; }
UnityFramework *ufw = [bundle.principalClass getInstance];
if (![ufw appController]) { [ufw setExecuteHeader:&_mh_execute_header]; }
return ufw;
}
- (bool)unityIsInitialized {
return [self ufw] && [[self ufw] appController];
}
extern int gArgc;
extern char** gArgv;
- (void)initUnity {
// unity如果初始化了,首先需要卸载unity
if ([self unityIsInitialized]) {
[DSProgressHUD showDetailInfo:@"Unity already initialized,please unload unity first"];
return;
}
[self setUfw:UnityFrameworkLoad()];
[[self ufw] setDataBundleId:"com.unity3d.framework"];
[[self ufw] registerFrameworkListener:self];
[[self ufw] runEmbeddedWithArgc:gArgc argv:gArgv appLaunchOpts:nil];
}
- (void)showUnityView {
[self initUnity];
[self.ufw showUnityWindow];
}
#pragma mark - UnityFrameworkListener
- (void)unityDidUnload:(NSNotification*)notification {
DSLog(@"unityDidUnload");
[[self ufw] unregisterFrameworkListener:self];
[self setUfw: nil];
[DSDelegateWindow makeKeyAndVisible];
}
@end
......@@ -6,16 +6,8 @@
//
#import <UIKit/UIKit.h>
#import <UnityFramework/UnityFramework.h>
@interface AppDelegate : UIResponder <UIApplicationDelegate, UnityFrameworkListener>
@interface AppDelegate : UIResponder <UIApplicationDelegate>
@property (strong, nonatomic) UIWindow * window;
#pragma mark - Unity
@property (nonatomic, strong) NSDictionary * appLaunchOpts;
@property (nonatomic, strong) UnityFramework* ufw;
/// 显示unity
- (void)showUnityView;
@end
......@@ -158,55 +158,4 @@
}
}
#pragma mark - Unity
UnityFramework* UnityFrameworkLoad(void) {
NSString* bundlePath = [[[NSBundle mainBundle] bundlePath] stringByAppendingString:@"/Frameworks/UnityFramework.framework"];
NSBundle* bundle = [NSBundle bundleWithPath:bundlePath];
if ([bundle isLoaded] == false) { [bundle load]; }
UnityFramework *ufw = [bundle.principalClass getInstance];
if (![ufw appController]) { [ufw setExecuteHeader:&_mh_execute_header]; }
return ufw;
}
- (bool)unityIsInitialized {
return [self ufw] && [[self ufw] appController];
}
extern int gArgc;
extern char** gArgv;
- (void)initUnity {
// unity如果初始化了,首先需要卸载unity
if ([self unityIsInitialized]) {
[DSProgressHUD showDetailInfo:@"Unity already initialized,please unload unity first"];
return;
}
[self setUfw:UnityFrameworkLoad()];
[[self ufw] setDataBundleId:"com.unity3d.framework"];
[[self ufw] registerFrameworkListener:self];
[[self ufw] runEmbeddedWithArgc:gArgc argv:gArgv appLaunchOpts:self.appLaunchOpts];
}
- (void)showUnityView {
[self initUnity];
[self.ufw showUnityWindow];
}
#pragma mark - UnityFrameworkListener
- (void)unityDidUnload:(NSNotification*)notification {
DSLog(@"unityDidUnload");
[[self ufw] unregisterFrameworkListener:self];
[self setUfw: nil];
[self.window makeKeyAndVisible];
}
- (void)applicationWillResignActive:(UIApplication *)application { [[[self ufw] appController] applicationWillResignActive: application]; }
- (void)applicationDidEnterBackground:(UIApplication *)application { [[[self ufw] appController] applicationDidEnterBackground: application]; }
- (void)applicationWillEnterForeground:(UIApplication *)application { [[[self ufw] appController] applicationWillEnterForeground: application]; }
- (void)applicationDidBecomeActive:(UIApplication *)application { [[[self ufw] appController] applicationDidBecomeActive: application]; }
- (void)applicationWillTerminate:(UIApplication *)application { [[[self ufw] appController] applicationWillTerminate: application]; }
@end
......@@ -143,10 +143,11 @@ extern bool _unityAppReady;
NSAssert(_rootView != nil, @"_rootView should be inited at this point");
NSAssert(_rootController != nil, @"_rootController should be inited at this point");
[UIView setAnimationsEnabled: NO];
ShowSplashScreen(_window);
#pragma mark - 3、修复首次加载unity页面出现主APP启动页面问题
// [UIView setAnimationsEnabled: NO];
// ShowSplashScreen(_window);
// make window visible only after we have set up initial controller we want to show
[_window makeKeyAndVisible];
// [_window makeKeyAndVisible];
#if UNITY_SUPPORT_ROTATION
// to be able to query orientation from view controller we should actually show it.
......
......@@ -131,6 +131,7 @@ NSInteger _forceInterfaceOrientationMask = 0;
UnitySetPlayerFocus(1);
#pragma mark - 1、解决手机开启静音模式下播放没有声音问题
AVAudioSession* audioSession = [AVAudioSession sharedInstance];
[audioSession setCategory:AVAudioSessionCategoryPlayback error:nil];
[audioSession setActive: YES error: nil];
......@@ -387,6 +388,7 @@ extern "C" void UnityCleanupTrampoline()
_didResignActive = false;
}
#pragma mark - 2、自定义
// 创建原生页面和控件,自己控制唤起Unity时机
- (void)startSelfIOSView
{
......
支持 Markdown 格式
你添加了 0 到此讨论。请谨慎行事。
Finish editing this message first!