Ejemplo n.º 1
0
        public static Material GetSharedFor(SkinnedGlowEffect spriteGlow)
        {
            for (int i = 0; i < sharedMaterials.Count; i++)
            {
                if (//sharedMaterials[i].SpriteTexture == spriteGlow.Renderer.sprite.texture &&
                    sharedMaterials[i].DrawOutside == spriteGlow.DrawOutside &&
                    sharedMaterials[i].InstancingEnabled == spriteGlow.EnableInstancing)
                {
                    return(sharedMaterials[i]);
                }
            }

            var material = new SkinnedGlowMaterial(//spriteGlow.Renderer.sprite.texture,
                spriteGlow.DrawOutside, spriteGlow.EnableInstancing);

            material.hideFlags = HideFlags.DontSaveInBuild | HideFlags.DontSaveInEditor | HideFlags.NotEditable;
            sharedMaterials.Add(material);

            return(material);
        }
Ejemplo n.º 2
0
        private void SetMaterialProperties()
        {
            if (!Renderer)
            {
                return;
            }

            Renderer.sharedMaterial = SkinnedGlowMaterial.GetSharedFor(this);

            if (materialProperties == null) // Initializing it at `Awake` or `OnEnable` causes nullref in editor in some cases.
            {
                materialProperties = new MaterialPropertyBlock();
            }

            materialProperties.SetFloat(isOutlineEnabledId, isActiveAndEnabled ? 1 : 0);
            materialProperties.SetColor(outlineColorId, GlowColor * GlowBrightness);
            materialProperties.SetFloat(outlineSizeId, OutlineWidth);
            materialProperties.SetFloat(alphaThresholdId, AlphaThreshold);

            Renderer.SetPropertyBlock(materialProperties);
        }