高亮
字体高亮:
获取UIlabel Effec属性调整

 private void SetFont()
    {
        SetBrightnessFont(playerNum);
        SetBrightnessFont(cardNum);
        SetBrightnessFont(coinNum);
        Invoke("NextFont", 0.3f);
    }
     private void SetBrightnessFont(UILabel uilabel)  //设置字体高亮
    {
        uilabel.effectStyle = UILabel.Effect.Shadow;
        uilabel.effectColor = new Color(255, 255, 255, 255);
       
    }
  private void RecoveryFont(UILabel uilabel)  //字体高亮复原
    {
        uilabel.effectStyle = UILabel.Effect.Outline;
        uilabel.effectColor = new Color(0,0,0, 255);
    }
这样就可以实现字体高亮闪现的效果
图片高亮:
第一步修改Unlit - Premultiplied Colored

 
Shader "Unlit/Transparent Colored (Bright)"
{
    Properties
    {
        _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
        _Bright("Brightness", Float) = 2
    }
     
    SubShader
    {
        LOD 100
 
        Tags
        {
            "Queue" = "Transparent"
            "IgnoreProjector" = "True"
            "RenderType" = "Transparent"
        }
         
        Cull Off
        Lighting Off
        ZWrite Off
        Fog { Mode Off }
        Offset -1, -1
        Blend SrcAlpha OneMinusSrcAlpha
 
        Pass
        {
            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                 
                #include "UnityCG.cginc"
     
                struct appdata_t
                {
                    float4 vertex : POSITION;
                    float2 texcoord : TEXCOORD0;
                    fixed4 color : COLOR;
                };
     
                struct v2f
                {
                    float4 vertex : SV_POSITION;
                    half2 texcoord : TEXCOORD0;
                    fixed4 color : COLOR;
                };
     
                sampler2D _MainTex;
                float4 _MainTex_ST;
                float _Bright;
                 
                v2f vert (appdata_t v)
                {
                    v2f o;
                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                    o.color = v.color;
                    return o;
                }
                 
                fixed4 frag (v2f i) : COLOR
                {
                    fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
                    col.rgb = _Bright * col.rgb;
                    return col;
                }
            ENDCG
        }
    }
 
    SubShader
    {
        LOD 100
 
        Tags
        {
            "Queue" = "Transparent"
            "IgnoreProjector" = "True"
            "RenderType" = "Transparent"
        }
         
        Pass
        {
            Cull Off
            Lighting Off
            ZWrite Off
            Fog { Mode Off }
            Offset -1, -1
            ColorMask RGB
            AlphaTest Greater .01
            Blend SrcAlpha OneMinusSrcAlpha
            ColorMaterial AmbientAndDiffuse
             
            SetTexture [_MainTex]
            {
                Combine Texture * Primary
            }
        }
    }
}


 第二步:
将图片的Shader进行替换

如果是Sprite的话可以进行如下操作
1.
创建新的Atlas

NGUI字体或图片高亮(灰化)
 
复制Atlas和Material,如上图是Wooden Atlas 1(两个分别是Atlas和Material)
将Atlas Wooden Atlas 1的Material指定为Wooden Atlas 1
修改新的Material
 NGUI字体或图片高亮(灰化)
 增加亮度
 NGUI字体或图片高亮(灰化)
修改Brightness即可(注意:修改后窗口可能不能立即显示效果,需要强制刷新对应的Panel)
NGUI字体或图片高亮(灰化)

应用
代码里面,用的时候将对应的sprite的atlas指定为新的atlas即可。

字体的灰化
和字体的高亮进行同样处理


图片的灰化
和图片的高亮唯一不同的只有shader代码了
shader代码

Shader "Unlit/Transparent Colored (Gray)"
{
    Properties
    {
        _MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
    }
     
    SubShader
    {
        LOD 100
 
        Tags
        {
            "Queue" = "Transparent"
            "IgnoreProjector" = "True"
            "RenderType" = "Transparent"
        }
         
        Cull Off
        Lighting Off
        ZWrite Off
        Fog { Mode Off }
        Offset -1, -1
        Blend SrcAlpha OneMinusSrcAlpha
 
        Pass
        {
            CGPROGRAM
                #pragma vertex vert
                #pragma fragment frag
                 
                #include "UnityCG.cginc"
     
                struct appdata_t
                {
                    float4 vertex : POSITION;
                    float2 texcoord : TEXCOORD0;
                    fixed4 color : COLOR;
                };
     
                struct v2f
                {
                    float4 vertex : SV_POSITION;
                    half2 texcoord : TEXCOORD0;
                    fixed4 color : COLOR;
                };
     
                sampler2D _MainTex;
                float4 _MainTex_ST;
                 
                v2f vert (appdata_t v)
                {
                    v2f o;
                    o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
                    o.texcoord = TRANSFORM_TEX(v.texcoord, _MainTex);
                    o.color = v.color;
                    return o;
                }
                 
                fixed4 frag (v2f i) : COLOR
                {
                    fixed4 col = tex2D(_MainTex, i.texcoord) * i.color;
                    col.rgb = dot(col.rgb, fixed3(.222,.707,.071));
                    return col;
                }
            ENDCG
        }
    }
 
    SubShader
    {
        LOD 100
 
        Tags
        {
            "Queue" = "Transparent"
            "IgnoreProjector" = "True"
            "RenderType" = "Transparent"
        }
         
        Pass
        {
            Cull Off
            Lighting Off
            ZWrite Off
            Fog { Mode Off }
            Offset -1, -1
            ColorMask RGB
            AlphaTest Greater .01
            Blend SrcAlpha OneMinusSrcAlpha
            ColorMaterial AmbientAndDiffuse
             
            SetTexture [_MainTex]
            {
                Combine Texture * Primary
            }
        }
    }
}

敲黑板敲黑板敲黑板
图片灰化的替代法
使用两套UITexture其中一套修改其ColorTint属性即可,这样做虽然快速有效,但消耗性能和内存。
参考网址:http://bbs.9ria.com/thread-418697-1-1.html

相关文章:

  • 2022-12-23
  • 2022-01-16
  • 2022-01-10
  • 2021-11-25
  • 2022-12-23
  • 2021-09-30
  • 2021-12-23
  • 2021-06-04
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-12-20
  • 2021-10-31
  • 2022-12-23
  • 2021-08-31
  • 2022-12-23
相关资源
相似解决方案