简单的Unity升级UI功能表现

  • Post author:
  • Post category:其他


在这里插入图片描述



渐变需要的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);
}



版权声明:本文为aaa583004321原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。