写给美术大佬的脚本,还要继续改,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. 随机IP

    function rand_ip(){ $ip_longs = array( array('607649792', '608174079'),        //36.56.0.0-36.63.255 ...

  2. LeetCode算法题-Min Cost Climbing Stairs(Java实现)

    这是悦乐书的第307次更新,第327篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第176题(顺位题号是746).在楼梯上,第i步有一些非负成本成本[i]分配(0索引). ...

  3. CentOS 7 MySql 解压版安装配置

    下载 访问www.mysql.com 点击DOWNLOADS-->Community-->MySQL Community Server 选择要下载的版本,目前可选择的有:5.5.5.6.5 ...

  4. EasyUI之DataGird动态组合列

    Dojo.ExtJS.Jquery(EasyUI.jQgrid.ligerui.DWZ).还有asp.net中的服务器控件.当然也少不了HTML 标签之table标签了.其中dojo.ExtJS.Jq ...

  5. eclipse java formater 配置详解

    comment.insert_new_line_before_root_tags(insert/do_not_insert):在Javadoc根标记块前插入空行,默认为insert: insert_s ...

  6. 你的知识需要管理PKM

    有一段时间没有更新技术博客了~,大脑中总感觉有点东西要写,却不知道从哪里开始写~至少写点东西,也算是一个阶段的成长.反思~ 学习(充电过程).工作(知识变现过程)不是简单重复,永远都是最值得去反思.玩 ...

  7. [LeetCode] 19. 删除链表的倒数第N个节点

    题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/ 题目描述: 给定一个链表,删除链表的倒数第 n 个节点, ...

  8. 《css世界》笔记之流、元素与基本尺寸

    1. 块级元素 基本特性:就是一个水平流上只能单独显示一个元素,多个块级元素则换行显示. 块级元素和"display 为block 的元素"不是一个概念,display:list- ...

  9. vue学习初探

    一.环境的搭建安装 VS Code vue开发环境的搭建 理解vue的脚手架 合适的cnpm版本

  10. Vue 环境搭建(win10)

    1.安装node node官网安装地址 推荐安装稳定版本(LTS)以及安装路径为系统盘(C) 查看node安装成功否 注释:以下命令使用 命令提示符(管理员)权限,win10 对user权限的限制了访 ...