SliderLerp.cs 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143
  1. using UnityEngine;
  2. using System.Collections;
  3. using UnityEngine.UI;
  4. using System;
  5. public class SliderLerp : MonoBehaviour {
  6. /// <summary>
  7. ///
  8. /// </summary>
  9. private Slider mOwner = null;
  10. /// <summary>
  11. ///
  12. /// </summary>
  13. private float mRate = 0;
  14. /// <summary>
  15. ///
  16. /// </summary>
  17. private float mCurt = 0;
  18. /// <summary>
  19. /// 耗时(毫秒)
  20. /// </summary>
  21. private float mTime = 0;
  22. /// <summary>
  23. /// 速度1500毫秒
  24. /// </summary>
  25. private float mSpeed = 0.2f;
  26. /// <summary>
  27. /// 发光条
  28. /// </summary>
  29. private Transform mGlow = null;
  30. /// <summary>
  31. /// 下面的计数框
  32. /// </summary>
  33. private Transform mHandle = null;
  34. /// <summary>
  35. /// 是否十连
  36. /// </summary>
  37. public bool mBoolTen = false;
  38. /// <summary>
  39. /// 是否结束
  40. /// </summary>
  41. public bool mBoolOver = true;
  42. /// <summary>
  43. ///
  44. /// </summary>
  45. public void InitComponents()
  46. {
  47. // Handle Slide Area
  48. this.mOwner = GetComponent<Slider>();
  49. mGlow = transform.Find("Fill Area/Fill/glow");
  50. if (mGlow != null)
  51. {
  52. mGlow.gameObject.SetActive(false);
  53. }
  54. mHandle = transform.Find("Handle Slide Area/Handle");
  55. }
  56. /// <summary>
  57. ///
  58. /// </summary>
  59. public void SetData(float _rate)
  60. {
  61. this.mCurt = _rate;
  62. this.mRate = _rate;
  63. }
  64. /// <summary>
  65. ///
  66. /// </summary>
  67. /// <param name="_rate">值</param>
  68. public void SetValueLerp(float _rate)
  69. {
  70. this.mRate = _rate;
  71. this.mBoolOver = false;
  72. if (mGlow != null)
  73. {
  74. mGlow.gameObject.SetActive(true);
  75. }
  76. if (mHandle != null && mBoolTen )
  77. {
  78. mHandle.GetComponent<Animator>().Play("LuckSilder");
  79. }
  80. }
  81. /// <summary>
  82. ///
  83. /// </summary>
  84. void Update()
  85. {
  86. if (this.mOwner == null)
  87. {
  88. return;
  89. }
  90. this.mCurt = Mathf.Lerp(this.mCurt, this.mRate, mSpeed);
  91. this.mOwner.value = this.mCurt;
  92. if (mHandle != null)
  93. {
  94. Transform temptxt = null;
  95. temptxt = mHandle.Find("NumText");
  96. // LogHelper.Log(temptxt);
  97. if (temptxt != null)
  98. {
  99. // LogHelper.Log(((int)this.mOwner.value * 100).ToString());
  100. temptxt.GetComponent<Text>().text = (Math.Round(this.mOwner.value * 100, 0)).ToString();
  101. }
  102. }
  103. if (mRate == 0)
  104. {
  105. if (mGlow != null)
  106. {
  107. mGlow.gameObject.SetActive(false);
  108. }
  109. if (mHandle != null && mBoolTen && !mBoolOver)
  110. {
  111. mHandle.GetComponent<Animator>().Play("LuckSliderStop");
  112. }
  113. this.mBoolOver = true;
  114. }
  115. else if ((mCurt / mRate )> 0.98f )
  116. {
  117. if (mGlow != null)
  118. {
  119. mGlow.gameObject.SetActive(false);
  120. }
  121. if (mHandle != null && mBoolTen && !mBoolOver)
  122. {
  123. mHandle.GetComponent<Animator>().Play("LuckSliderStop");
  124. }
  125. this.mBoolOver = true;
  126. }
  127. }
  128. }