protected override void OnDisable() { base.OnDisable(); MaterialCache.Unregister(_materialCache); _materialCache = null; _player.OnDisable(); }
/// <summary> /// Modifies the material. /// </summary> public override void ModifyMaterial() { if (isTMPro) { return; } ulong hash = (m_NoiseTexture ? (uint)m_NoiseTexture.GetInstanceID() : 0) + ((ulong)1 << 32) + ((ulong)m_ColorMode << 36); if (_materialCache != null && (_materialCache.hash != hash || !isActiveAndEnabled || !m_EffectMaterial)) { MaterialCache.Unregister(_materialCache); _materialCache = null; } if (!isActiveAndEnabled || !m_EffectMaterial) { material = null; } else if (!m_NoiseTexture) { material = m_EffectMaterial; } else if (_materialCache != null && _materialCache.hash == hash) { material = _materialCache.material; } else { _materialCache = MaterialCache.Register(hash, m_NoiseTexture, () => { var mat = new Material(m_EffectMaterial); mat.name += "_" + m_NoiseTexture.name; mat.SetTexture("_NoiseTex", m_NoiseTexture); return(mat); }); material = _materialCache.material; } }