Skip to content
切换导航条
切换导航条
当前项目
正在载入...
登录
陈高翔
/
DreamSleep-iOS
转到一个项目
切换导航栏
切换导航栏固定状态
项目
群组
代码片段
帮助
项目
活动
版本库
流水线
图表
问题
0
合并请求
0
维基
网络
创建新的问题
作业
提交
问题看板
文件
提交
网络
比较
分支
标签
Commit a0fd194e
由
cgx
编写于
2022-05-20 17:17:37 +0800
浏览文件
选项
浏览文件
标签
下载
电子邮件补丁
差异文件
解决Unity在静音模式下无法播放bug
1 个父辈
28bd1061
显示空白字符变更
内嵌
并排
正在显示
4 个修改的文件
包含
73 行增加
和
17 行删除
DreamSleep/DreamSleep/Class/Start/Root/AppDelegate.h
DreamSleep/DreamSleep/Class/Start/Root/AppDelegate.m
DreamSleep/TapiOS/Classes/UnityAppController.h
DreamSleep/TapiOS/Classes/UnityAppController.mm
DreamSleep/DreamSleep/Class/Start/Root/AppDelegate.h
查看文件 @
a0fd194
...
@@ -14,6 +14,7 @@
...
@@ -14,6 +14,7 @@
#pragma mark - Unity
#pragma mark - Unity
@property
(
nonatomic
,
strong
)
NSDictionary
*
appLaunchOpts
;
@property
(
nonatomic
,
strong
)
NSDictionary
*
appLaunchOpts
;
@property
(
nonatomic
,
strong
)
UnityFramework
*
ufw
;
@property
(
nonatomic
,
strong
)
UnityFramework
*
ufw
;
/// 显示unity
-
(
void
)
showUnityView
;
-
(
void
)
showUnityView
;
@end
@end
...
...
DreamSleep/DreamSleep/Class/Start/Root/AppDelegate.m
查看文件 @
a0fd194
...
@@ -162,13 +162,10 @@
...
@@ -162,13 +162,10 @@
UnityFramework
*
UnityFrameworkLoad
(
void
)
{
UnityFramework
*
UnityFrameworkLoad
(
void
)
{
NSString
*
bundlePath
=
[[[
NSBundle
mainBundle
]
bundlePath
]
stringByAppendingString
:
@"/Frameworks/UnityFramework.framework"
];
NSString
*
bundlePath
=
[[[
NSBundle
mainBundle
]
bundlePath
]
stringByAppendingString
:
@"/Frameworks/UnityFramework.framework"
];
NSBundle
*
bundle
=
[
NSBundle
bundleWithPath
:
bundlePath
];
NSBundle
*
bundle
=
[
NSBundle
bundleWithPath
:
bundlePath
];
if
([
bundle
isLoaded
]
==
false
)
[
bundle
load
];
if
([
bundle
isLoaded
]
==
false
)
{
[
bundle
load
];
}
UnityFramework
*
ufw
=
[
bundle
.
principalClass
getInstance
];
UnityFramework
*
ufw
=
[
bundle
.
principalClass
getInstance
];
if
(
!
[
ufw
appController
])
if
(
!
[
ufw
appController
])
{
[
ufw
setExecuteHeader
:
&
_mh_execute_header
];
}
{
[
ufw
setExecuteHeader
:
&
_mh_execute_header
];
}
return
ufw
;
return
ufw
;
}
}
...
@@ -180,17 +177,16 @@ extern int gArgc;
...
@@ -180,17 +177,16 @@ extern int gArgc;
extern
char
**
gArgv
;
extern
char
**
gArgv
;
-
(
void
)
initUnity
{
-
(
void
)
initUnity
{
if
([
self
unityIsInitialized
])
{
// unity如果初始化了,首先需要卸载unity
[
DSProgressHUD
showDetailInfo
:
@"Unload Unity first"
];
if
([
self
unityIsInitialized
])
{
[
DSProgressHUD
showDetailInfo
:
@"Unity already initialized,please unload unity first"
];
return
;
return
;
}
}
[
self
setUfw
:
UnityFrameworkLoad
()];
[
self
setUfw
:
UnityFrameworkLoad
()];
[[
self
ufw
]
setDataBundleId
:
"com.unity3d.framework"
];
[[
self
ufw
]
setDataBundleId
:
"com.unity3d.framework"
];
[[
self
ufw
]
registerFrameworkListener
:
self
];
[[
self
ufw
]
registerFrameworkListener
:
self
];
[[
self
ufw
]
runEmbeddedWithArgc
:
gArgc
argv
:
gArgv
appLaunchOpts
:
self
.
appLaunchOpts
];
[[
self
ufw
]
runEmbeddedWithArgc
:
gArgc
argv
:
gArgv
appLaunchOpts
:
self
.
appLaunchOpts
];
[[[
self
ufw
]
appController
]
rootView
];
}
}
-
(
void
)
showUnityView
{
-
(
void
)
showUnityView
{
...
@@ -201,15 +197,16 @@ extern char** gArgv;
...
@@ -201,15 +197,16 @@ extern char** gArgv;
#pragma mark - UnityFrameworkListener
#pragma mark - UnityFrameworkListener
-
(
void
)
unityDidUnload
:
(
NSNotification
*
)
notification
{
-
(
void
)
unityDidUnload
:
(
NSNotification
*
)
notification
{
DSLog
(
@"unityDidUnload
ed called
"
);
DSLog
(
@"unityDidUnload"
);
[
self
.
window
makeKeyAndVisible
];
[[
self
ufw
]
unregisterFrameworkListener
:
self
];
[[
self
ufw
]
unregisterFrameworkListener
:
self
];
[
self
setUfw
:
nil
];
[
self
setUfw
:
nil
];
[
self
.
window
makeKeyAndVisible
];
}
}
-
(
void
)
unityDidQuit
:
(
NSNotification
*
)
notification
{
-
(
void
)
applicationWillResignActive
:
(
UIApplication
*
)
application
{
[[[
self
ufw
]
appController
]
applicationWillResignActive
:
application
];
}
DSLog
(
@"========== %s ============"
,
__func__
);
-
(
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
@end
DreamSleep/TapiOS/Classes/UnityAppController.h
查看文件 @
a0fd194
...
@@ -36,6 +36,7 @@ __attribute__ ((visibility("default")))
...
@@ -36,6 +36,7 @@ __attribute__ ((visibility("default")))
id
<
RenderPluginDelegate
>
_renderDelegate
;
id
<
RenderPluginDelegate
>
_renderDelegate
;
}
}
@property
(
strong
,
nonatomic
)
UIViewController
*
vc
;
// override it to add your render plugin delegate
// override it to add your render plugin delegate
-
(
void
)
shouldAttachRenderDelegate
;
-
(
void
)
shouldAttachRenderDelegate
;
...
...
DreamSleep/TapiOS/Classes/UnityAppController.mm
查看文件 @
a0fd194
...
@@ -132,6 +132,7 @@ NSInteger _forceInterfaceOrientationMask = 0;
...
@@ -132,6 +132,7 @@ NSInteger _forceInterfaceOrientationMask = 0;
UnitySetPlayerFocus
(
1
);
UnitySetPlayerFocus
(
1
);
AVAudioSession
*
audioSession
=
[
AVAudioSession
sharedInstance
];
AVAudioSession
*
audioSession
=
[
AVAudioSession
sharedInstance
];
[
audioSession
setCategory
:
AVAudioSessionCategoryPlayback
error
:
nil
];
[
audioSession
setActive
:
YES
error
:
nil
];
[
audioSession
setActive
:
YES
error
:
nil
];
[
audioSession
addObserver
:
self
forKeyPath
:
@"outputVolume"
options
:
0
context
:
nil
];
[
audioSession
addObserver
:
self
forKeyPath
:
@"outputVolume"
options
:
0
context
:
nil
];
UnityUpdateMuteState
([
audioSession
outputVolume
]
<
0
.
01
f
?
1
:
0
);
UnityUpdateMuteState
([
audioSession
outputVolume
]
<
0
.
01
f
?
1
:
0
);
...
@@ -378,11 +379,67 @@ extern "C" void UnityCleanupTrampoline()
...
@@ -378,11 +379,67 @@ extern "C" void UnityCleanupTrampoline()
{
{
_startUnityScheduled
=
true
;
_startUnityScheduled
=
true
;
[
self
performSelector
:
@selector
(
startUnity
:)
withObject
:
application
afterDelay
:
0
];
[
self
performSelector
:
@selector
(
startUnity
:)
withObject
:
application
afterDelay
:
0
];
// 替换startUnity:为startSelfIOSView
// [self performSelector: @selector(startSelfIOSView) withObject: application afterDelay: 0];
}
}
_didResignActive
=
false
;
_didResignActive
=
false
;
}
}
// 创建原生页面和控件,自己控制唤起Unity时机
-
(
void
)
startSelfIOSView
{
UIViewController
*
vc
=
[[
UIViewController
alloc
]
init
];
vc
.
view
.
frame
=
[
UIScreen
mainScreen
].
bounds
;
vc
.
view
.
backgroundColor
=
[
UIColor
blackColor
];
UIButton
*
btn
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectMake
(
100
,
100
,
200
,
50
)];
btn
.
backgroundColor
=
[
UIColor
blueColor
];
[
btn
setTitle
:
@"跳转到Unity界面"
forState
:
UIControlStateNormal
];
// 按钮被点击时唤起Unity项目
[
btn
addTarget
:
self
action
:
@selector
(
startUnity
:
)
forControlEvents
:
UIControlEventTouchUpInside
];
[
vc
.
view
addSubview
:
btn
];
self
.
vc
=
vc
;
[
_window
addSubview
:
vc
.
view
];
[
self
addGLViewButton
];
}
// 在UnityGetGLView上添加按钮
-
(
void
)
addGLViewButton
{
// 添加右旋按钮
UIButton
*
rightBtn
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectMake
(
10
,
150
,
100
,
30
)];
rightBtn
.
backgroundColor
=
[
UIColor
whiteColor
];
[
rightBtn
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateNormal
];
[
rightBtn
setTitle
:
@"向右旋转"
forState
:
UIControlStateNormal
];
[
rightBtn
addTarget
:
self
action
:
@selector
(
turnRight
)
forControlEvents
:
UIControlEventTouchUpInside
];
// 添加左旋按钮
UIButton
*
leftBtn
=
[[
UIButton
alloc
]
initWithFrame
:
CGRectMake
(
10
,
200
,
100
,
30
)];
leftBtn
.
backgroundColor
=
[
UIColor
whiteColor
];
[
leftBtn
setTitleColor
:[
UIColor
blackColor
]
forState
:
UIControlStateNormal
];
[
leftBtn
setTitle
:
@"向左旋转"
forState
:
UIControlStateNormal
];
[
leftBtn
addTarget
:
self
action
:
@selector
(
turnLeft
)
forControlEvents
:
UIControlEventTouchUpInside
];
// 在Unity界面添加按钮
[
UnityGetGLViewController
().
view
addSubview
:
rightBtn
];
[
UnityGetGLViewController
().
view
addSubview
:
leftBtn
];
}
// 左旋按钮响应事件
-
(
void
)
turnRight
{
const
char
*
str
=
[[
NSString
stringWithFormat
:
@"向右"
]
UTF8String
];
UnitySendMessage
(
"_bridgeManager"
,
"turnRight"
,
str
);
}
// 右旋按钮响应事件
-
(
void
)
turnLeft
{
const
char
*
str
=
[[
NSString
stringWithFormat
:
@"向左"
]
UTF8String
];
UnitySendMessage
(
"_bridgeManager"
,
"turnLeft"
,
str
);
}
-
(
void
)
updateUnityAudioOutput
-
(
void
)
updateUnityAudioOutput
{
{
UnityUpdateAudioOutputState
();
UnityUpdateAudioOutputState
();
...
...
编写
预览
支持
Markdown
格式
附加文件
你添加了
0
人
到此讨论。请谨慎行事。
Finish editing this message first!
Cancel
请
注册
或
登录
后发表评论