Unregister() public static method

public static Unregister ( MaterialCache cache ) : void
cache MaterialCache
return void
 /// <summary>
 /// This function is called when the behaviour becomes disabled () or inactive.
 /// </summary>
 protected override void OnDisable()
 {
     base.OnDisable();
     MaterialCache.Unregister(_materialCache);
     _materialCache = null;
     _player.OnDisable();
 }
Example #2
0
        /// <summary>
        /// Modifies the material.
        /// </summary>
        public Material GetModifiedMaterial(Material baseMaterial)
        {
            if (_materialCache != null && !_materialCache.IsMatch(m_ColorMode, m_NoiseTexture))
            {
                MaterialCache.Unregister(_materialCache);
                _materialCache = null;
            }

            if (!isActiveAndEnabled || !m_NoiseTexture || !m_EffectMaterial)
            {
                return(baseMaterial);
            }
            else if (_materialCache != null && _materialCache.IsMatch(m_ColorMode, m_NoiseTexture))
            {
                return(_materialCache.material);
            }

            _materialCache = MaterialCache.Register(m_ColorMode, m_NoiseTexture, () =>
            {
                var mat = new Material(m_EffectMaterial);
                mat.SetTexture("_NoiseTex", m_NoiseTexture);
                return(mat);
            });
            return(_materialCache.material);
        }
Example #3
0
        /// <summary>
        /// Modifies the material.
        /// </summary>
        public override void ModifyMaterial()
        {
            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)
            {
                graphic.material = null;
            }
            else if (!m_NoiseTexture)
            {
                graphic.material = m_EffectMaterial;
            }
            else if (_materialCache != null && _materialCache.hash == hash)
            {
                graphic.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);
                });
                graphic.material = _materialCache.material;
            }
        }
Example #4
0
        /// <summary>
        /// Modifies the material.
        /// </summary>
        public override void ModifyMaterial()
        {
            ulong hash = (m_TransitionTexture ? (uint)m_TransitionTexture.GetInstanceID() : 0) + (uint)m_EffectMode;

            if (_materialCache != null && (_materialCache.hash != hash || !isActiveAndEnabled || !m_EffectMaterial))
            {
                MaterialCache.Unregister(_materialCache);
                _materialCache = null;
            }

            if (!isActiveAndEnabled || !m_EffectMaterial)
            {
                graphic.material = null;
            }
            else if (!m_TransitionTexture)
            {
                graphic.material = m_EffectMaterial;
            }
            else if (_materialCache != null && _materialCache.hash == hash)
            {
                graphic.material = _materialCache.material;
            }
            else
            {
                _materialCache = MaterialCache.Register(hash, m_TransitionTexture, () =>
                {
                    var mat = new Material(m_EffectMaterial);
                    mat.SetTexture("_TransitionTexture", m_TransitionTexture);
                    return(mat);
                });
                graphic.material = _materialCache.material;
            }
        }
Example #5
0
 protected override void OnDisable()
 {
     Canvas.willRenderCanvases -= test;
     MaterialCache.Unregister(_materialCache);
     _materialCache = null;
     _player.OnDisable();
     base.OnDisable();
 }
Example #6
0
        /// <summary>
        /// This function is called when the behaviour becomes disabled () or inactive.
        /// </summary>
        protected override void OnDisable()
        {
            SetVerticesDirty();
            SetMaterialDirty();

            if (paramTex != null)
            {
                paramTex.Unregister(this);
            }

            MaterialCache.Unregister(_effectMaterialHash);
            _effectMaterialHash = k_InvalidHash;
        }
Example #7
0
        /// <summary>
        /// Modifies the material.
        /// </summary>
        public override void ModifyMaterial()
        {
            if (graphic is TMPro.TextMeshProUGUI)
            {
                TMPro.TextMeshProUGUI t = graphic as TMPro.TextMeshProUGUI;
                //baseMaterial.SetTexture ("_NoiseTex", m_NoiseTexture);
                Debug.LogFormat("ModifyMaterial {0}, {1}, {2}, {3}, {4}", t.material, t.fontMaterial, t.fontMaterial.GetInstanceID(), t.fontSharedMaterial, t.fontSharedMaterial.GetInstanceID());
                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;
            }
        }
Example #8
0
        public virtual Material GetModifiedMaterial(Material baseMaterial, Graphic graphic)
        {
            if (!isActiveAndEnabled)
            {
                return(baseMaterial);
            }

            var oldHash = _effectMaterialHash;

            _effectMaterialHash = GetMaterialHash(baseMaterial);
            var modifiedMaterial = baseMaterial;

            if (_effectMaterialHash.isValid)
            {
                modifiedMaterial = MaterialCache.Register(baseMaterial, _effectMaterialHash, ModifyMaterial, graphic);
            }

            MaterialCache.Unregister(oldHash);

            return(modifiedMaterial);
        }