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