iOS 设备的大多数功能都通过 Input 和 Handheld 类公开。跨平台项目通过定义 UNITY_IPHONE 按条件编译 iOS 特定的 C# 代码。
您可以访问设备特有的许多属性。请参阅以下脚本参考:
破解应用程序的一种常见方法是移除 AppStore DRM 保护,然后进行免费重新分发。Unity 附带反盗版检查功能,用于查明应用程序在提交到 AppStore 之后是否被篡改。
可以使用 Application.genuine 属性检查应用程序是否为正版(未被破解)。如果该属性返回 false
,则可警告用户他们正在使用经过破解的应用程序,或者可以禁用该应用程序的某些功能。
注意:使用 Application.genuineCheckAvailable 以及 Application.genuine 可验证应用程序完整性。访问 Application.genuine 属性是一项资源密集型操作,不应在帧更新期间或运行其他时间迫切的代码时执行该操作。
可通过调用 Handheld.Vibrate 来触发振动。不含振动硬件的设备将忽略此调用。
移动操作系统具有内置活动指示器;可在慢速操作期间使用这些指示器。有关示例,请参阅 Handheld.StartActivityIndicator 文档。
可在 iOS 和 Android 设备上控制应用程序的屏幕方向。通过检测方向变化或强制使用特定方向,可以创建一些取决于用户如何握持设备的应用程序行为。
要获取设备方向,请访问 Screen.orientation 属性。允许的方向如下:
方向 | 行为 |
---|---|
Portrait | 设备处于纵向模式,直立握持设备,主屏幕按钮位于底部。 |
PortraitUpsideDown | 设备处于纵向模式,但是上下颠倒,直立握持设备,主屏幕按钮位于顶部。 |
LandscapeLeft | 设备处于横向模式,直立握持设备,主屏幕按钮位于右侧。 |
LandscapeRight | 设备处于横向模式,直立握持设备,主屏幕按钮位于左侧。 |
将 Screen.orientation 设置为上述方向之一,或使用 ScreenOrientation.AutoRotation 来控制屏幕方向。启用自动旋转后,仍可根据具体情况禁用某个方向。
有关更多信息,请参阅以下 API 文档:
不同的设备世代具有不同的性能并支持不同的功能。可使用 iOS.DeviceGeneration 属性来查询设备的世代。
在某些显示屏上,屏幕上的某些区域可能由于其他硬件占用该空间而被遮挡或无法正常工作。使用 Screen.cutouts 可以返回每个凹口周围的包围盒列表。
iOS 设备不提供原生 API 来获取显示屏凹口信息,因此要在 Xcode 项目中针对每个可用的 iOS 设备为凹口进行硬编码。可以在 Unity Xcode 项目 ReportSafeAreaChangeForView
函数(位于 UnityView.mm
文件内)中修改现有数据或添加其他设备。
可以使用 ReplayKit 录制游戏的音频和视频,以及从设备的麦克风和摄像头捕获的音频和视频评论。
Did you find this page useful? Please give it a rating:
Thanks for rating this page!
What kind of problem would you like to report?
Thanks for letting us know! This page has been marked for review based on your feedback.
If you have time, you can provide more information to help us fix the problem faster.
Provide more information
You've told us this page needs code samples. If you'd like to help us further, you could provide a code sample, or tell us about what kind of code sample you'd like to see:
You've told us there are code samples on this page which don't work. If you know how to fix it, or have something better we could use instead, please let us know:
You've told us there is information missing from this page. Please tell us more about what's missing:
You've told us there is incorrect information on this page. If you know what we should change to make it correct, please tell us:
You've told us this page has unclear or confusing information. Please tell us more about what you found unclear or confusing, or let us know how we could make it clearer:
You've told us there is a spelling or grammar error on this page. Please tell us what's wrong:
You've told us this page has a problem. Please tell us more about what's wrong:
Thank you for helping to make the Unity documentation better!
Your feedback has been submitted as a ticket for our documentation team to review.
We are not able to reply to every ticket submitted.