unity, itween 对不透明对象使用FadeTo需要先更换material
跟自己实现fade一样,使用itween对不透明对象FadeTo前也要先更换material为透明material。
设player的Hierarchy如下:
player
--aniRoot
----head
----body
其中head和body都挂有如下脚本:
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Assertions.Must;
public class materialControl : MonoBehaviour {
public List<string> m_keyList;
public List<Material> m_matList;
private Dictionary<string,Material> m_matDic=new Dictionary<string, Material>();//dictionary will not show in inspeactor
void Awake(){
int keyCount = m_keyList.Count;
int matCount = m_matList.Count;
keyCount.MustBeEqual(matCount);
for (int i=0; i<keyCount; i++) {
string key=m_keyList[i];
Material mat=m_matList[i];
m_matDic.Add (key,mat);
}
}
public Material getMaterialByKey(string key){
Material mat=null;
bool isGot=m_matDic.TryGetValue (key,out mat);
if (isGot) {
return mat;
} else {
return null;
}
}
public void changeMaterialTo(string key){
Material mat=getMaterialByKey (key);
if (mat) {
GetComponent<MeshRenderer> ().material = mat;
} else {
Debug.Log("error: material not found!");
}
}
}
player挂有如下脚本:
using UnityEngine;
using System.Collections;
using UnityEngine.Assertions.Must;
public class playerControl : MonoBehaviour {
void fadeOut(){
Transform aniRoot = transform.FindChild ("aniRoot");
Transform[] allChildren = aniRoot.GetComponentsInChildren<Transform> ();
foreach (Transform child in allChildren) {
materialControl materialControlScript = child.GetComponent<materialControl> ();
if (materialControlScript) {
materialControlScript.changeMaterialTo ("fadeMat");
}
}
//ref: http://www.xuanyusong.com/archives/2052
Hashtable args = new Hashtable();
args.Add("alpha",0);
args.Add("time",0.2f);
args.Add ("oncomplete", "disActive");
args.Add("oncompleteparams", gameObject);
args.Add("oncompletetarget", gameObject);
iTween.FadeTo (aniRoot.gameObject, args);
}
void disActive(GameObject target){
target.SetActive (false);
}
......
}
unity, itween 对不透明对象使用FadeTo需要先更换material的更多相关文章
- unity, itween, closed path
- 【Unity Shaders】Diffuse Shading——向Surface Shader添加properties
本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源 ...
- Unity Glossary
https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...
- 网格导入设置 Import settings for Meshes
原地址:http://game.ceeger.com/Components/FBXImporter-Model.html The Import Settings for a model file wi ...
- iTween for Unity
你曾经在你的游戏中制作过动画吗?问这个问题可能是愚蠢的,几乎每个Game都有动画,虽然有一些没有,但你必须处理有动画和没有动画.让我们结识 ITween. iTween 官方网站:http://itw ...
- 【转】iTween for Unity
http://www.cnblogs.com/zhaoqingqing/p/3833321.html?utm_source=tuicool&utm_medium=referral 你曾经在你的 ...
- unity开源移动库iTween使用完整Demo
public Vector3[] paths; // Use this for initialization void Start () { paths = ] { , , ), , , -) }; ...
- Unity路径规划
Unity路径规划 转自:http://www.cnblogs.com/zsb517/p/4090629.html 背景 酷跑游戏中涉及到弯道.不规则道路. 找来一些酷跑游戏的案例来看,很多都是只有 ...
- iTween研究院之学习笔记Move移动篇
最近项目中需要加入一些模型移动的小动画,学习过程中发现了iTween这个类库.它主要的功能就是处理模型从起始点到结束点之间运动的轨迹.(移动,旋转,音频,路径,摄像机等)它是一个开源 ...
随机推荐
- Eclipse运行Maven的SpringMVC项目Run on Server时出现错误:Error configuring application listener of class org.springframework.web.context.ContextLoaderListener的问题解决
错误: 严重: Error configuring application listener of class org.springframework.web.context.ContextLoade ...
- mysql设置远程访问密码
mysql -u root -p Aaa111222 grant all privileges on *.* to root@'%' identified by 'aaa111222; Quit ln ...
- 回顾苹果操作系统Mac OS的发展历史
在新的MacBook AIR和Mac OS X Lion即将发布之际,我们仅以此文向伟大的苹果和乔布斯致敬.并祝Apple教主乔布斯早日康复,长命百岁,千秋万载,一统苹果! Mac OS是指运行于苹果 ...
- OpenCV腐蚀与膨胀(Eroding and Dilating)
腐蚀与膨胀(Eroding and Dilating) 目标 本文档尝试解答如下问题: 如何使用OpenCV提供的两种最基本的形态学操作,腐蚀与膨胀( Erosion 与 Dilation): ero ...
- [转]Working with Transactions (EF6 Onwards)
本文转自:http://www.cnblogs.com/xiepeixing/p/5275999.html Working with Transactions (EF6 Onwards) This d ...
- iOS:iOS中的几种动画
本文来自收藏,感谢原创博主. iOS中的动画 摘要 本文主要介绍核iOS中的动画:核心动画Core Animation, UIView动画, Block动画, UIImageView的帧动画. 核心动 ...
- 对Storm ETL的初步思考
ETL简介 ETL,是英文 Extract-Transform-Load 的缩写,用来描述将数据从来源端经过萃取(extract).转置(transform).加载(load)至目的端的过程. ETL ...
- Centos6.8配置svn
svn的安装:yum -y install subversion 一.一个仓库放所有的项目 创建仓库,以后所有代码都放在这个下面,创建成功后在svn下面多了几个文件夹.1.创建仓库:svnadmin ...
- jQuery选取表单元素
表单元素选择器 选择器 说明 :button <button>元素和type属性值为button的<input& ...
- C++ Primer笔记2_四种类型转换_异常机制
1.类型转换 命名的强制类型转换: 有static_cast.dynamic_cast.const_cast.reinterpret_cast static_cast: 编译器隐式运行的不论什么类型转 ...