写给美术大佬的脚本,还要继续改,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. linux如何批量关闭进程

    碰到需要杀掉某一类进程的时候,如何批量杀掉这些进程,使用awk命令是很好的选择. 代码: ps -ef|grep aaa|grep -v grep|awk '{print "kill -9 ...

  2. Bootstrap table 行编辑导航

    /*开启表格编辑方向键导航 方向键(←): VK_LEFT (37) 方向键(↑): VK_UP (38) 方向键(→): VK_RIGHT (39) 方向键(↓): VK_DOWN (40) */ ...

  3. P1090 合并果子 题解

    那么,我们开始吧, 堆 堆是一个完全二叉树,而且是每层都有规律的二叉树 规律大概是: 小根堆:最上层数的大小最小,往下每层结点都比父亲结点大,比两个儿子结点小 大根堆:最上层数的大小最大,往下每层结点 ...

  4. [认证授权] 1.OAuth2授权

    1 OAuth2解决什么问题的? 举个栗子先.小明在QQ空间积攒了多年的照片,想挑选一些照片来打印出来.然后小明在找到一家提供在线打印并且包邮的网站(我们叫它PP吧(Print Photo缩写

  5. 求导程序编写(oo-java编程)

    本单元的任务为求导. 即将一个含自变量x的多项式F求导成为另外一个含自变量x的多项式f.使得 dF/dx = f 为降低我们的难度,这个任务被分解成了三个阶段: (1)对幂函数进行求导(不允许嵌套) ...

  6. 二、PHP基本语法 - PHP零基础快速入门

    我们日常生活中,有些人使用普通话交流,有些人使用家乡话.类比到计算机的世界里,PHP 是人与计算机沟通的语言之一. 既然是语言,那就必须遵循一定的语法规则.譬如 A 向 B 表白,A 会对 B 说:& ...

  7. url全部信息打印

    public String findAllContract(HttpServletRequest request,String a){ String string = new StringBuilde ...

  8. js 前端常用排序算法总结

    (冒泡排序.快排顺序.选择排序.插入排序.归并排序) 下面是前端比较常用的五个算法demo: 冒泡算法:比较两个相邻的数值,if第一个>第二个,交换他们的位置元素项向上移动至正确的顺序. fun ...

  9. 【翻译】asp.net core2.0中的token认证

    原文地址:https://developer.okta.com/blog/2018/03/23/token-authentication-aspnetcore-complete-guide token ...

  10. LinkedHashMap基本原理和用法&使用实现简单缓存(转)

    一. 基本用法LinkedHashMap是HashMap的子类,但是内部还有一个双向链表维护键值对的顺序,每个键值对既位于哈希表中,也位于双向链表中.LinkedHashMap支持两种顺序插入顺序 . ...