private IEnumerator Changing(float processTime, int count = 13, Action onFinish = null, OnTimes onTimes = null) { while (_numbers.Count > 0) { var temp = _numbers.Dequeue(); var time = processTime / count; var d = temp - _curNumber; var nd = Mathf.Abs(d); float a; if (nd < count) { if (d >= 0) { count = (int)d; a = 1; } else { count = (int)-d; a = -1; } } else { a = (float)(d) / count; } // count = d < count ? (int)d : count; // var a = (float)(d)/count; //Debug.Log("---------- " + count + " " + a + " time:" + time); //YxDebug.Log("最终数字: " + temp + " | 差值: " + dvalue + " | 速度: " + f + " | 时间:" + time); for (var i = 0; i < count; i++) { var y = (long)(a * i + _curNumber); //Debug.Log(y); Show(y); if (onTimes != null) { onTimes(y); } yield return(new WaitForSeconds(time)); } //YxDebug.Log("最终数字: " + temp + " | 当前: " + d); _curNumber = temp; } Show(Number); _isPlaying = false; if (onFinish != null) { onFinish(); } }
public void SetNumber(long number, float processTime, int count = 11, Action onFinish = null, OnTimes onTimes = null) { if (processTime > 0) { Number = number; _numbers.Enqueue(number); if (_isPlaying) { return; } _isPlaying = true; StartCoroutine(Changing(processTime, count, onFinish, onTimes)); return; } SetNumber(number); if (onFinish != null) { onFinish(); } }