本手册页的主要目的是帮助开发者从 iOS 过渡到 tvOS。Apple TV 平台(也称为 tvOS)建立在 iOS 平台的基础上,为游戏开发者带来了新的模式和挑战。只需点击一下即可在 tvOS 上部署现有的移动端游戏,但游戏内容通常需要适应 Unity 的新输入控制方式以及游戏在大屏幕上显示的这一事实。
要进行 tvOS 开发,必须满足以下先决条件:
otool -l
从命令行分析可执行文件中的 LLVM 部分。Apple TV 遥控器(Siri 遥控器)可用作多功能输入设备,既可用作传统菜单导航控制器、游戏控制器、陀螺仪和加速度传感器,也可用作触摸手势设备。Apple TV 遥控器输入由 Unity 进行最低限度的处理,而主要路由到相应的 Unity API。
通常,每个游戏都需要对其输入方案进行微调,以利用独特的 Apple TV 遥控器输入功能。一些游戏将受益于将该遥控器用作传统游戏控制器(具有一个模拟轴和一个额外的动作按钮),而其他游戏将受益于使用加速度计(例如,用于转向目的)。建议在将游戏移植到 tvOS 时尝试各种方案。
以下是关于访问特定 TV 遥控器功能的一些技术细节:
Input.touches
(Touch.type
设置为 Indirect
并被 Unity GUI 忽略)和常规游戏杆输入 API(例如 Input.GetAxis("Horizontal");
)Input.acceleration
和 Input.gyro
。Input.acceleration
派生自内部陀螺仪 API,可能有一定的不稳定性。遗憾的是,tvOS SDK 中没有专用的加速度计 API。Input.gyro.attitude
派生自重力矢量,因此缺乏围绕平行于重力矢量的轴的旋转。Input.gyro.rotationRate
也是同样的情况。UnityEngine.Apple.TV.Remote.allowExitToHome
为 true)UnityEngine.Apple.TV.Remote.allowExitToHome
为 false 时,让应用程序响应点击(映射到按钮“Pause”/游戏杆按钮 0)。这是默认行为。UnityEngine.Apple.TV.Remote.allowExitToHome
UnityEngine.Apple.TV.Remote.allowRemoteRotation
UnityEngine.Apple.TV.Remote.reportAbsoluteDpadValues
UnityEngine.Apple.TV.Remote.touchesEnabled
警告:由于当 UnityEngine.Apple.TV.Remote.allowExitToHome
设置为 false 时,Apple TV 遥控器“Menu”按钮被报告为游戏杆按钮 0,而默认 Input 窗口绑定的 Submit 虚拟按钮也映射到同一个游戏杆按钮 0,因此按下 Menu 按钮时,此按钮会触发 UI 元素上的操作。要解决此问题,请在 Input 窗口中删除或修改 Submit 虚拟按钮绑定。
进行这些设置后,即可在 Editor 中运行时通过键盘导航 UI,而在设备上运行时通过 Apple TV 遥控器轻扫并完全停止点击。
注意:在电视模拟器中运行时,Apple TV 遥控器导航无效。
游戏中心 (Game Center) 要求为其原生排行榜 UI 提供自定义可视化资源。以下是有关如何在 Xcode 中设置这些资源的快速说明:
对于应用程序可以保留的磁盘空间量,tvOS 有严格的要求。主应用程序安装包大小不能超过 200 MB。但是,其他可下载内容的大小上限要高得多(正在使用的资源最多可达 2GB,总共可下载内容最多可达 20GB)。Apple 建议对 tvOS 的可下载内容采用按需加载资源 (On Demand Resources, ODR),因为此功能为 tvOS 提供了最佳的磁盘空间管理策略。Unity 通过资源包支持 ODR。在关于该主题的专用博客文章中可找到一份 ODR 实现指南。
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.