U3D 中 Image的渐变加载
程序员文章站
2022-04-28 15:34:59
...
啦啦啦,啦啦啦,最近项目中可能有这个新的需求,碰巧今天遇到一大佬分享的博客....
略微有些小的改动诺...
private List<Sprite> storeTexture;
public Image logo;
private Sprite texture;
public void Start()
{
storeTexture = new List<Sprite>();
storeTexture.Clear();
//加载图片并储存在List中
for (int i = 1; i < 4; i++)
{
texture = Resources.Load<Sprite>("logo" + i);
storeTexture.Add(texture);
}
//遍历List中物体并打印出名字
foreach (var kk in storeTexture)
{
Debug.LogError(kk.name);
}
}
private float Timer = 0;
private float value = 3;
public void Update()
{
//Logo1从透明变为不透明状态
if (logoSwtich == LogoSwtich.Start)
{
Timer += Time.deltaTime / value;
logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
if (Timer >= 1)
{
logoSwtich = LogoSwtich.DeleteLogo1Alpha;
}
}
//Logo1从不透明变为透明状态
if (logoSwtich == LogoSwtich.DeleteLogo1Alpha)
{
Timer -= Time.deltaTime / value;
logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
if (Timer <= 0)
{
logoSwtich = LogoSwtich.ChangeLogo2;
}
}
//将Logo1更换为Logo2
if (logoSwtich == LogoSwtich.ChangeLogo2)
{
logo.GetComponent<Image>().sprite = storeTexture[0];
logoSwtich = LogoSwtich.AddLogo2Alpha;
}
//Logo2从透明变为不透明状态
if (logoSwtich == LogoSwtich.AddLogo2Alpha)
{
Timer += Time.deltaTime / value;
logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
if (Timer >= 1)
{
logoSwtich = LogoSwtich.DeleteLogo2Alpha;
}
}
//Logo1从不透明变为透明状态
if (logoSwtich == LogoSwtich.DeleteLogo2Alpha)
{
Timer -= Time.deltaTime / value;
logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
if (Timer <= 0)
{
logoSwtich = LogoSwtich.ChangeLogo3;
}
}
//将Logo2更换为Logo3
if (logoSwtich == LogoSwtich.ChangeLogo3)
{
logo.GetComponent<Image>().sprite = storeTexture[1];
logoSwtich = LogoSwtich.AddLogo3Alpha;
}
//Logo3从透明变为不透明状态
if (logoSwtich == LogoSwtich.AddLogo3Alpha)
{
Timer += Time.deltaTime / value;
logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
if (Timer >= 1)
{
logoSwtich = LogoSwtich.DeleteLogo3Alph;
}
}
//Logo3从不透明变为透明状态
if (logoSwtich == LogoSwtich.DeleteLogo3Alph)
{
Timer -= Time.deltaTime / value;
logo.GetComponent<Image>().color = new Color(1, 1, 1, Timer);
if (Timer <= 0)
{
logoSwtich = LogoSwtich.ChangeLogo1;
}
}
//将Logo3更换为Logo1
if (logoSwtich == LogoSwtich.ChangeLogo1)
{
logo.GetComponent<Image>().sprite = storeTexture[2];
logoSwtich = LogoSwtich.Start;
}
}
LogoSwtich logoSwtich = LogoSwtich.ChangeLogo2;
//Logo图片切换状态
public enum LogoSwtich
{
Start,
DeleteLogo1Alpha,
ChangeLogo2,
AddLogo2Alpha,
DeleteLogo2Alpha,
ChangeLogo3,
AddLogo3Alpha,
DeleteLogo3Alph,
ChangeLogo1,
End
}
记得添加引用哦...
Nice
上一篇: 记一次性能优化,限制tcp_timewait数量,快速回收和重用
下一篇: PHP禁止页面缓存的代码
推荐阅读
-
ps中渐变映射调整图层如何定义及其各项参数的使用技巧
-
在JavaScript应用中实现延迟加载的方法
-
Element中的Cascader(级联列表)动态加载省\市\区数据的方法
-
flash中怎么制作红黑两色逐渐变成两色太极图像的动画?
-
Winform中实现根据配置文件重新加载ZedGraph属性的实现思路
-
webpack中的热刷新与热加载的区别
-
使用css3背景渐变中的透明度来设置不同颜色的背景渐变
-
Asp.Net 将HTML中通过dom-to-image.js标签div内的内容转化为图片保存到本地
-
PHP中的自动加载操作实现方法详解
-
使用Python PIL库中的Image.thumbnail函数裁剪图片