当前显示的数字/// 目标数字/// 比例值public doub.">
赞
踩
- using UnityEngine;
-
- /// <summary>
- /// 数字上升效果
- /// </summary>
- public class ChangeNum : MonoBehaviour
- {
- /// <summary>
- /// 数字变化
- /// </summary>
- /// <param name="initNum">初始数字</param>
- /// <param name="showNum">显示的数字(结果)</param>
- /// <param name="targetNum">目标数字</param>
- /// <param name="v">Linear:时间 EaseOut:比例值</param>
- /// <param name="changeType">变化类型</param>
- public static double NumberChange(double initNum, double showNum, double targetNum, float v, ChangeType changeType = ChangeType.Linear)
- {
- switch (changeType)
- {
- case ChangeType.Linear:
- showNum += (targetNum - initNum) * Time.deltaTime / v;
- if (showNum >= targetNum)
- {
- showNum = targetNum;
- }
- return showNum;
- case ChangeType.EaseIn:
- return showNum;
- case ChangeType.EaseOut:
- showNum += (targetNum - showNum) * Time.deltaTime / v;
- return showNum;
- default:
- return 0;
- }
- }
- }
-
- /// <summary>
- /// 变化速度的类型
- /// </summary>
- public enum ChangeType
- {
- Linear,//线性
- EaseIn,//先慢后快
- EaseOut,//先快后慢
- }
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。