66 lines
1.9 KiB
C#
66 lines
1.9 KiB
C#
|
using UnityEngine;
|
|||
|
using UnityEngine.UI;
|
|||
|
using UnityEngine.SceneManagement;
|
|||
|
using System.Threading.Tasks;
|
|||
|
using DG.Tweening;
|
|||
|
using TMPro;
|
|||
|
using System.Collections;
|
|||
|
using Unity.VisualScripting;
|
|||
|
|
|||
|
public class loadingPanel : MonoBehaviour
|
|||
|
{
|
|||
|
public Text targetText; // <20><>Ҫ<EFBFBD><D2AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Text<78><74><EFBFBD><EFBFBD>
|
|||
|
public string fullText = "<22><><EFBFBD>ڼ<EFBFBD><DABC>أ<EFBFBD><D8A3><EFBFBD><EFBFBD>Ժ<EFBFBD>..."; // Ҫ<><D2AA>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD>
|
|||
|
public float typewriterDelay = 0.1f; // <20><><EFBFBD>ֻ<EFBFBD>Ч<EFBFBD><D0A7><EFBFBD>ļ<EFBFBD><C4BC><EFBFBD>ʱ<EFBFBD><CAB1>
|
|||
|
public int SceneIndex;
|
|||
|
|
|||
|
// <20><><EFBFBD>Ƽ<EFBFBD><C6BC>س<EFBFBD><D8B3><EFBFBD><EFBFBD>Ͷ<EFBFBD><CDB6><EFBFBD>֮<EFBFBD><D6AE><EFBFBD><EFBFBD>ʱ<EFBFBD><CAB1>ͬ<EFBFBD><CDAC>
|
|||
|
async void Start()
|
|||
|
{
|
|||
|
// <20><><EFBFBD>ü<EFBFBD><C3BC>س<EFBFBD><D8B3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD><EFBFBD><EFBFBD>ķ<EFBFBD><C4B7><EFBFBD>
|
|||
|
await LoadSceneWithTextAnimation(SceneIndex);
|
|||
|
}
|
|||
|
|
|||
|
public async Task LoadSceneWithTextAnimation(int sceneBuildIndex)
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
Task textAnimationTask = AnimateText();
|
|||
|
|
|||
|
// <20>첽<EFBFBD><ECB2BD><EFBFBD>س<EFBFBD><D8B3><EFBFBD>
|
|||
|
AsyncOperation asyncOperation = SceneManager.LoadSceneAsync(sceneBuildIndex);
|
|||
|
asyncOperation.allowSceneActivation = false; // <20><><EFBFBD>Զ<EFBFBD><D4B6><EFBFBD><EFBFBD><EFBFBD><EEB3A1>
|
|||
|
|
|||
|
while (!asyncOperation.isDone)
|
|||
|
{
|
|||
|
// <20><><EFBFBD>ݼ<EFBFBD><DDBC>ؽ<EFBFBD><D8BD>ȸ<EFBFBD><C8B8><EFBFBD>UI
|
|||
|
float progress = asyncOperation.progress;
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD>ݣ<EFBFBD><DDA3><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ؽ<EFBFBD><D8BD><EFBFBD>
|
|||
|
targetText.text = $"{fullText} ({progress * 100:F0}%)";
|
|||
|
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD>ؽ<EFBFBD><D8BD>Ƚӽ<C8BD>90%ʱ<><CAB1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
if (progress >= 0.9f)
|
|||
|
{
|
|||
|
asyncOperation.allowSceneActivation = true;
|
|||
|
}
|
|||
|
|
|||
|
// ÿִ֡<D6A1><D6B4>һ<EFBFBD><D2BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
await Task.Yield();
|
|||
|
}
|
|||
|
|
|||
|
// <20>ȴ<EFBFBD><C8B4>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>û<EFBFBD>н<EFBFBD><D0BD><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
await textAnimationTask;
|
|||
|
}
|
|||
|
|
|||
|
// ִ<><D6B4><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ı<EFBFBD><C4B1><EFBFBD><EFBFBD><EFBFBD>
|
|||
|
private async Task AnimateText()
|
|||
|
{
|
|||
|
// <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD>ı<EFBFBD>
|
|||
|
for (int i = 0; i < fullText.Length; i++)
|
|||
|
{
|
|||
|
targetText.text = fullText.Substring(0, i + 1); // <20><><EFBFBD><EFBFBD><EFBFBD>ַ<EFBFBD><D6B7><EFBFBD>ƴ<EFBFBD><C6B4><EFBFBD><EFBFBD>ʾ<EFBFBD>ı<EFBFBD>
|
|||
|
await Task.Delay((int)(typewriterDelay * 1000)); // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ʾ<EFBFBD><CABE><EFBFBD>ٶ<EFBFBD>
|
|||
|
}
|
|||
|
}
|
|||
|
}
|