写给美术大佬的脚本,还要继续改,github地址:TransEffect【github】

效果图如下:

Ver.1源码,针对3d Object:

using System.Collections;
using System.Collections.Generic;
using UnityEngine; public class TransEffect : MonoBehaviour
{ public List<GoInfo> GoList;
public float varifySpeed = 0.5f;
public float aTime = 5f;//每个物体保持出现的时间
public float dTime = 5f; private float minAlpha = 0.0f;
private float maxAlpha = .9f;
private float curAlpha = 1.0f;
private float nextAlpha = 0.0f;
private int i = ; public void OnEnable()
{
LoadGo();
} // Use this for initialization
void Start()
{
//初始化全List隐形
foreach (GoInfo go in GoList)
{
Color c = go.rend.material.color;
c.a = ;
go.rend.material.color = c; }
} // Update is called once per frame
public void Update()
{
Trans();
} void LoadGo()
{
GoList = new List<GoInfo>();
GoList.Add(new GoInfo("Cylinder", , transform.Find("Cylinder").GetComponent<GameObject>(), transform.Find("Cylinder").GetComponent<MeshRenderer>()));
GoList.Add(new GoInfo("Cube", , transform.Find("Cube").GetComponent<GameObject>(), transform.Find("Cube").GetComponent<MeshRenderer>()));
GoList.Add(new GoInfo("Sphere", , transform.Find("Sphere").GetComponent<GameObject>(), transform.Find("Sphere").GetComponent<MeshRenderer>()));
GoList.Add(new GoInfo("Capsule", , transform.Find("Capsule").GetComponent<GameObject>(), transform.Find("Capsule").GetComponent<MeshRenderer>()));
} private void Trans()
{
GoInfo go = GoList[i];
GoInfo nextgo;
Color c = go.rend.material.color;
Color nextc = go.rend.material.color; if (i <= GoList.Count)
{
if (i == GoList.Count - )
{
nextgo = GoList[];
}
else
{
nextgo = GoList[i + ];
} Debug.Log(nextAlpha);
Debug.Log(curAlpha); if (Time.time < aTime)//当前物体保持显形
{
c.a = ;
go.rend.material.color = c;
}
else if (Time.time >= aTime)
{
curAlpha += Time.deltaTime * varifySpeed * (-);//当前物体逐渐消失
nextAlpha += Time.deltaTime * varifySpeed;//下一个物体逐渐现形 if (curAlpha <= minAlpha)//当前物体渐变到不透明时
{
c.a = ;//设置当前obj保持透明
go.rend.material.color = c;
i++;
//设置数据为下一物体做准备
curAlpha = ;
nextAlpha = ;
} else//当前物体逐渐透明,下一物体逐渐现形
{
curAlpha = Mathf.Clamp(curAlpha, minAlpha, maxAlpha);
nextAlpha = Mathf.Clamp(nextAlpha, minAlpha, maxAlpha);
c.a = curAlpha;
nextc.a = nextAlpha;
go.rend.material.color = c;
nextgo.rend.material.color = nextc; } if (curAlpha >= maxAlpha)//下一物体完全显形
{
Debug.Log(nextAlpha);
Debug.Log(curAlpha);
aTime = Time.time + dTime; //设置新一轮时间限制
Debug.Log(aTime); }
}
}
else
{
i = ;
}
} } [System.Serializable]
public class GoInfo
{
public string ID;
public int index;
public MeshRenderer rend;
public GameObject[] obj;
public GameObject curObj;
private Color co; public GoInfo(string id0, int index0, GameObject obj0, MeshRenderer rend0)
{
ID = id0;
index = index0;
curObj = obj0;
rend = rend0; } }

创建物体:

写完才发现是要用在UI Image上的...不过其实差别也不大,还略简单点。

Ver.2源码,针对UI Image:

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI; public class TransEffect : MonoBehaviour
{
public Transform lib;
public List<GoInfo> GoList;
public float varifySpeed = 0.5f;
public float aTime = 5f;//每个物体保持出现的时间
public float dTime = 5f;//第一张图片第一轮循环时出现时间 private float minAlpha = 0.0f;
private float maxAlpha = .9f;
private float curAlpha = 1.0f;
private float nextAlpha = 0.0f;
private int i = ; public void OnEnable()
{
LoadGo();
} // Use this for initialization
void Start()
{
//初始化全List隐形
foreach (GoInfo go in GoList)
{
Color c = go.curImg.color;
c.a = ;
go.curImg.color = c; }
} // Update is called once per frame
public void Update()
{
Trans();
} void LoadGo()
{
//添加图片列表
GoList = new List<GoInfo>();
for (int i = ; i < lib.childCount; i++) {
GoList.Add(new GoInfo(lib.GetChild(i).name.ToString(),lib.transform.GetChild(i).GetComponent<Image>()));
}
Debug.Log(GoList.Count);
} private void Trans()
{ Debug.Log(i);
GoInfo go;
GoInfo nextgo; if (i >= GoList.Count - )
{
go = GoList[i];
nextgo = GoList[];
}
else
{
go = GoList[i];
nextgo = GoList[i + ];
} Color c = go.curImg.color;
Color nextc = go.curImg.color; if (Time.time < aTime)//当前物体保持显形
{
c.a = ;
go.curImg.color = c;
}
else if (Time.time >= aTime)
{
curAlpha += Time.deltaTime * varifySpeed * (-);//当前物体逐渐消失
nextAlpha += Time.deltaTime * varifySpeed;//下一个物体逐渐现形 if (curAlpha <= minAlpha)//当前物体渐变到不透明时
{
c.a = ;//设置当前obj保持透明
go.curImg.color = c; if (i == GoList.Count - )
i = -;
i++; //设置数据为下一物体做准备
curAlpha = ;
nextAlpha = ;
} else//当前物体逐渐透明,下一物体逐渐现形
{
curAlpha = Mathf.Clamp(curAlpha, minAlpha, maxAlpha);
nextAlpha = Mathf.Clamp(nextAlpha, minAlpha, maxAlpha);
c.a = curAlpha;
nextc.a = nextAlpha;
go.curImg.color = c;
nextgo.curImg.color = nextc; } if (curAlpha >= maxAlpha)//下一物体完全显形
{
aTime = Time.time + dTime; //设置新一轮时间限制
}
} } } [System.Serializable]
public class GoInfo
{
public string ID;
public Image[] imgList;
public Image curImg; private Color co; public GoInfo(string id0,Image img)
{
ID = id0;
curImg = img;
} }

直接把存放图片子物体的父物体拖到Lib变量中,再调整所需渐变速度和显示时间即可。

设置如下:

【over】

【Unity】透明度渐变的更多相关文章

  1. android 背景透明度渐变动画

    button.setVisibility(View.VISIBLE); // 背景透明度渐变动画 ObjectAnimator alpha = ObjectAnimator.ofFloat(butto ...

  2. Android 旋转、平移、缩放和透明度渐变的补间动画

    补间动画就是通过对场景里的对象不断进行图像变化来产生动画效果.在实现补间动画时,只需要定义开始和结束的“关键帧”,其他过渡帧由系统自动计算并补齐.在Android中,提供了以下4种补间动画. **1. ...

  3. view渐变色,透明度渐变

    1 功能描述 开发中经常遇到这样的需求:view2显示在view1上面,透过view2可以渐渐的看到view1.效果如图1所示:view1是一个imageView,view2是一个普通view.vie ...

  4. Duilib 实现右下角弹出像QQ新闻窗口,3秒后窗口透明度渐变最后关闭,若在渐变过程中鼠标放到窗口上,窗口恢复最初状态(二)

    效果: 1.定义两个个定时器ID #define ID_TIMER_DISPLAY_DELAY 30 #define ID_TIMER_DISPLAY_CLOSE 40 2.添加一个成员函数和成员变量 ...

  5. iOS中为控件设置颜色渐变和透明度渐变

    项目中用到地图设置渐变色,查找资料找到两种方法:一种设置颜色,一种设置透明度: //为颜色设置渐变效果: UIView *view = [[UIView alloc] initWithFrame:CG ...

  6. css3颜色+透明度渐变

    .linear { width: 630px; height: 120px; line-height: 150px; text-align: center; font-size: 26px; posi ...

  7. Android之绚丽的图片游览效果--有点像W7效果,透明的倒影,层叠的图片,渐变的颜色透明度

    这里转载一个牛人的博客:http://www.cnblogs.com/tankaixiong/archive/2011/02/24/1964340.html 下面,是我参照他的博客实现的一个效果图.这 ...

  8. JS实现简单的图片透明度循环变化(渐变)

    找了好多,都是由100到0就结束了,到头来自己魔改,以下就是源码. div中加入img,js添加函数,完事(调用),取名后面加个1是为了避免冲突 <!DOCTYPE HTML> <h ...

  9. Unity Shader 知识点总结(二)

    紧接着上一篇文章的shader入门知识的总结,本文主要总结shader中的纹理贴图.透明度混合.顶点动画.后期特效处理等操作.如果有什么地方有错,请指出更正,谢谢.本文的代码主要来自开源书:unity ...

随机推荐

  1. 关于executemany()方法在不同OS和DB API下的不同表现的测试

    昨天在参照着网上写一段关于MySQL连接池的配合gevent多线程调用的代码时遇到了一个问题,自己写的代码根本不能多线程执行,比单会话插入数据慢太多,直到今天早上才发现问题所在,把DB API从MyS ...

  2. Postgresql数据库部署之:Postgresql 存在session 会话不能删除数据库

    SELECT pg_terminate_backend(pid) FROM pg_stat_activity WHERE datname='数据库名' AND pid<>pg_backen ...

  3. Ubuntu 16.04 安装Google 浏览器

    Ubuntu安装好后,自带Firefox浏览器,有时我们需要再安装几个浏览器,那么Google Chrome,就是首选, 安装如下: 下载浏览器安装包, 下载链接:https://dl.google. ...

  4. 分布式存储ceph——(3)ceph常用命令

    1.查看ceph集群配置信息 1 ceph daemon /var/run/ceph/ceph-mon.$(hostname -s).asok config show   2.在部署节点修改了ceph ...

  5. form单选框

    form中的单选框: var resultStartRadio = new Ext.form.RadioGroup({ id : 'resultStartRadio', name :"for ...

  6. maven:私服的相关配置

    添加到settings.xml中 <server> <id>releases</id> <username>admin</username> ...

  7. CF51C Three Base Stations

    https://codeforces.com/problemset/problem/51/C 题目 The New Vasjuki village is stretched along the mot ...

  8. 【DeepLearning】优化算法:SGD、GD、mini-batch GD、Moment、RMSprob、Adam

    优化算法 1 GD/SGD/mini-batch GD GD:Gradient Descent,就是传统意义上的梯度下降,也叫batch GD. SGD:随机梯度下降.一次只随机选择一个样本进行训练和 ...

  9. 【DeepLearning】深入理解dropout正则化

    本文为转载,作者:Microstrong0305 来源:CSDN 原文:https://blog.csdn.net/program_developer/article/details/80737724 ...

  10. leanote折腾指南

    持续更新. 过几天把自己的修改好的css放到github上给大家参考. https://github.com/whuwangyong/leanote-conf TODO leanote Linux/W ...