这是一种在Unity个人版去除默认启动动画的方法,通过修改RuntimeInitializeOnLoadType属性,创建脚本SkipUnityLogo,适用于Unity2019.4及以上版本,但可能在大型项目中出现闪现或延迟问题。
1.概述介绍
在Unity发布后默认启动会有启动动画,并且默认是Unity的Logo。而在Project Settings里个人版是不能去掉这个启动动画的,需要付费购买才行,那么这里推荐一种使用个人版也能去除Logo的办法。
2.RuntimeInitializeLoadType
API描述
设置 RuntimeInitializeOnLoadMethod 类型。
另请参阅:RuntimeInitializeOnLoadMethodAttribute。
应用变量
AfterSceneLoad 在场景加载后。
BeforeSceneLoad 在场景加载前。
AfterAssembliesLoaded 加载完所有程序集并初始化预加载资源时的回调。
BeforeSplashScreen 在显示启动画面之前。
SubsystemRegistration 用于子系统注册的回调
代码放在不是Editor下面就行
代码如下:
#if !UNITY_EDITOR
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Scripting;
[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
4.注意事项
- 此方法不是所有Unity版本有效,我这用的Unity2021版本测试。理论上是Unity2019.4或者更高版本。
- 当工程较大时,会出现Logo一闪而过或者卡出几帧Logo画面。
感谢您的阅读,如果喜欢,就帮忙点个赞。
点关注,点个关注不迷路哦!!!谢谢