Abstract class to derive from for defining custom GUI for shader properties and for extending the material preview.
public void FindProperties(MaterialProperty[] props) { this.blendMode = ShaderGUI.FindProperty("_Mode", props); this.albedoMap = ShaderGUI.FindProperty("_MainTex", props); this.albedoColor = ShaderGUI.FindProperty("_Color", props); this.alphaCutoff = ShaderGUI.FindProperty("_Cutoff", props); this.specularMap = ShaderGUI.FindProperty("_SpecGlossMap", props, false); this.specularColor = ShaderGUI.FindProperty("_SpecColor", props, false); this.metallicMap = ShaderGUI.FindProperty("_MetallicGlossMap", props, false); this.metallic = ShaderGUI.FindProperty("_Metallic", props, false); this.m_WorkflowMode = this.specularMap == null || this.specularColor == null ? (this.metallicMap == null || this.metallic == null ? StandardShaderGUI.WorkflowMode.Dielectric : StandardShaderGUI.WorkflowMode.Metallic) : StandardShaderGUI.WorkflowMode.Specular; this.smoothness = ShaderGUI.FindProperty("_Glossiness", props); this.bumpScale = ShaderGUI.FindProperty("_BumpScale", props); this.bumpMap = ShaderGUI.FindProperty("_BumpMap", props); this.heigtMapScale = ShaderGUI.FindProperty("_Parallax", props); this.heightMap = ShaderGUI.FindProperty("_ParallaxMap", props); this.occlusionStrength = ShaderGUI.FindProperty("_OcclusionStrength", props); this.occlusionMap = ShaderGUI.FindProperty("_OcclusionMap", props); this.emissionColorForRendering = ShaderGUI.FindProperty("_EmissionColor", props); this.emissionMap = ShaderGUI.FindProperty("_EmissionMap", props); this.detailMask = ShaderGUI.FindProperty("_DetailMask", props); this.detailAlbedoMap = ShaderGUI.FindProperty("_DetailAlbedoMap", props); this.detailNormalMapScale = ShaderGUI.FindProperty("_DetailNormalMapScale", props); this.detailNormalMap = ShaderGUI.FindProperty("_DetailNormalMap", props); this.uvSetSecondary = ShaderGUI.FindProperty("_UVSec", props); }
public void FindProperties(MaterialProperty[] props) { this.blendMode = ShaderGUI.FindProperty("_Mode", props); this.colorMode = ShaderGUI.FindProperty("_ColorMode", props, false); this.flipbookMode = ShaderGUI.FindProperty("_FlipbookMode", props); this.cullMode = ShaderGUI.FindProperty("_Cull", props); this.distortionEnabled = ShaderGUI.FindProperty("_DistortionEnabled", props); this.distortionStrength = ShaderGUI.FindProperty("_DistortionStrength", props); this.distortionBlend = ShaderGUI.FindProperty("_DistortionBlend", props); this.albedoMap = ShaderGUI.FindProperty("_MainTex", props); this.albedoColor = ShaderGUI.FindProperty("_Color", props); this.alphaCutoff = ShaderGUI.FindProperty("_Cutoff", props); this.metallicMap = ShaderGUI.FindProperty("_MetallicGlossMap", props, false); this.metallic = ShaderGUI.FindProperty("_Metallic", props, false); this.smoothness = ShaderGUI.FindProperty("_Glossiness", props, false); this.bumpScale = ShaderGUI.FindProperty("_BumpScale", props); this.bumpMap = ShaderGUI.FindProperty("_BumpMap", props); this.emissionEnabled = ShaderGUI.FindProperty("_EmissionEnabled", props); this.emissionColorForRendering = ShaderGUI.FindProperty("_EmissionColor", props); this.emissionMap = ShaderGUI.FindProperty("_EmissionMap", props); this.softParticlesEnabled = ShaderGUI.FindProperty("_SoftParticlesEnabled", props); this.cameraFadingEnabled = ShaderGUI.FindProperty("_CameraFadingEnabled", props); this.softParticlesNearFadeDistance = ShaderGUI.FindProperty("_SoftParticlesNearFadeDistance", props); this.softParticlesFarFadeDistance = ShaderGUI.FindProperty("_SoftParticlesFarFadeDistance", props); this.cameraNearFadeDistance = ShaderGUI.FindProperty("_CameraNearFadeDistance", props); this.cameraFarFadeDistance = ShaderGUI.FindProperty("_CameraFarFadeDistance", props); }
public void FindProperties(MaterialProperty[] props) { this.blendMode = ShaderGUI.FindProperty("_Mode", props); this.albedoMap = ShaderGUI.FindProperty("_MainTex", props); this.albedoColor = ShaderGUI.FindProperty("_Color", props); this.alphaCutoff = ShaderGUI.FindProperty("_Cutoff", props); this.metallicMap = ShaderGUI.FindProperty("_MetallicGlossMap", props, false); this.metallic = ShaderGUI.FindProperty("_Metallic", props, false); this.roughness = ShaderGUI.FindProperty("_Glossiness", props); this.roughnessMap = ShaderGUI.FindProperty("_SpecGlossMap", props); this.highlights = ShaderGUI.FindProperty("_SpecularHighlights", props, false); this.reflections = ShaderGUI.FindProperty("_GlossyReflections", props, false); this.bumpScale = ShaderGUI.FindProperty("_BumpScale", props); this.bumpMap = ShaderGUI.FindProperty("_BumpMap", props); this.heigtMapScale = ShaderGUI.FindProperty("_Parallax", props); this.heightMap = ShaderGUI.FindProperty("_ParallaxMap", props); this.occlusionStrength = ShaderGUI.FindProperty("_OcclusionStrength", props); this.occlusionMap = ShaderGUI.FindProperty("_OcclusionMap", props); this.emissionColorForRendering = ShaderGUI.FindProperty("_EmissionColor", props); this.emissionMap = ShaderGUI.FindProperty("_EmissionMap", props); this.detailMask = ShaderGUI.FindProperty("_DetailMask", props); this.detailAlbedoMap = ShaderGUI.FindProperty("_DetailAlbedoMap", props); this.detailNormalMapScale = ShaderGUI.FindProperty("_DetailNormalMapScale", props); this.detailNormalMap = ShaderGUI.FindProperty("_DetailNormalMap", props); this.uvSetSecondary = ShaderGUI.FindProperty("_UVSec", props); }
internal void DetermineWorkflow(MaterialProperty[] props) { if (ShaderGUI.FindProperty("_SpecGlossMap", props, false) != null && ShaderGUI.FindProperty("_SpecColor", props, false) != null) { this.m_WorkflowMode = StandardShaderGUI.WorkflowMode.Specular; } else if (ShaderGUI.FindProperty("_MetallicGlossMap", props, false) != null && ShaderGUI.FindProperty("_Metallic", props, false) != null) { this.m_WorkflowMode = StandardShaderGUI.WorkflowMode.Metallic; } else { this.m_WorkflowMode = StandardShaderGUI.WorkflowMode.Dielectric; } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { if (!this.m_Initialized) { this.m_ShowLatLongLayout.valueChanged.AddListener(new UnityAction(materialEditor.Repaint)); this.m_ShowMirrorOnBack.valueChanged.AddListener(new UnityAction(materialEditor.Repaint)); this.m_Show3DControl.valueChanged.AddListener(new UnityAction(materialEditor.Repaint)); this.m_Initialized = true; } float labelWidth = EditorGUIUtility.labelWidth; materialEditor.SetDefaultGUIWidths(); this.ShowProp(materialEditor, ShaderGUI.FindProperty("_Tint", props)); this.ShowProp(materialEditor, ShaderGUI.FindProperty("_Exposure", props)); this.ShowProp(materialEditor, ShaderGUI.FindProperty("_Rotation", props)); this.ShowProp(materialEditor, ShaderGUI.FindProperty("_MainTex", props)); EditorGUIUtility.labelWidth = labelWidth; this.m_ShowLatLongLayout.target = (this.ShowProp(materialEditor, ShaderGUI.FindProperty("_Mapping", props)) == 1f); if (EditorGUILayout.BeginFadeGroup(this.m_ShowLatLongLayout.faded)) { this.m_ShowMirrorOnBack.target = (this.ShowProp(materialEditor, ShaderGUI.FindProperty("_ImageType", props)) == 1f); if (EditorGUILayout.BeginFadeGroup(this.m_ShowMirrorOnBack.faded)) { EditorGUI.indentLevel++; this.ShowProp(materialEditor, ShaderGUI.FindProperty("_MirrorOnBack", props)); EditorGUI.indentLevel--; } EditorGUILayout.EndFadeGroup(); this.m_Show3DControl.value = false; BuildPlatform[] buildPlatforms = BuildPlatforms.instance.buildPlatforms; for (int i = 0; i < buildPlatforms.Length; i++) { BuildPlatform buildPlatform = buildPlatforms[i]; if (VREditor.GetVREnabledOnTargetGroup(buildPlatform.targetGroup)) { this.m_Show3DControl.value = true; break; } } if (EditorGUILayout.BeginFadeGroup(this.m_Show3DControl.faded)) { this.ShowProp(materialEditor, ShaderGUI.FindProperty("_Layout", props)); } EditorGUILayout.EndFadeGroup(); } EditorGUILayout.EndFadeGroup(); materialEditor.PropertiesDefaultGUI(new MaterialProperty[0]); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { materialEditor.SetDefaultGUIWidths(); MaterialProperty materialProperty = ShaderGUI.FindProperty("_SunDisk", props); SkyboxProceduralShaderGUI.SunDiskMode sunDiskMode = (SkyboxProceduralShaderGUI.SunDiskMode)materialProperty.floatValue; for (int i = 0; i < props.Length; i++) { if ((props[i].flags & (MaterialProperty.PropFlags.HideInInspector | MaterialProperty.PropFlags.PerRendererData)) == MaterialProperty.PropFlags.None) { if (!(props[i].name == "_SunSizeConvergence") || sunDiskMode == SkyboxProceduralShaderGUI.SunDiskMode.HighQuality) { float propertyHeight = materialEditor.GetPropertyHeight(props[i], props[i].displayName); Rect controlRect = EditorGUILayout.GetControlRect(true, propertyHeight, EditorStyles.layerMaskField, new GUILayoutOption[0]); materialEditor.ShaderProperty(controlRect, props[i], props[i].displayName); } } } }
public void FindProperties(MaterialProperty[] props) { this.blendMode = ShaderGUI.FindProperty("_Mode", props); this.albedoMap = ShaderGUI.FindProperty("_MainTex", props); this.albedoColor = ShaderGUI.FindProperty("_Color", props); this.alphaCutoff = ShaderGUI.FindProperty("_Cutoff", props); this.specularMap = ShaderGUI.FindProperty("_SpecGlossMap", props, false); this.specularColor = ShaderGUI.FindProperty("_SpecColor", props, false); this.metallicMap = ShaderGUI.FindProperty("_MetallicGlossMap", props, false); this.metallic = ShaderGUI.FindProperty("_Metallic", props, false); if (this.specularMap != null && this.specularColor != null) { this.m_WorkflowMode = StandardShaderGUI.WorkflowMode.Specular; } else if (this.metallicMap != null && this.metallic != null) { this.m_WorkflowMode = StandardShaderGUI.WorkflowMode.Metallic; } else { this.m_WorkflowMode = StandardShaderGUI.WorkflowMode.Dielectric; } this.smoothness = ShaderGUI.FindProperty("_Glossiness", props); this.smoothnessScale = ShaderGUI.FindProperty("_GlossMapScale", props, false); this.smoothnessMapChannel = ShaderGUI.FindProperty("_SmoothnessTextureChannel", props, false); this.highlights = ShaderGUI.FindProperty("_SpecularHighlights", props, false); this.reflections = ShaderGUI.FindProperty("_GlossyReflections", props, false); this.bumpScale = ShaderGUI.FindProperty("_BumpScale", props); this.bumpMap = ShaderGUI.FindProperty("_BumpMap", props); this.heigtMapScale = ShaderGUI.FindProperty("_Parallax", props); this.heightMap = ShaderGUI.FindProperty("_ParallaxMap", props); this.occlusionStrength = ShaderGUI.FindProperty("_OcclusionStrength", props); this.occlusionMap = ShaderGUI.FindProperty("_OcclusionMap", props); this.emissionColorForRendering = ShaderGUI.FindProperty("_EmissionColor", props); this.emissionMap = ShaderGUI.FindProperty("_EmissionMap", props); this.detailMask = ShaderGUI.FindProperty("_DetailMask", props); this.detailAlbedoMap = ShaderGUI.FindProperty("_DetailAlbedoMap", props); this.detailNormalMapScale = ShaderGUI.FindProperty("_DetailNormalMapScale", props); this.detailNormalMap = ShaderGUI.FindProperty("_DetailNormalMap", props); this.uvSetSecondary = ShaderGUI.FindProperty("_UVSec", props); }
internal static ShaderGUI CreateShaderGUI(string customEditorName) { string value = "UnityEditor." + customEditorName; Assembly[] loadedAssemblies = EditorAssemblies.loadedAssemblies; ShaderGUI result; for (int i = loadedAssemblies.Length - 1; i >= 0; i--) { Assembly assembly = loadedAssemblies[i]; Type[] typesFromAssembly = AssemblyHelper.GetTypesFromAssembly(assembly); Type[] array = typesFromAssembly; int j = 0; while (j < array.Length) { Type type = array[j]; if (type.FullName.Equals(customEditorName, StringComparison.Ordinal) || type.FullName.Equals(value, StringComparison.Ordinal)) { if (typeof(ShaderGUI).IsAssignableFrom(type)) { ShaderGUI shaderGUI = Activator.CreateInstance(type) as ShaderGUI; result = shaderGUI; return(result); } result = null; return(result); } else { j++; } } } result = null; return(result); }
private void CreateCustomShaderGUI(Shader shader, string oldEditorName) { if ((UnityEngine.Object) shader == (UnityEngine.Object) null || string.IsNullOrEmpty(shader.customEditor)) { this.m_CustomShaderGUI = (ShaderGUI) null; } else { if (oldEditorName == shader.customEditor) return; this.m_CustomShaderGUI = ShaderGUIUtility.CreateShaderGUI(shader.customEditor); this.m_CheckSetup = true; } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { if (m_FirstTimeApply) { foreach (var obj in materialEditor.targets) { MaterialChanged((Material)obj); } m_FirstTimeApply = false; } // Use default labelWidth EditorGUIUtility.labelWidth = 0.0f; EditorGUI.BeginChangeCheck(); { GUILayout.Label(Styles.primaryMapsText, EditorStyles.boldLabel); // color var colorTexProp = ShaderGUI.FindProperty("_MainTex", properties); var colorProp = ShaderGUI.FindProperty("_Color", properties); materialEditor.TexturePropertySingleLine(Styles.colorText, colorTexProp, null, colorProp); // normal var normalTexProp = ShaderGUI.FindProperty("_BumpMap", properties); materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalTexProp); // extra var extraTexProp = ShaderGUI.FindProperty("_ExtraTex", properties); materialEditor.TexturePropertySingleLine(Styles.extraMapText, extraTexProp, null); if (extraTexProp.textureValue == null) { var glossProp = ShaderGUI.FindProperty("_Glossiness", properties); materialEditor.ShaderProperty(glossProp, Styles.smoothnessText, 2); var metallicProp = ShaderGUI.FindProperty("_Metallic", properties); materialEditor.ShaderProperty(metallicProp, Styles.metallicText, 2); } // subsurface var ssTexProp = ShaderGUI.FindProperty("_SubsurfaceTex", properties); var ssProp = ShaderGUI.FindProperty("_SubsurfaceColor", properties); materialEditor.TexturePropertySingleLine(Styles.subsurfaceMapText, ssTexProp, null, ssProp); // Emission emissionColorForRendering = ShaderGUI.FindProperty("_EmissionColor", properties); emissionMap = ShaderGUI.FindProperty("_EmissionMap", properties); emissionMap.textureScaleAndOffset = colorTexProp.textureScaleAndOffset; // other options EditorGUILayout.Space(); GUILayout.Label(Styles.optionsText, EditorStyles.boldLabel); MakeAlignedProperty(FindProperty("_TwoSided", properties), Styles.twoSidedText, materialEditor, true); MakeAlignedProperty(FindProperty("_WindQuality", properties), Styles.windQualityText, materialEditor, true); MakeCheckedProperty(FindProperty("_HueVariationKwToggle", properties), FindProperty("_HueVariationColor", properties), Styles.hueVariationText, materialEditor); MakeAlignedProperty(FindProperty("_NormalMapKwToggle", properties), Styles.normalMappingText, materialEditor, true); // subsurface var subsurfaceToggle = FindProperty("_SubsurfaceKwToggle", properties); MakeAlignedProperty(subsurfaceToggle, Styles.subsurfaceText, materialEditor, true); if (subsurfaceToggle.floatValue > 0.0f) { var sssIndirectProp = ShaderGUI.FindProperty("_SubsurfaceIndirect", properties); materialEditor.ShaderProperty(sssIndirectProp, Styles.subsurfaceIndirectText, 2); } // billboard var billboardToggle = FindProperty("_BillboardKwToggle", properties); MakeAlignedProperty(billboardToggle, Styles.billboardText, materialEditor, true); if (billboardToggle.floatValue > 0.0f) { var prop = ShaderGUI.FindProperty("_BillboardShadowFade", properties); materialEditor.ShaderProperty(prop, Styles.billboardShadowFadeText, 2); } } if (EditorGUI.EndChangeCheck()) { foreach (var obj in materialEditor.targets) { Material mat = (Material)obj; MaterialChanged(mat); } } EditorGUILayout.Space(); GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel); materialEditor.EnableInstancingField(); materialEditor.DoubleSidedGIField(); // Emission for GI? m_MaterialEditor = materialEditor; if (materialEditor.EmissionEnabledProperty()) { bool hadEmissionTexture = emissionMap.textureValue != null; // Texture and HDR color controls m_MaterialEditor.TexturePropertyWithHDRColor(Styles.emissionText, emissionMap, emissionColorForRendering, false); // If texture was assigned and color was black set color to white float brightness = emissionColorForRendering.colorValue.maxColorComponent; if (emissionMap.textureValue != null && !hadEmissionTexture && brightness <= 0f) { emissionColorForRendering.colorValue = Color.white; } // change the GI flag and fix it up with emissive as black if necessary m_MaterialEditor.LightmapEmissionFlagsProperty(MaterialEditor.kMiniTextureFieldLabelIndentLevel, true); SetKeyword((Material)m_MaterialEditor.target, "EFFECT_EMISSION", true); } else { SetKeyword((Material)m_MaterialEditor.target, "EFFECT_EMISSION", false); } }
protected static MaterialProperty FindProperty(string propertyName, MaterialProperty[] properties) { return(ShaderGUI.FindProperty(propertyName, properties, true)); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { // Use default labelWidth EditorGUIUtility.labelWidth = 0.0f; { GUILayout.Label(Styles.primaryMapsText, EditorStyles.boldLabel); // color var colorTexProp = ShaderGUI.FindProperty("_MainTex", properties); var colorProp = ShaderGUI.FindProperty("_Color", properties); materialEditor.TexturePropertySingleLine(Styles.colorText, colorTexProp, null, colorProp); // normal var normalTexProp = ShaderGUI.FindProperty("_BumpMap", properties); materialEditor.TexturePropertySingleLine(Styles.normalMapText, normalTexProp); // extra var extraTexProp = ShaderGUI.FindProperty("_ExtraTex", properties); materialEditor.TexturePropertySingleLine(Styles.extraMapText, extraTexProp, null); if (extraTexProp.textureValue == null) { var glossProp = ShaderGUI.FindProperty("_Glossiness", properties); materialEditor.ShaderProperty(glossProp, Styles.smoothnessText, 2); var metallicProp = ShaderGUI.FindProperty("_Metallic", properties); materialEditor.ShaderProperty(metallicProp, Styles.metallicText, 2); } // subsurface var ssTexProp = ShaderGUI.FindProperty("_SubsurfaceTex", properties); var ssProp = ShaderGUI.FindProperty("_SubsurfaceColor", properties); materialEditor.TexturePropertySingleLine(Styles.subsurfaceMapText, ssTexProp, null, ssProp); // other options EditorGUILayout.Space(); GUILayout.Label(Styles.optionsText, EditorStyles.boldLabel); MakeAlignedProperty(FindProperty("_TwoSided", properties), Styles.twoSidedText, materialEditor, true); MakeAlignedProperty(FindProperty("_WindQuality", properties), Styles.windQualityText, materialEditor, true); MakeCheckedProperty(FindProperty("_HueVariationKwToggle", properties), FindProperty("_HueVariationColor", properties), Styles.hueVariationText, materialEditor); MakeAlignedProperty(FindProperty("_NormalMapKwToggle", properties), Styles.normalMappingText, materialEditor, true); // subsurface var subsurfaceToggle = FindProperty("_SubsurfaceKwToggle", properties); MakeAlignedProperty(subsurfaceToggle, Styles.subsurfaceText, materialEditor, true); if (subsurfaceToggle.floatValue > 0.0f) { var sssIndirectProp = ShaderGUI.FindProperty("_SubsurfaceIndirect", properties); materialEditor.ShaderProperty(sssIndirectProp, Styles.subsurfaceIndirectText, 2); } // billboard var billboardToggle = FindProperty("_BillboardKwToggle", properties); MakeAlignedProperty(billboardToggle, Styles.billboardText, materialEditor, true); if (billboardToggle.floatValue > 0.0f) { var prop = ShaderGUI.FindProperty("_BillboardShadowFade", properties); materialEditor.ShaderProperty(prop, Styles.billboardShadowFadeText, 2); } } EditorGUILayout.Space(); GUILayout.Label(Styles.advancedText, EditorStyles.boldLabel); materialEditor.EnableInstancingField(); materialEditor.DoubleSidedGIField(); }
private void CreateCustomShaderGUI(Shader shader, string oldEditorName) { if (shader == null || string.IsNullOrEmpty(shader.customEditor)) { this.m_CustomShaderGUI = null; return; } if (oldEditorName == shader.customEditor) { return; } this.m_CustomShaderGUI = ShaderGUIUtility.CreateShaderGUI(shader.customEditor); if (this.m_CustomShaderGUI == null && !this.IsMaterialEditor(shader.customEditor)) { Debug.LogWarning("MaterialEditor: Could not create custom UI from the CustomEditor: '" + base.name + "' of the shader. Does the class name include its namespace? And does the class either derive from ShaderGUI or MaterialEditor?"); } }
private void CreateCustomShaderGUI(Shader shader, string oldEditorName) { if ((shader == null) || string.IsNullOrEmpty(shader.customEditor)) { this.m_CustomShaderGUI = null; } else if (oldEditorName != shader.customEditor) { this.m_CustomShaderGUI = ShaderGUIUtility.CreateShaderGUI(shader.customEditor); this.m_CheckSetup = true; } }