在进行移动端开发时,可访问许多特定于设备的属性。请参阅有关 SystemInfo.deviceUniqueIdentifier、SystemInfo.deviceName、SystemInfo.deviceModel 和 SystemInfo.operatingSystem 的 Unity Scripting API 页面以了解更多信息。
盗版者经常通过移除 DRM 保护再免费重新分发应用程序来进行破解。Unity 附带反盗版检查功能,用于确定应用程序在提交到 Google Play 应用商店之后是否被篡改。
要检查应用程序是否为正版(意味着未被破解),请使用 Unity Scripting API Application.genuine 属性。如果此属性返回 false
,则可通知应用程序用户他们正在使用经过破解的应用程序,也可禁用对应用程序某些功能的访问。
注意:应使用 Application.genuineCheckAvailable 以及 Application.genuine 来验证应用程序完整性。访问 Application.genuine 属性是一项资源密集型操作,因此请勿在帧更新期间或运行其他时间迫切的代码时调用该操作。
要触发振动,请在代码中调用 Handheld.Vibrate。缺少振动硬件的设备将忽略此调用。
移动操作系统具有内置活动指示器;可在慢速操作期间激活这些指示器。
请参阅活动指示器 Unity Scripting API 文档以查看示例。
为 iOS 和 Android 创建项目时,可控制用户设备的屏幕方向。检测方向变化或强制使用特定方向对于根据用户握持设备的方式来改变游戏行为非常有用。
要检索设备方向,请使用 Screen.orientation 属性。允许的方向如下:
方向 | 行为 |
---|---|
Portrait | 设备处于纵向模式,直立握持设备,主屏幕按钮位于底部。 |
PortraitUpsideDown | 设备处于纵向模式,但是上下颠倒,直立握持设备,主屏幕按钮位于顶部。 |
LandscapeLeft | 设备处于横向模式,直立握持设备,主屏幕按钮位于右侧。 |
LandscapeRight | 设备处于横向模式,直立握持设备,主屏幕按钮位于左侧。 |
通过将 Screen.orientation 设置为上述选项之一或设置为 ScreenOrientation.AutoRotation 来控制屏幕方向。
使用自动旋转时,可根据具体情况禁用某些方向。请参阅有关 Screen.autorotateToPortrait、Screen.autorotateToPortraitUpsideDown、Screen.autorotateToLandscapeLeft 和 Screen.autorotateToLandscapeRight 的脚本 API 页面以了解更多信息。
2017–05–25 页面已发布并进行了编辑审查
5.5 版中的更新功能
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.