Unity学习辅助篇之打包跳过Unity开场动画

在学习Unity的过程中,我们将做好的项目进行打包至其他平台后运行,会出现Unity自带的过场动画,如何解决?仅需一段代码即可。

Assets文件夹添加脚本SkipUnityLogo,如下

#if !UNITY_EDITOR
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Scripting;

/**
 * 跳过unity-logo
 */
[Preserve]
public class SkipUnityLogo
{
    [RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]
    private static void BeforeSplashScreen()
    {
#if UNITY_WEBGL
        Application.focusChanged += Application_focusChanged;
#else
        System.Threading.Tasks.Task.Run(AsyncSkip);
#endif
    }
 
#if UNITY_WEBGL
    private static void Application_focusChanged(bool obj)
    {
        Application.focusChanged -= Application_focusChanged;
        SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
    }
#else
    private static void AsyncSkip()
    {
        SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate);
    }
#endif
}
#endif

通过此脚本,Unity的开场动画会消失掉。只有这个需求的,看到这里就可以结束了。

接下来,我们可以添加自定义的加载图片。

打开 Edit -> Project Settings -> Player,可以进行设置了

以下三个平台,都存在Splash Image 根据你打包的平台进行设置

Android为例

PlayerSettings->Player->Android->Splash Image下的Background Image添加图片即可。

本文章解决的Unity为免费版,付费版在Splash Image有跳过开场动画的选项。

重新打包,则会成功替换为你设置的图片。

猜你喜欢

转载自blog.csdn.net/m0_68957787/article/details/142817346