You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Unity:通过代码程序化修改启动画面Logo Sprite

多平台构建时通过条件编译设置不同启动Logo的可行性

这种方式是可行的,但有几个关键细节需要注意,避免出现问题:

  • 确保PLATFORM_VARIABLE是有效的平台宏:可以使用Unity官方预定义的宏(如UNITY_ANDROID、UNITY_IOS、UNITY_STANDALONE_WIN等),也可以在PlayerSettings > Other Settings > Scripting Define Symbols中自定义专属宏。
  • 代码需在编辑环境中运行:PlayerSettings属于编辑器API,无法在游戏运行时调用,所以要把脚本放在项目的Editor目录下,或者给脚本添加[ExecuteInEditMode]特性。
  • 提前验证启动Logo数组:如果PlayerSettings.SplashScreen.logos是空数组,直接访问logos[0]会触发数组越界错误,建议先判断数组长度,或者在Unity编辑器中手动添加一个启动Logo条目后再执行赋值操作。
  • 保证资源引用有效:developerLogo和publisherLogo必须是正确的Sprite或Texture资源,同时要确保对应平台的构建配置中能正常加载这些资源(比如不要将仅适配某平台的资源打包到其他平台的构建中)。

你可以参考以下修正后的示例脚本:

#if UNITY_ANDROID
    if (PlayerSettings.SplashScreen.logos.Length > 0)
        PlayerSettings.SplashScreen.logos[0].logo = developerLogo;
#else
    if (PlayerSettings.SplashScreen.logos.Length > 0)
        PlayerSettings.SplashScreen.logos[0].logo = publisherLogo;
#endif

内容的提问来源于stack exchange,提问作者Cubius

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.12 17:01:21