Example #1
0
        /// <summary>
        /// 获取当前Render 组件关联的所有材质球的Shader属性定义信息
        /// </summary>
        /// <param name="renderTarget"></param>
        /// <returns></returns>
        public GameObjectRenderPropertyInfor GetMaterialShaderProperty(Renderer renderTarget)
        {
            GameObjectRenderPropertyInfor renderPropertyInfor = new GameObjectRenderPropertyInfor();

            GetMaterialShaderProperty(renderTarget, ref renderPropertyInfor);
            return(renderPropertyInfor);
        }
Example #2
0
    // Use this for initialization
    void Start()
    {
        Debug.Log("   m_Go.GetComponent<Renderer>()=" + m_Go.GetComponent <Renderer>().material.name);
#if UNITY_EDITOR
        //***测试获取材质球属性字段
        GameObjectRenderPropertyInfor propertyInfor = ShaderUtility.Instance.GetMaterialShaderProperty(m_Go.GetComponent <Renderer>());
        Debug.Log(propertyInfor);
#endif
    }
Example #3
0
        /// <summary>
        /// 获取当前Render 组件关联的所有材质球的Shader属性定义信息
        /// </summary>
        /// <param name="renderTarget"></param>
        /// <param name="gameObjectRenderInfor"></param>
        public void GetMaterialShaderProperty(Renderer renderTarget, ref GameObjectRenderPropertyInfor gameObjectRenderInfor)
        {
            if (renderTarget == null)
            {
                return;
            }
            if (gameObjectRenderInfor == null)
            {
                gameObjectRenderInfor = new GameObjectRenderPropertyInfor();
            }
            else
            {
                gameObjectRenderInfor.ClearRenderPropertyInfor();
            }


            if (renderTarget.sharedMaterials == null || renderTarget.sharedMaterials.Length == 0)
            {
                return;
            }
            for (int dex = 0; dex < renderTarget.sharedMaterials.Length; ++dex)
            {
                #region 解析当前Render 关联的所有材质球
                MeterialPropertysInfor materialInfor = new MeterialPropertysInfor();
                materialInfor.m_MaterialIndex = dex;

                Material mat = renderTarget.sharedMaterials[dex];
                if (mat == null)
                {
                    Debug.LogEditorInfor(string.Format("Target Object : {0}  ShaderMaterial Index={1} is Null,Please Check is Right ?"));
                    gameObjectRenderInfor.AddMaterialInfor(materialInfor);
                    continue;
                }
                materialInfor.m_MeterialName = mat.name;
                #region  解析Shader中每一个定义的属性

                int shaderPropertysCount = ShaderUtil.GetPropertyCount(mat.shader);  //获取一个Shader中定义的属性个数
                for (int subIndex = 0; subIndex < shaderPropertysCount; ++subIndex)
                {
                    MaterialPropertyItem propertyItemInfor = new MaterialPropertyItem();
                    propertyItemInfor.m_PropertyIndex      = subIndex;
                    propertyItemInfor.m_PropertyName       = ShaderUtil.GetPropertyName(mat.shader, subIndex);
                    propertyItemInfor.m_ShaderPropertyEnum = ShaderPropertyType2ShaderPropertyEnum(ShaderUtil.GetPropertyType(mat.shader, subIndex));
                    propertyItemInfor.m_PropertyValue      = GetPropertyValue(mat, propertyItemInfor.m_PropertyName, propertyItemInfor.m_ShaderPropertyEnum);
                    materialInfor.AddPropertyItemInfor(propertyItemInfor.m_PropertyIndex, propertyItemInfor);

                    //**** 使用 mat.GetXXX()  接口根据不同的 ShaderPropertyType 返回一个值
                    //         Debug.LogEditorInfor(propertyItemInfor.ToString());
                }

                #endregion

                gameObjectRenderInfor.AddMaterialInfor(materialInfor);
                #endregion
            }
        }