跟自己实现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的更多相关文章

  1. unity, itween, closed path

  2. 【Unity Shaders】Diffuse Shading——向Surface Shader添加properties

    本系列主要参考<Unity Shaders and Effects Cookbook>一书(感谢原书作者),同时会加上一点个人理解或拓展. 这里是本书所有的插图.这里是本书所需的代码和资源 ...

  3. Unity Glossary

    https://docs.unity3d.com/2018.4/Documentation/Manual/Glossary.html 2D terms 2D Physics terms AI term ...

  4. 网格导入设置 Import settings for Meshes

    原地址:http://game.ceeger.com/Components/FBXImporter-Model.html The Import Settings for a model file wi ...

  5. iTween for Unity

    你曾经在你的游戏中制作过动画吗?问这个问题可能是愚蠢的,几乎每个Game都有动画,虽然有一些没有,但你必须处理有动画和没有动画.让我们结识 ITween. iTween 官方网站:http://itw ...

  6. 【转】iTween for Unity

    http://www.cnblogs.com/zhaoqingqing/p/3833321.html?utm_source=tuicool&utm_medium=referral 你曾经在你的 ...

  7. unity开源移动库iTween使用完整Demo

    public Vector3[] paths; // Use this for initialization void Start () { paths = ] { , , ), , , -) }; ...

  8. Unity路径规划

    Unity路径规划  转自:http://www.cnblogs.com/zsb517/p/4090629.html 背景 酷跑游戏中涉及到弯道.不规则道路. 找来一些酷跑游戏的案例来看,很多都是只有 ...

  9. iTween研究院之学习笔记Move移动篇

             最近项目中需要加入一些模型移动的小动画,学习过程中发现了iTween这个类库.它主要的功能就是处理模型从起始点到结束点之间运动的轨迹.(移动,旋转,音频,路径,摄像机等)它是一个开源 ...

随机推荐

  1. Android编程实用代码合集

    1.android dp和px之间转换public class DensityUtil { /** * 根据手机的分辨率从 dip 的单位 转成为 px(像素) */ public static in ...

  2. [转]解决Eclipse更新ADT插件时遇到的Eclipse reports rendering library more recent than ADT plug-in问题

    使用 SDK Manager 工具更新下载新版本后,无法显示可视化布局,同时提示 This version of the rendering library is more recent than y ...

  3. 如何Oracle查出一个用户具有的所有系统权限和对象权限

    1. 系统权限 SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE = 'LCAM_SYS_1216' UNION ALL SELECT * FROM DBA_SYS_ ...

  4. Android Killer

    首先,我们先看一Android界有名的大神写关于Android反编译的博客: 郭 大 侠:http://blog.csdn.net/guolin_blog/article/details/497380 ...

  5. 在Windows Server 2008 R2上安装Exchange 2013过程中遇到的一些问题

    笔者对Exchange经验非常有限, 但也正因为如此, 这里分享的东西对从没接触过Exchange的朋友会有更多的帮助吧, 至少希望如此.   1. Exchange 2013的安装需要.net fr ...

  6. PLSQL Developer连接远程Oracle方法(非安装client)

    远程连接Oracle比較麻烦,通常须要安装oracle的客户端才干实现. 通过instantclient能够比較简单的连接远程的Oracle. 1.新建文件夹D:\Oracle_Cleint用于存放相 ...

  7. [Angular] AfterContentChecked && AfterViewChecked

    AfterContentChecked & AfterViewChecked are called after 'OnChanges' lifecycle. And each time 'ng ...

  8. 关于configure和Makefile

    http://blog.csdn.net/lltaoyy/article/details/7615833 转篇文章,讲的不是很清楚,再附上几个资料连接,来自http://www.linuxdw.com ...

  9. Spring Boot环境下自定义shiro过滤器会过滤所有的url的问题

    在配置shiro过滤器时增加了自定义的过滤器,主要是用来处理未登录状态下返回一些信息 //自定义过滤器 Map<String, Filter> filtersMap = new Linke ...

  10. Linux中查看jdk安装目录、Linux卸载jdk、rpm命令、rm命令参数

    一.查看jdk安装目录 [root@node001 ~]# whereis java java: /usr/bin/java /usr/local/java #java执行路径 [root@node0 ...