GameFramework.EntityViewModel.Hide C# (CSharp) Method

Hide() public method

隐身效果切换
public Hide ( bool hide, bool bNPC = false ) : void
hide bool
bNPC bool
return void
        public void Hide(bool hide,bool bNPC = false)
        {
            if ((m_isHidden && hide) || (!m_isHidden && !hide))
                return;
            GameObject obj = m_Actor;
            //obj.layer = 1 << LayerMask.NameToLayer("DeActive"); //(!hide);

            if (!hide)
            {

                int ct = m_Materials.Count;
                if (m_Shaders.Count != ct || m_Colors.Count != ct)
                {
                    GameFramework.LogSystem.Error("replaceshaderandfadecolor materials num is not equal shaders num !");
                    return;
                }
                for (int i = 0; i < ct; ++i)
                {
                    m_Materials[i].shader = m_Shaders[i];
                    if (m_Materials[i].HasProperty("_Color"))
                    {
                        m_Materials[i].color = m_Colors[i];
                    }
                }
                m_Materials.Clear();
                m_Shaders.Clear();
                m_Colors.Clear();
                m_isHidden = false;
            }
            else
            {
                if (m_Materials.Count <= 0)
                {
                    Renderer[] renderers = obj.GetComponentsInChildren<Renderer>();
                    if (null != renderers)
                    {
                        for (int i = 0; i < renderers.Length; ++i)
                        {
                            Material mat = renderers[i].material;
                            m_Shaders.Add(mat.shader);
                            if (mat.HasProperty("_Color"))
                            {
                                m_Colors.Add(mat.color);
                            }
                            else
                            {
                                m_Colors.Add(Color.white);
                            }
                            m_Materials.Add(mat);
                        }
                    }
                }
                if (m_Materials.Count > 0)
                {
                    for (int i = 0; i <m_Materials.Count ; ++i)//
                    //现在把粒子绑在了骨骼上,不能直接修改所有材质,否则在受击时,进入隐身状态,所带受击粒子也会进行材质的改变 形成一个黑片
                    {
                        Material mat = m_Materials[i];
                        if (mat.shader.name == "Tut/Shader/Toon/toon" || mat.shader.name == "Mobile/Diffuse"||mat.shader.name == "LOLL/Toon/toonwithStencil")
                        { }
                        else
                        {
                            continue;
                        }

                        mat.shader = Shader.Find("Legacy Shaders/Transparent/Diffuse");
                        if (bNPC)
                        {
                            mat.color = new Color(1, 1, 1, 0.0f);
                        }
                        else
                        {
                            mat.color = new Color(1, 1, 1, 0.3f);
                        }

                    }
                }
                m_isHidden = true;
            }
        }

Usage Example

 static public int Hide(IntPtr l)
 {
     try {
         GameFramework.EntityViewModel self = (GameFramework.EntityViewModel)checkSelf(l);
         System.Boolean a1;
         checkType(l, 2, out a1);
         System.Boolean a2;
         checkType(l, 3, out a2);
         self.Hide(a1, a2);
         pushValue(l, true);
         return(1);
     }
     catch (Exception e) {
         return(error(l, e));
     }
 }