以上是启动屏相关API
相关特性RuntimeInitializeOnLoadMethodAttribute
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.BeforeSplashScreen)]即在在显示启动画面之前调用这个静态方法,在静态方法中调用SplashScreen.Stop(SplashScreen.StopBehavior.StopImmediate)来立即停止启动屏。
设置RuntimeInitializeOnLoadMethod类型。
AfterSceneLoad | 在场景加载后 |
BeforeSceneLoad | 在场景加载前 |
AfterAssembliesLoaded | 加载完所有程序集并初始化预加载资源时的回调 |
BeforeSplashScreen | 在显示启动画面之前 |
SubsystemRegistration | 用于子系统注册的回调 |
使用方法:
将下面脚本文件直接作为Runtime代码放到项目里(注意,不是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