简单的Unity升级UI功能表现

9 篇文章 0 订阅

在这里插入图片描述

渐变需要的UI数据

public struct LerpEffectUIData
{
      public Image fill;
      public Text leftText;
      public Text rightText;
}

渐变频率参数

 public struct LerpEffectData
 {
      public float plusValue;
      public float waitTimeValue;
 }

主要逻辑

public void DoFillAmount(LerpEffectUIData uidata, int getExp, int nowLevelExp, int nowLevel, Dictionary<int, float> level_Exp_Dicts, LerpEffectData _data,Action<int,int> call=null)
{
      StartCoroutine(ILevelExpLerpEffect(uidata, getExp,nowLevelExp,nowLevel, level_Exp_Dicts, _data, call));
}
 IEnumerator ILevelExpLerpEffect(LerpEffectUIData uidata, int getExp,int nowLevelExp,int nowLevel,Dictionary<int, float> level_Exp_Dicts, LerpEffectData _data, Action<int, int> call)
{
      //判断是否升级?
      int nowTempExp = nowLevelExp+ getExp;
      int nowTempLevel = nowLevel;
      //*******************************满足升级*****************************************
      while (nowTempExp> level_Exp_Dicts[nowTempLevel + 1])
      {
        int outExp = nowTempExp - (int)level_Exp_Dicts[nowTempLevel + 1];
        //升1级消耗完剩余的经验值
        nowTempExp = outExp;
        nowTempLevel++;
        //对应下一级的进度
        float outExpPropress = (float)outExp/level_Exp_Dicts[nowTempLevel + 1];
        //进度条动画
        while (uidata.fill.fillAmount < 1f)
        {
          uidata.fill.fillAmount += _data.plusValue;
          yield return new WaitForSeconds(_data.waitTimeValue);
        }
        uidata.leftText.text = nowTempLevel.ToString();
        //这里可以做一些动画表现.......         
        rightText.transform.DOScale(1.1f,0.1f).OnComplete(()=> {
          rightText.transform.DOScale(1, 0.1f);
          rightText.text = (nowTempLevel + 1).ToString();
        });
        uidata.fill.fillAmount = 0f;
        //继续下一级别的进度
        while (outExpPropress >= 1)
        {
          while (uidata.fill.fillAmount < 1f)
          {
            uidata.fill.fillAmount += _data.plusValue;
            yield return new WaitForSeconds(_data.waitTimeValue);
          }
          outExpPropress -= 1f;
        }
        while (uidata.fill.fillAmount < outExpPropress)
        {
          uidata.fill.fillAmount += _data.plusValue;
          yield return new WaitForSeconds(_data.waitTimeValue);
        }
      }
      //*******************************不满足升级*****************************************

      float targetExpPropress = nowTempExp / level_Exp_Dicts[nowTempLevel + 1];
      Debug.Log(targetExpPropress);
      while (uidata.fill.fillAmount < targetExpPropress)
      {
        uidata.fill.fillAmount += _data.plusValue;
        yield return new WaitForSeconds(_data.waitTimeValue);
      }

      call?.Invoke(nowTempLevel, nowTempExp);
      Debug.Log("新等级=>"+nowTempLevel);
      Debug.Log("升级后当前经验=>"+ nowTempExp);
}
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

打赏作者

_阿松先生

感谢您的支持~

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

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

打赏作者

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

抵扣说明:

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

余额充值