123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143 |
- using UnityEngine;
- using System.Collections;
- using UnityEngine.UI;
- using System;
- public class SliderLerp : MonoBehaviour {
- /// <summary>
- ///
- /// </summary>
- private Slider mOwner = null;
- /// <summary>
- ///
- /// </summary>
- private float mRate = 0;
- /// <summary>
- ///
- /// </summary>
- private float mCurt = 0;
- /// <summary>
- /// 耗时(毫秒)
- /// </summary>
- private float mTime = 0;
- /// <summary>
- /// 速度1500毫秒
- /// </summary>
- private float mSpeed = 0.2f;
- /// <summary>
- /// 发光条
- /// </summary>
- private Transform mGlow = null;
- /// <summary>
- /// 下面的计数框
- /// </summary>
- private Transform mHandle = null;
- /// <summary>
- /// 是否十连
- /// </summary>
- public bool mBoolTen = false;
- /// <summary>
- /// 是否结束
- /// </summary>
- public bool mBoolOver = true;
- /// <summary>
- ///
- /// </summary>
- public void InitComponents()
- {
- // Handle Slide Area
- this.mOwner = GetComponent<Slider>();
- mGlow = transform.Find("Fill Area/Fill/glow");
- if (mGlow != null)
- {
- mGlow.gameObject.SetActive(false);
- }
- mHandle = transform.Find("Handle Slide Area/Handle");
- }
- /// <summary>
- ///
- /// </summary>
- public void SetData(float _rate)
- {
- this.mCurt = _rate;
- this.mRate = _rate;
- }
- /// <summary>
- ///
- /// </summary>
- /// <param name="_rate">值</param>
- public void SetValueLerp(float _rate)
- {
- this.mRate = _rate;
- this.mBoolOver = false;
- if (mGlow != null)
- {
- mGlow.gameObject.SetActive(true);
- }
- if (mHandle != null && mBoolTen )
- {
- mHandle.GetComponent<Animator>().Play("LuckSilder");
- }
- }
- /// <summary>
- ///
- /// </summary>
- void Update()
- {
- if (this.mOwner == null)
- {
- return;
- }
- this.mCurt = Mathf.Lerp(this.mCurt, this.mRate, mSpeed);
- this.mOwner.value = this.mCurt;
- if (mHandle != null)
- {
- Transform temptxt = null;
- temptxt = mHandle.Find("NumText");
- // LogHelper.Log(temptxt);
- if (temptxt != null)
- {
- // LogHelper.Log(((int)this.mOwner.value * 100).ToString());
- temptxt.GetComponent<Text>().text = (Math.Round(this.mOwner.value * 100, 0)).ToString();
- }
- }
- if (mRate == 0)
- {
- if (mGlow != null)
- {
- mGlow.gameObject.SetActive(false);
- }
- if (mHandle != null && mBoolTen && !mBoolOver)
- {
- mHandle.GetComponent<Animator>().Play("LuckSliderStop");
- }
- this.mBoolOver = true;
- }
- else if ((mCurt / mRate )> 0.98f )
- {
- if (mGlow != null)
- {
- mGlow.gameObject.SetActive(false);
- }
- if (mHandle != null && mBoolTen && !mBoolOver)
- {
- mHandle.GetComponent<Animator>().Play("LuckSliderStop");
- }
- this.mBoolOver = true;
- }
- }
- }
|