public object CreateConverter(MaterialEditor editor)
        {
            StandardMaterialValueConverter converter = new StandardMaterialValueConverter();

            converter.Material = editor.Material;
            return(converter);
        }
        public object GetValue(StandardMaterialValueConverter[] converters, Func <StandardMaterialValueConverter, object> getter)
        {
            if (converters == null || converters.Length == 0 || converters[0] == null)
            {
                return(null);
            }

            object val = getter(converters[0]);

            for (int i = 1; i < converters.Length; ++i)
            {
                StandardMaterialValueConverter converter = converters[i];
                if (converter == null)
                {
                    return(null);
                }

                object val2 = getter(converter);
                if (!Equals(val, val2))
                {
                    return(null);
                }
            }

            return(val);
        }
 public void EraseAccessorTarget(object accessorRef, object target)
 {
     if (accessorRef is StandardMaterialValueConverter)
     {
         StandardMaterialValueConverter accessor = (StandardMaterialValueConverter)accessorRef;
         accessor.Material = target as Material;
     }
     else if (accessorRef is MaterialPropertyAccessor)
     {
         MaterialPropertyAccessor accessor = (MaterialPropertyAccessor)accessorRef;
         accessor.Material = target as Material;
     }
 }
 public object CreateConverter(MaterialEditor editor)
 {
     object[]   converters = new object[editor.Materials.Length];
     Material[] materials  = editor.Materials;
     for (int i = 0; i < materials.Length; ++i)
     {
         Material material = materials[i];
         if (material != null)
         {
             converters[i] = new StandardMaterialValueConverter
             {
                 Material = material
             };
         }
     }
     return(converters);
 }
        public MaterialPropertyDescriptor[] GetProperties(MaterialEditor editor, object converterObject)
        {
            PropertyEditorCallback         valueChangedCallback = () => editor.BuildEditor();
            StandardMaterialValueConverter converter            = (StandardMaterialValueConverter)converterObject;

            PropertyInfo modeInfo          = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.Mode, "Mode");
            PropertyInfo cutoffInfo        = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.Cutoff, "Cutoff");
            PropertyInfo metallicMapInfo   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.MetallicGlossMap, "MetallicGlossMap");
            PropertyInfo bumpMapInfo       = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.BumpMap, "BumpMap");
            PropertyInfo parallaxMapInfo   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.ParallaxMap, "ParallaxMap");
            PropertyInfo occlusionMapInfo  = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.OcclusionMap, "OcclusionMap");
            PropertyInfo emissionMapInfo   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.EmissionMap, "EmissionMap");
            PropertyInfo emissionColorInfo = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.EmissionColor, "EmissionColor");
            PropertyInfo detailMaskInfo    = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.DetailMask, "DetailMask");
            PropertyInfo detailAlbedoMap   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.DetailAlbedoMap, "DetailAlbedoMap");
            PropertyInfo detailNormalMap   = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.DetailNormalMap, "DetailNormalMap");
            // PropertyInfo uvSecondaryInfo = Strong.PropertyInfo((StandardMaterialValueConverter x) => x.UVSecondary);

            PropertyInfo texInfo   = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Texture, "Texture");
            PropertyInfo colorInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Color, "Color");
            PropertyInfo floatInfo = Strong.PropertyInfo((MaterialPropertyAccessor x) => x.Float, "Float");

            BlendMode mode = GetBlendMode(editor.Material);
            List <MaterialPropertyDescriptor> properties = new List <MaterialPropertyDescriptor>();

            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Rendering Mode", RTShaderPropertyType.Float, modeInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, valueChangedCallback, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _MainTex), "Albedo", RTShaderPropertyType.TexEnv, texInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _Color), "Albedo Color", RTShaderPropertyType.Color, colorInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, null, EraseAccessorTarget));
            if (mode == BlendMode.Cutout)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Alpha Cutoff", RTShaderPropertyType.Range, cutoffInfo, new RuntimeShaderInfo.RangeLimits(0.5f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Metallic", RTShaderPropertyType.TexEnv, metallicMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            bool hasGlossMap = IsMetallicGlossMapSet(editor.Material);

            if (!hasGlossMap)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _Metallic), "Metallic", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                if (StandardMaterialValueConverter.GetSmoothnessMapChannel(editor.Material) == StandardMaterialValueConverter.SmoothnessMapChannel.SpecularMetallicAlpha)
                {
                    properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _Glossiness), "Smoothness", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.5f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                }
                else
                {
                    properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _GlossMapScale), "Smoothness", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
                }
            }
            else
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _GlossMapScale), "Smoothness", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0.0f, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
            }


            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Normal Map", RTShaderPropertyType.TexEnv, bumpMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            if (converter.BumpMap != null)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _BumpScale), "Normal Map Scale", RTShaderPropertyType.Float, floatInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Height Map", RTShaderPropertyType.TexEnv, parallaxMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            if (converter.ParallaxMap != null)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _Parallax), "Height Map Scale", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.02f, 0.005f, 0.08f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Occlusion Map", RTShaderPropertyType.TexEnv, occlusionMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback, EraseAccessorTarget));
            if (converter.OcclusionMap != null)
            {
                properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _OcclusionStrength), "Occlusion Strength", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0, 1.0f), TextureDimension.None, null, EraseAccessorTarget));
            }

            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Emission Map", RTShaderPropertyType.TexEnv, emissionMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Emission Color", RTShaderPropertyType.Color, emissionColorInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.None, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Detail Mask", RTShaderPropertyType.TexEnv, detailMaskInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Detail Albedo Map", RTShaderPropertyType.TexEnv, detailAlbedoMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, converter, "Detail Normal Map", RTShaderPropertyType.TexEnv, detailNormalMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null, EraseAccessorTarget));
            properties.Add(new MaterialPropertyDescriptor(editor.Material, new MaterialPropertyAccessor(editor.Material, _DetailNormalMapScale), "Detail Scale", RTShaderPropertyType.Float, floatInfo, new RuntimeShaderInfo.RangeLimits(0, 0, 0), TextureDimension.None, null, EraseAccessorTarget));

            return(properties.ToArray());
        }