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这个类库.它主要的功能就是处理模型从起始点到结束点之间运动的轨迹.(移动,旋转,音频,路径,摄像机等)它是一个开源 ...
随机推荐
- Educational Codeforces Round 6 F. Xors on Segments 暴力
F. Xors on Segments 题目连接: http://www.codeforces.com/contest/620/problem/F Description You are given ...
- 【web.xml】报错java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
今天搭建新的项目,虽然在web.xml中配置了ContextLoaderListener以及IntrospectorCleanupListener 如下: web.xml中部分代码: <!-- ...
- Java构造和解析Json数据的两种方法详解二——org.json
转自:http://www.cnblogs.com/lanxuezaipiao/archive/2013/05/24/3096437.html 在www.json.org上公布了很多JAVA下的jso ...
- easyui时间控件设置为可清空——jquery-easyui-1.3.3(这个版本还没有buttons,网上的好多博文都是1.3.5之后的版本)
效果图: 更改的源码jquery.easyui.min.js 11358行: var _858=$("<div class=\"datebox-button\"&g ...
- IntelliJ IDEA maven项目的基础配置
htt 选择编程风格File->Settings->Apprearance 配置maven路径,同样也是在settings Java Web项目配置 File->Project St ...
- scrapy中ROBOTSTXT_OBEY = True的相关说明
在scrapy中创建项目以后,在settings文件中有这样的一条默认开启的语句: # Obey robots.txt rules ROBOTSTXT_OBEY = True 观察代码可以发现,默认为 ...
- Node.js mm131图片批量下载爬虫1.00 iconv协助转码
//====================================================== // mm131图片批量下载爬虫1.00 // 2017年11月15日 //===== ...
- ModelAndView command
new ModelAndView("student", "command", new Student()); 对“如果在JSP中使用<form:form& ...
- ztree3.5.02选中结点时报错
ztree3.5.02选中结点时报错 更新jquery版本后,使用jquery1.1.1,左键点击Tree里的节点的时候报错,虽然不影响显示,但是在chrome控制台显示报错 Uncaught Typ ...
- hdu 4506 小明系列故事——师兄帮帮忙【幂取模乱搞】
链接: http://acm.hdu.edu.cn/showproblem.php?pid=4506 http://acm.hust.edu.cn/vjudge/contest/view.action ...