unity:一行代码写完加载进度条

很多时候游戏并不需要真的进行异步加载场景,但是刚打开游戏的时候,通常会稍微有些卡(比如因为要加载广告之类的),这个时候,放一个加载进度条就很有用;用doTween的方式,一行代码就能实现此效果:

this.bar.DOFillAmount(0.3f, 2f).OnComplete((TweenCallback) (() => this.bar.DOFillAmount(0.8f, 2f).OnComplete((TweenCallback) (() => this.bar.DOFillAmount(1f, 2f).OnComplete((TweenCallback) (() =>
    {};
如果需要在加载完毕后实现下一步操作,在后面的完成事件里添加代码就好了,比如:
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;

public class loading : MonoBehaviour
{
  public Image bar;
  public GameObject menuPanel;
  public GameObject dailyBonusPanel;

  private void Start()
  {
    this.bar.DOFillAmount(0.3f, 2f).OnComplete((TweenCallback) (() => this.bar.DOFillAmount(0.8f, 2f).OnComplete((TweenCallback) (() => this.bar.DOFillAmount(1f, 2f).OnComplete((TweenCallback) (() =>
    {
      this.dailyBonusPanel.SetActive(true);
      this.menuPanel.SetActive(true);
      this.gameObject.SetActive(false);
    }))))));
  }
}

你可能感兴趣的:(unity,loading)