异步跳转(跳转间接)------枚举在要跳转的Button中设置并跳转到缓冲场景

这篇博客详细介绍了在Unity中如何使用UnityEngine.SceneManagement进行场景的异步加载,并通过UI Slider和Text组件实时显示加载进度。代码示例展示了如何在Login和Main两个场景间平滑切换,并通过限制场景激活来防止加载过程中的不必要操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
 public enum Scenetype
   {
   Login,//开始场景
    Main//战斗场景
   }
 public class UILoadingView : MonoBehaviour
 {
public static Scenetype scentype;

public Slider slider;
public Text text;
private AsyncOperation async;


void Start ()
{
    if (scentype == Scenetype.Main)
    {
        async = SceneManager.LoadSceneAsync("Main");
    }
    else if (scentype == Scenetype.Login)
    {
        async = SceneManager.LoadSceneAsync("Login");
    }
    //异步跳转       
   // async = SceneManager.LoadSceneAsync(JianJie.Instance.Path_ );           
    async.allowSceneActivation = false;
   
}
private int progpress;
private int currprogpress;
void Update ()
{
    OnTime();
}
public void OnTime()
{
    if (async != null)
    {
        if (async.progress < 0.9)//跳转加载进度
        {
            //使加载不生硬 
            progpress = Mathf.Clamp((int)async.progress * 100, 1, 100);
        }
        else
        {
            progpress = 100;
        }
        if (currprogpress < progpress)
        {
            currprogpress++;
            slider.value = currprogpress / 100.0f;
            text.text = string.Format("{0}%", currprogpress );
        }
        else
        {
            slider.value = 1;
            currprogpress = 100;    
            text.text = string.Format("{0}%", currprogpress);
            async.allowSceneActivation = true;
        }
    }
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

卿屿­­­­­­­-轻尘

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值