public void BuildEditor() { foreach (Transform t in EditorsPanel) { Destroy(t.gameObject); } IMaterialDescriptor selector; if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector)) { selector = new MaterialDescriptor(); } object converter = selector.CreateConverter(this); MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter); if (descriptors == null) { Destroy(gameObject); return; } for (int i = 0; i < descriptors.Length; ++i) { MaterialPropertyDescriptor descriptor = descriptors[i]; PropertyEditor editor = null; object target = descriptor.Target; PropertyInfo propertyInfo = descriptor.PropertyInfo; #if !UNITY_WEBGL && PROC_MATERIAL if (descriptor.ProceduralDescription == null) #endif { RTShaderPropertyType propertyType = descriptor.Type; switch (propertyType) { case RTShaderPropertyType.Range: if (RangeEditor != null) { RangeEditor range = Instantiate(RangeEditor); range.transform.SetParent(EditorsPanel, false); var rangeLimits = descriptor.Limits; range.Min = rangeLimits.Min; range.Max = rangeLimits.Max; editor = range; } break; default: if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } break; } } #if !UNITY_WEBGL && PROC_MATERIAL else { ProcPropertyDescription input = descriptor.ProceduralDescription; if (input.hasRange) { if (input.type == ProcPropertyType.Float) { if (RangeEditor != null) { RangeEditor range = Instantiate(RangeEditor); range.transform.SetParent(EditorsPanel, false); range.Min = input.minimum; range.Max = input.maximum; //TODO implement step on range editor // = input.step editor = range; } } else { //TODO: Implement range on vector editors if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } } } else { //if(input.type == ProceduralPropertyType.Enum) //TODO: Implement enum from string array editor. //input.enumOptions if (EditorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = EditorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } } } #endif if (editor == null) { continue; } editor.Init(target, propertyInfo, descriptor.Label, null, descriptor.ValueChangedCallback, () => { RuntimeEditorApplication.SaveSelectedObjects(); }); } }
public void BuildEditor() { foreach (Transform t in EditorsPanel) { Destroy(t.gameObject); } IMaterialDescriptor selector; if (!m_propertySelectors.TryGetValue(Material.shader.name, out selector)) { selector = new MaterialDescriptor(); } object converter = selector.CreateConverter(this); MaterialPropertyDescriptor[] descriptors = selector.GetProperties(this, converter); if (descriptors == null) { Destroy(gameObject); return; } for (int i = 0; i < descriptors.Length; ++i) { MaterialPropertyDescriptor descriptor = descriptors[i]; PropertyEditor editor = null; PropertyInfo propertyInfo = descriptor.PropertyInfo; RTShaderPropertyType propertyType = descriptor.Type; switch (propertyType) { case RTShaderPropertyType.Range: if (RangeEditor != null) { RangeEditor range = Instantiate(RangeEditor); range.transform.SetParent(EditorsPanel, false); var rangeLimits = descriptor.Limits; range.Min = rangeLimits.Min; range.Max = rangeLimits.Max; editor = range; } break; default: if (m_editorsMap.IsPropertyEditorEnabled(propertyInfo.PropertyType)) { GameObject editorPrefab = m_editorsMap.GetPropertyEditor(propertyInfo.PropertyType); GameObject instance = Instantiate(editorPrefab); instance.transform.SetParent(EditorsPanel, false); if (instance != null) { editor = instance.GetComponent <PropertyEditor>(); } } break; } if (editor == null) { continue; } editor.Init(descriptor.Target, descriptor.Accessor, propertyInfo, descriptor.EraseTargetCallback, descriptor.Label, null, descriptor.ValueChangedCallback, () => { m_editor.IsDirty = true; UpdatePreview(Material); }); } }
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(converter, "Rendering Mode", RTShaderPropertyType.Float, modeInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, valueChangedCallback)); properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _MainTex), "Albedo", RTShaderPropertyType.TexEnv, texInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.Tex2D, null)); properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _Color), "Albedo Color", RTShaderPropertyType.Color, colorInfo, new RuntimeShaderInfo.RangeLimits(), TextureDimension.None, null)); if (mode == BlendMode.Cutout) { properties.Add(new MaterialPropertyDescriptor(converter, "Alpha Cutoff", RTShaderPropertyType.Range, cutoffInfo, new RuntimeShaderInfo.RangeLimits(0.5f, 0.0f, 1.0f), TextureDimension.None, null)); } properties.Add(new MaterialPropertyDescriptor(converter, "Metallic", RTShaderPropertyType.TexEnv, metallicMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback)); bool hasGlossMap = IsMetallicGlossMapSet(editor.Material); if (!hasGlossMap) { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _Metallic), "Metallic", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 1.0f), TextureDimension.None, null)); if (StandardMaterialValueConverter.GetSmoothnessMapChannel(editor.Material) == StandardMaterialValueConverter.SmoothnessMapChannel.SpecularMetallicAlpha) { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _Glossiness), "Smoothness", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.5f, 0.0f, 1.0f), TextureDimension.None, null)); } else { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _GlossMapScale), "Smoothness", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0.0f, 1.0f), TextureDimension.None, null)); } } else { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _GlossMapScale), "Smoothness", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0.0f, 1.0f), TextureDimension.None, null)); } properties.Add(new MaterialPropertyDescriptor(converter, "Normal Map", RTShaderPropertyType.TexEnv, bumpMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback)); if (converter.BumpMap != null) { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _BumpScale), "Normal Map Scale", RTShaderPropertyType.Float, floatInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.None, null)); } properties.Add(new MaterialPropertyDescriptor(converter, "Height Map", RTShaderPropertyType.TexEnv, parallaxMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback)); if (converter.ParallaxMap != null) { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _Parallax), "Height Map Scale", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(0.02f, 0.005f, 0.08f), TextureDimension.None, null)); } properties.Add(new MaterialPropertyDescriptor(converter, "Occlusion Map", RTShaderPropertyType.TexEnv, occlusionMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, valueChangedCallback)); if (converter.OcclusionMap != null) { properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _OcclusionStrength), "Occlusion Strength", RTShaderPropertyType.Range, floatInfo, new RuntimeShaderInfo.RangeLimits(1.0f, 0, 1.0f), TextureDimension.None, null)); } properties.Add(new MaterialPropertyDescriptor(converter, "Emission Map", RTShaderPropertyType.TexEnv, emissionMapInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null)); properties.Add(new MaterialPropertyDescriptor(converter, "Emission Color", RTShaderPropertyType.Color, emissionColorInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.None, null)); properties.Add(new MaterialPropertyDescriptor(converter, "Detail Mask", RTShaderPropertyType.TexEnv, detailMaskInfo, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null)); properties.Add(new MaterialPropertyDescriptor(converter, "Detail Albedo Map", RTShaderPropertyType.TexEnv, detailAlbedoMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null)); properties.Add(new MaterialPropertyDescriptor(converter, "Detail Normal Map", RTShaderPropertyType.TexEnv, detailNormalMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null)); properties.Add(new MaterialPropertyDescriptor(new MaterialPropertyAccessor(editor.Material, _DetailNormalMapScale), "Detail Scale", RTShaderPropertyType.Float, floatInfo, new RuntimeShaderInfo.RangeLimits(0, 0, 0), TextureDimension.None, null)); //properties.Add(new MaterialPropertyDescriptor(converter, "UV Set", RTShaderPropertyType.Float, detailNormalMap, new RuntimeShaderInfo.RangeLimits(0.0f, 0.0f, 0.0f), TextureDimension.Tex2D, null)); #if !UNITY_WEBGL && PROC_MATERIAL ProceduralMaterial procMaterial = editor.Material as ProceduralMaterial; if (procMaterial != null) { MaterialDescriptor.GetProceduralMaterialDescriptors(procMaterial, properties); } #endif return(properties.ToArray()); }