| //-------------------------------------------------------- | 
| //    [Author]:           玩个游戏 | 
| //    [  Date ]:           Tuesday, October 24, 2017 | 
| //-------------------------------------------------------- | 
| using UnityEngine; | 
| using System.Collections; | 
| using UnityEngine.UI; | 
|   | 
|   | 
|     public class CoolDownBehaviour : MonoBehaviour | 
|     { | 
|         [SerializeField] | 
|         ButtonEx m_ButtonEx; | 
|   | 
|         [SerializeField] | 
|         Text m_OriginalText; | 
|   | 
|         [SerializeField] | 
|         Text m_CoolDownText; | 
|   | 
|         [SerializeField] | 
|         ImageEx m_GrayImage; | 
|   | 
|         float timer = 0f; | 
|         protected virtual void OnEnable() | 
|         { | 
|             timer = 0f; | 
|         } | 
|   | 
|         protected virtual void LateUpdate() | 
|         { | 
|             if (m_ButtonEx == null) | 
|             { | 
|                 return; | 
|             } | 
|   | 
|             if (m_ButtonEx.ableTime > Time.realtimeSinceStartup) | 
|             { | 
|                 if (m_CoolDownText != null && !m_CoolDownText.gameObject.activeInHierarchy) | 
|                 { | 
|                     m_CoolDownText.SetActive(true); | 
|                 } | 
|   | 
|                 if (m_OriginalText != null && m_OriginalText.gameObject.activeInHierarchy) | 
|                 { | 
|                     m_OriginalText.SetActive(false); | 
|                 } | 
|   | 
|                 if (m_GrayImage != null) | 
|                 { | 
|                     m_GrayImage.gray = true; | 
|                 } | 
|   | 
|                 timer -= Time.deltaTime; | 
|                 if (timer < 0f) | 
|                 { | 
|                     timer = 1f; | 
|                     var seconds = Mathf.RoundToInt(m_ButtonEx.ableTime - Time.realtimeSinceStartup); | 
|                     m_CoolDownText.text = StringUtility.Contact(seconds, Language.Get("RealmWin_Bewrite_35")); | 
|                 } | 
|             } | 
|             else | 
|             { | 
|                 if (m_CoolDownText != null && m_CoolDownText.gameObject.activeInHierarchy) | 
|                 { | 
|                     m_CoolDownText.SetActive(false); | 
|                 } | 
|   | 
|                 if (m_OriginalText != null && !m_OriginalText.gameObject.activeInHierarchy) | 
|                 { | 
|                     m_OriginalText.SetActive(true); | 
|                 } | 
|   | 
|                 if (m_GrayImage != null) | 
|                 { | 
|                     m_GrayImage.gray = false; | 
|                 } | 
|             } | 
|   | 
|         } | 
|   | 
|     } |