private void EnsureTintExists() { if (Tint == null) { Tint = new TintData(); } }
// ******************************************************************** // ******************************************************************** #region MonoBehaviour Methods // ******************************************************************** void Awake() { for (int i = 0; i < m_tints.Count; ++i) { TintData tint = m_tints[i]; if (m_tintMap.ContainsKey(tint.id)) { Debug.LogError("Duplicate ID found: " + tint.id); } else { m_tintMap[tint.id] = tint; } } }
// ******************************************************************** #endregion // ******************************************************************** // ******************************************************************** #region Private Methods // ******************************************************************** private void ApplyTint(string _id) { if (!m_tintMap.ContainsKey(_id)) { Debug.LogError("No data found for ID: " + _id); return; } TintData tint = m_tintMap[_id]; if (tint.duration == 0) { for (int i = 0; i < tint.renderers.Length; ++i) { tint.renderers[i].color = tint.tint; } } else { StartCoroutine(ApplyTintOverTime(tint)); } }
// ******************************************************************** #endregion // ******************************************************************** // ******************************************************************** #region Private Methods // ******************************************************************** private IEnumerator ApplyTintOverTime(TintData _tint) { float startTime = Time.time; Color[] originalColors = new Color[_tint.renderers.Length]; for (int i = 0; i < originalColors.Length; ++i) { originalColors[i] = _tint.renderers[i].color; } while (Time.time < startTime + _tint.duration) { float timePassed = Time.time - startTime; for (int i = 0; i < _tint.renderers.Length; ++i) { _tint.renderers[i].color = Color.Lerp(originalColors[i], _tint.tint, timePassed / _tint.duration); } yield return(null); } for (int i = 0; i < _tint.renderers.Length; ++i) { _tint.renderers[i].color = _tint.tint; } }
private void EnsureTintExists() { if (Tint == null) Tint = new TintData(); }