11111
This commit is contained in:
48
Assets/00.StaryEvo/Runtime/Tool/loading/SplashScreen.cs
Normal file
48
Assets/00.StaryEvo/Runtime/Tool/loading/SplashScreen.cs
Normal file
@@ -0,0 +1,48 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Threading.Tasks;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.UI;
|
||||
|
||||
public class SplashScreen : MonoBehaviour
|
||||
{
|
||||
private Image image;
|
||||
|
||||
async void Start()
|
||||
{
|
||||
image = GetComponentInChildren<Image>();
|
||||
// 初始完全透明
|
||||
image.color = new Color(1, 1, 1, 0);
|
||||
|
||||
// 渐显效果(2秒)
|
||||
await Fade(0, 1, 0.5f);
|
||||
|
||||
// 保持显示(原2秒等待)
|
||||
await UniTask.Delay(TimeSpan.FromSeconds(1));
|
||||
|
||||
// 渐隐效果(1秒)
|
||||
await Fade(1, 0, 0.5f);
|
||||
|
||||
await SceneManager.LoadSceneAsync(1);
|
||||
if (transform != null)
|
||||
Destroy(gameObject);
|
||||
}
|
||||
|
||||
|
||||
private async UniTask Fade(float startAlpha, float endAlpha, float duration)
|
||||
{
|
||||
float elapsed = 0f;
|
||||
while (elapsed < duration)
|
||||
{
|
||||
float alpha = Mathf.Lerp(startAlpha, endAlpha, elapsed / duration);
|
||||
image.color = new Color(1, 1, 1, alpha);
|
||||
elapsed += Time.deltaTime;
|
||||
await UniTask.Yield();
|
||||
}
|
||||
|
||||
image.color = new Color(1, 1, 1, endAlpha);
|
||||
}
|
||||
}
|
||||
11
Assets/00.StaryEvo/Runtime/Tool/loading/SplashScreen.cs.meta
Normal file
11
Assets/00.StaryEvo/Runtime/Tool/loading/SplashScreen.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: eaccb6795ccb65c479e97450d3227af6
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user