NGUI图片闪光
先上效果
Shader
Shader "Unlit/Transparent Colored Flow Texture"
{
Properties
{
_MainTex ("Base (RGB), Alpha (A)", 2D) = "black" {}
_FlashTex("Flash (RGB), Alpha (A)", 2D) = "white" {}
_FlashColor("Flash Color", Color) = (1,1,1,0)
_Interval("Interval", Float) = 5 } SubShader
{
LOD 200 Tags
{
"Queue" = "Transparent"
"IgnoreProjector" = "True"
"RenderType" = "Transparent"
} Pass
{
Cull Off
Lighting Off
ZWrite Off
Fog { Mode Off }
Offset -1, -1
Blend SrcAlpha OneMinusSrcAlpha CGPROGRAM
#pragma vertex vert
#pragma fragment frag
#include "UnityCG.cginc" sampler2D _MainTex;
float4 _MainTex_ST;
sampler2D _FlashTex;
float4 _FlashColor;
float _Interval; struct appdata_t
{
float4 vertex : POSITION;
float2 texcoord : TEXCOORD0;
fixed4 color : COLOR;
}; struct v2f
{
float4 vertex : SV_POSITION;
half2 texcoord : TEXCOORD0;
half2 texcoord1 : TEXCOORD1;
fixed4 color : COLOR;
}; v2f o; float mymod(float x, float y)
{
return x - y * floor(x/y);
} v2f vert (appdata_t v)
{
o.vertex = mul(UNITY_MATRIX_MVP, v.vertex);
o.texcoord = v.texcoord;
o.texcoord1 = o.texcoord;
o.texcoord1.x += mymod(-_Time.w, _Interval) - 1.0f;
o.color = v.color;
return o;
} fixed4 frag (v2f IN) : COLOR
{
float4 col = tex2D(_MainTex, IN.texcoord) * IN.color; float4 flashCol = tex2D(_FlashTex,IN.texcoord1)*_FlashColor;
col.rgb = col.rgb + flashCol.rgb * flashCol.w; 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
Blend SrcAlpha OneMinusSrcAlpha
ColorMaterial AmbientAndDiffuse SetTexture [_MainTex]
{
Combine Texture * Primary
}
}
}
}
脚本
using UnityEngine;
using System.Collections; /*-------------------------------------------------------------------
Copyright 2015 Minty Game LTD. All Rights Reserved.
Maintained by bailu
-------------------------------------------------------------------
bailu 2016-01-26 14:45:52
带流光的UITexture
*/ [ExecuteInEditMode]
[RequireComponent(typeof(UITexture))]
public class UIFlowTexture : MonoBehaviour { //流光颜色
[SerializeField]
private Texture FlowTexture = null; //流光时间间隔
[SerializeField]
private float Interval = 5f; //流光颜色
[SerializeField]
private Color FlowColor = Color.white; //被流光的UITexture
private UITexture mUITexture; void Awake()
{
mUITexture = gameObject.GetComponent<UITexture>();
} // Use this for initialization
void Start ()
{
ResourceManager.PrepareResource<Material>(Resource.Dir.Material + "UITexture_Flow.mat", material =>
{
mUITexture.material = new Material(material);
RefreshMaterialProperty();
});
} [ContextMenu("Refresh Material Property")]
public void RefreshMaterialProperty()
{
var mat = mUITexture.material;
if(null==mat)
{
return;
} if(null!=FlowTexture)
{
mat.SetTexture("_FlashTex", FlowTexture);
} mat.SetFloat("_Interval", Interval); mUITexture.MarkAsChanged();
} }
搞法:
1、创建个材质命名成UITexture_Flow.mat,把上面的shader拖拽进去。
2、创建GameObject,挂上UITexture(不用修改的材质,原因是我代码里会去修改他的材质。为什么总是new 新的材质,原因是每个UITexture都要自己流动自己的)
3、然后再挂上UITextureFlow,设置流光的参数
注意:如果你放ScrollView下发现裁剪不正确,那就按照NGUI的shader规则,增加XXX 1.shader,XXX 2.shader。
NGUI图片闪光的更多相关文章
- css实现图片闪光效果
1.这个效果是看到京东商城上的一个下效果,原本的思路是 用js控制一个图片在某张需要闪光的图片上重复出现,但是 网上找了一些资料,竟然是用css写的,真是太帅了!!! 2.原理:在需要闪光的图片前添加 ...
- NGUI图片字(Bitmap图片转文字)
用图片字而不是图片 美术和程序的配合,需要程序能够很快抓住问题重点并提出解决方案.美术出的图片字比我们使用的字体更好好看,那么是否要一个个图片去拼成数字呢? NGUI创建图片字 准备材料 美术提供的数 ...
- 关于Unity3D中Resources动态加载NGUI图片的方法
在NGUI中有些图片我需要动态进行变更或者加载,怎么办? 首先在项目中创建一个Resources目录,接着把需要的图片放在这里面,可以有子文件夹么?当然可以,文件结构很重要哦~ NGUI加载图片的方法 ...
- 关于Unity中NGUI图片精灵响应鼠标的方法
我在Unity里做NGUI的时候发现一个问题. 在Unity2D场景当中,一个精灵图片只要加上了Box Collider或者Box Collider2D,就可以相应OnMouseEnter和OnMou ...
- 使用CSS3线性渐变实现图片闪光划过效果
<p class="overimg"> <a><img src="http://www.nowamagic.net/librarys/ima ...
- NGUI 图片变灰
效果图 1.先准备好一个变灰shader.代码如下 Shader "Custom/Gray" { Properties { _MainTex ("Base (RGB), ...
- css3划过图片闪光
css代码 01 .img { display:block; position: relative; width:800px; height:450px; margin:0 auto;} 02 .im ...
- 【CSS3】使用CSS3线性渐变实现图片闪光划过效果(转)
原文:http://www.nowamagic.net/librarys/veda/detail/2600 资料参考: http://www.cnblogs.com/lhb25/archive/201 ...
- 整理六百篇web前端知识混总
9个有用的和免费的工具来支持动态网页开发 8个基本的引导工具的网页设计师 11款CSS3动画工具的开发 2016年某前端群题目答案参考 9最好的JavaScript压缩工具 创建响应式布局的10款优秀 ...
随机推荐
- 获取SQLSERVER所有库 所有表 所有列 所有字段信息
最近想起来做一个项目代码生成器,直接生成底层代码.. 这免不了要先行读取数据库已有的信息.. 废话不多说..开整.. SELECT NAME FROM MASTER..SYSDATABASES --读 ...
- Java调试
线上load高的问题排查步骤是: 先用top找到耗资源的进程 ps+grep找到对应的java进程/线程 jstack分析哪些线程阻塞了,阻塞在哪里 jstat看看FullGC频率 jmap看看有没有 ...
- ls按时间排序输出文件列表
文件转自:http://www.2cto.com/os/201303/197829.html ls按时间排序输出文件列表 首先,ls --help查看ls相关的与时间排序相关的参数: > ...
- php怎么获取mac地址?
如何用php获取mac地址呢?大家知道mac地址是电脑在全球范围的唯一标识,所以这个就非常实用,比如说要做一个投票功能,那mac地址是必不可少 的,如果单纯的靠ip地址来判断这个肯定是不准确的,水分太 ...
- django view
当请求一个页面时,Django 创建一个包含有关请求数据的 HttpRequest 对象,并将它作为第一个参数传给视图函数,每个视图函数处理完相应逻辑后返回一个 HttpResponse 对象,Htt ...
- 一行代码解决各种IE兼容问题IE8,IE9,IE10
一:一.指定文件兼容性模式(Xee:因为我已经放弃IE6,7了,所以以后设计的网页最低支持IE8;) 要为你的网页指定文件模式,需要在你的网页中使用meta元素放入X-UA-Compatible ht ...
- linux压缩排除
tar -zcvf www/la.tar.gz --exclude=www/uploadfile --exclude=www/databases --exclude=www/web_logs www ...
- github及其他记录
http://mvnrepository.com/artifact/org.jdom/jdom/1.1.3 https://github.com/open-power-workgroup/Hospit ...
- SQL 语句-partition by
/****** ******/ 初始化数据 create table employee (empid int ,deptid int ,salary decimal(10,2)) insert int ...
- 用数组求Fibonacci数列
#include<stdio.h>int main(){ int a[20]={1,1}; int n=2,i; for(n=2;n<20;n++) ...