/// <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();
 }
Пример #2
0
        public static MaterialCache Register(ulong hash, Texture texture, System.Func <Material> onCreateMaterial)
        {
            var cache = materialCaches.FirstOrDefault(x => x.hash == hash);

            if (cache != null && cache.material)
            {
                if (cache.material)
                {
                    cache.referenceCount++;
                }
                else
                {
                    materialCaches.Remove(cache);
                    cache = null;
                }
            }
            if (cache == null)
            {
                cache = new MaterialCache()
                {
                    hash           = hash,
                    material       = onCreateMaterial(),
                    referenceCount = 1,
                };
                materialCaches.Add(cache);
            }
            return(cache);
        }
Пример #3
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);
        }
Пример #4
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;
            }
        }
Пример #5
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;
            }
        }
Пример #6
0
 protected override void OnDisable()
 {
     Canvas.willRenderCanvases -= test;
     MaterialCache.Unregister(_materialCache);
     _materialCache = null;
     _player.OnDisable();
     base.OnDisable();
 }
Пример #7
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;
        }
Пример #8
0
        public static void Unregister(MaterialCache cache)
        {
            if (cache == null)
            {
                return;
            }

            cache.referenceCount--;
            if (cache.referenceCount <= 0)
            {
                MaterialCache.materialCaches.Remove(cache);
                cache.material = null;
            }
        }
Пример #9
0
		public static MaterialCache Register(ulong hash, System.Func<Material> onCreateMaterial)
		{
			var cache = materialCaches.FirstOrDefault(x => x.hash == hash);
			if (cache != null)
			{
				cache.referenceCount++;
			}
			if (cache == null)
			{
				cache = new MaterialCache()
				{
					hash = hash,
					material = onCreateMaterial(),
					referenceCount = 1,
				};
				materialCaches.Add(cache);
			}
			return cache;
		}
Пример #10
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;
            }
        }
Пример #11
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);
        }
Пример #12
0
        public static MaterialCache Register(ColorMode color, Texture tex, System.Func <Material> onCreateMaterial)
        {
            var cache = materialCache.FirstOrDefault(x => x.IsMatch(color, tex));

            if (cache != null)
            {
                cache.referenceCount++;
            }
            if (cache == null)
            {
                cache = new MaterialCache()
                {
                    colorMode      = color,
                    texture        = tex,
                    material       = onCreateMaterial(),
                    referenceCount = 1,
                };
                materialCache.Add(cache);
            }
            return(cache);
        }