public void OnGUI(ref Rect position, MaterialProperty prop, string label, MaterialEditor editor) { float num = position.height; position.height = 0f; if (this.m_DecoratorDrawers != null) { foreach (MaterialPropertyDrawer current in this.m_DecoratorDrawers) { position.height = current.GetPropertyHeight(prop, label, editor); float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; current.OnGUI(position, prop, label, editor); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; position.y += position.height; num -= position.height; } } position.height = num; if (this.m_PropertyDrawer != null) { float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; this.m_PropertyDrawer.OnGUI(position, prop, label, editor); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; } }
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 override void Apply(MaterialProperty prop) { base.Apply(prop); if (!MaterialToggleDrawer.IsPropertyTypeSuitable(prop) || prop.hasMixedValue) return; this.SetKeyword(prop, (double) Math.Abs(prop.floatValue) > 1.0 / 1000.0); }
override public void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (!checkVisible (editor)) return; Color col = GUI.contentColor; Color bcol = GUI.backgroundColor; GUI.contentColor = new Color(1f, 1f, 0.8f, 1f); GUI.backgroundColor = backgroundColor; //position.y -= 15; Rect pos=new Rect(position); pos.y += 3; pos.height -= 3; //if (visibilityProp1==null || visibilityProp1=="indent") { // pos.height -= 10; // pos.y += 10; //} if (visibilityProp1!=null) { pos.x+=12; pos.width-=12; } // pos.height = 17; EditorGUI.HelpBox(pos, (foldoutFlag ? " ":"")+label, MessageType.None); if (foldoutFlag) { Rect fpos = new Rect(pos); fpos.x += 15; fpos.y += 1; bool state = EditorGUI.Foldout(fpos, prop.floatValue==1, "", true); prop.floatValue = state ? 1 : 0; } GUI.contentColor = col; GUI.backgroundColor = bcol; }
public static void SetupMaterialPropertyBlock(MaterialProperty materialProp, int changedMask, Renderer target) { MaterialPropertyBlock materialPropertyBlock = new MaterialPropertyBlock(); target.GetPropertyBlock(materialPropertyBlock); materialProp.WriteToMaterialPropertyBlock(materialPropertyBlock, changedMask); target.SetPropertyBlock(materialPropertyBlock); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { base.OnGUI(materialEditor, props); materialEditor.LightmapEmissionProperty(0); foreach (Material target in materialEditor.targets) target.globalIlluminationFlags &= ~MaterialGlobalIlluminationFlags.EmissiveIsBlack; }
public static int FindProperties(ShaderGUIBase _inst, MaterialProperty[] _properties) { int _cnt = 0; var _flags = System.Reflection.BindingFlags.Instance | System.Reflection.BindingFlags.NonPublic | System.Reflection.BindingFlags.Public; _inst.m_Keywords.Clear (); foreach (var _field in _inst.GetType ().GetFields (_flags)) { foreach (var _attr in _field.GetCustomAttributes (true)) { var _propAttr = _attr as MaterialPropertyAttribute; if (null != _propAttr && _field.FieldType == typeof(MaterialProperty)) { var _prop = FindProperty (_propAttr.Name, _properties); if (null == _prop) { Log.E ("Material Property {0} not found!", _propAttr.Name); continue; } var _keyword = _propAttr.Keyword; if (null != _keyword) _inst.m_Keywords.Add (_prop.name, _keyword); _field.SetValue (_inst, _prop); ++_cnt; } } } return _cnt; }
public void FindProperties(MaterialProperty[] props) { blendMode = FindProperty("_Mode", props); albedoMap = FindProperty("_MainTex", props); albedoColor = FindProperty("_Color", props); alphaCutoff = FindProperty("_Cutoff", props); specularMap = FindProperty("_SpecGlossMap", props, false); specularColor = FindProperty("_SpecColor", props, false); metallicMap = FindProperty("_MetallicGlossMap", props, false); metallic = FindProperty("_Metallic", props, false); if (specularMap != null && specularColor != null) m_WorkflowMode = WorkflowMode.Specular; else if (metallicMap != null && metallic != null) m_WorkflowMode = WorkflowMode.Metallic; else m_WorkflowMode = WorkflowMode.Dielectric; smoothness = FindProperty("_Glossiness", props); bumpScale = FindProperty("_BumpScale", props); bumpMap = FindProperty("_BumpMap", props); heigtMapScale = FindProperty("_Parallax", props); heightMap = FindProperty("_ParallaxMap", props); occlusionStrength = FindProperty("_OcclusionStrength", props); occlusionMap = FindProperty("_OcclusionMap", props); emissionScaleUI = FindProperty("_EmissionScaleUI", props); emissionColorUI = FindProperty("_EmissionColorUI", props); emissionColorForRendering = FindProperty("_EmissionColor", props); emissionMap = FindProperty("_EmissionMap", props); detailMask = FindProperty("_DetailMask", props); detailAlbedoMap = FindProperty("_DetailAlbedoMap", props); detailNormalMapScale = FindProperty("_DetailNormalMapScale", props); detailNormalMap = FindProperty("_DetailNormalMap", props); uvSetSecondary = FindProperty("_UVSec", props); vertexColor = FindProperty("_IntensityVC", props); }
public static bool ApplyMaterialModificationToAnimationRecording(MaterialProperty materialProp, int changedMask, Renderer target, object oldValue) { switch (materialProp.type) { case MaterialProperty.PropType.Color: SetupMaterialPropertyBlock(materialProp, changedMask, target); ApplyMaterialModificationToAnimationRecording(materialProp, target, (Color) oldValue); return true; case MaterialProperty.PropType.Vector: SetupMaterialPropertyBlock(materialProp, changedMask, target); ApplyMaterialModificationToAnimationRecording(materialProp, target, (Color) ((Vector4) oldValue)); return true; case MaterialProperty.PropType.Float: case MaterialProperty.PropType.Range: SetupMaterialPropertyBlock(materialProp, changedMask, target); ApplyMaterialModificationToAnimationRecording(materialProp, target, (float) oldValue); return true; case MaterialProperty.PropType.Texture: { if (!MaterialProperty.IsTextureOffsetAndScaleChangedMask(changedMask)) { return false; } string name = materialProp.name + "_ST"; SetupMaterialPropertyBlock(materialProp, changedMask, target); ApplyMaterialModificationToAnimationRecording(name, target, (Vector4) oldValue); return true; } } return false; }
public void FindProperties (MaterialProperty[] props) { cullMode = FindProperty ("_CullMode", props, false); albedoMap = FindProperty ("_MainTex", props); albedoColor = FindProperty ("_Color", props); specularMap = FindProperty ("_SpecGlossMap", props, false); specularColor = FindProperty ("_SpecColor", props, false); metallicMap = FindProperty ("_MetallicGlossMap", props, false); metallic = FindProperty ("_Metallic", props, false); if (specularMap != null && specularColor != null) m_WorkflowMode = WorkflowMode.Specular; else if (metallicMap != null && metallic != null) m_WorkflowMode = WorkflowMode.Metallic; else m_WorkflowMode = WorkflowMode.Dielectric; smoothness = FindProperty ("_Glossiness", props); smoothnessTweak1 = FindProperty ("_SmoothnessTweak1", props, false); smoothnessTweak2 = FindProperty ("_SmoothnessTweak2", props, false); smoothnessTweaks = FindProperty ("_SmoothnessTweaks", props, false); specularMapColorTweak = FindProperty ("_SpecularMapColorTweak", props, false); bumpScale = FindProperty ("_BumpScale", props); bumpMap = FindProperty ("_BumpMap", props); orthoNormalize = FindProperty ("_Orthonormalize", props, false); occlusionStrength = FindProperty ("_OcclusionStrength", props); occlusionMap = FindProperty ("_OcclusionMap", props); detailMask = FindProperty ("_DetailMask", props); detailAlbedoMap = FindProperty ("_DetailAlbedoMap", props); detailNormalMapScale = FindProperty ("_DetailNormalMapScale", props); detailNormalMap = FindProperty ("_DetailNormalMap", props); uvSetSecondary = FindProperty ("_UVSec", props); smoothnessInAlbedo = FindProperty ("_SmoothnessInAlbedo", props, false); }
public void OnGUI(ref Rect position, MaterialProperty prop, string label, MaterialEditor editor) { float height = position.height; position.height = 0.0f; if (this.m_DecoratorDrawers != null) { using (List<MaterialPropertyDrawer>.Enumerator enumerator = this.m_DecoratorDrawers.GetEnumerator()) { while (enumerator.MoveNext()) { MaterialPropertyDrawer current = enumerator.Current; position.height = current.GetPropertyHeight(prop, label, editor); float labelWidth = EditorGUIUtility.labelWidth; float fieldWidth = EditorGUIUtility.fieldWidth; current.OnGUI(position, prop, label, editor); EditorGUIUtility.labelWidth = labelWidth; EditorGUIUtility.fieldWidth = fieldWidth; position.y += position.height; height -= position.height; } } } position.height = height; if (this.m_PropertyDrawer == null) return; float labelWidth1 = EditorGUIUtility.labelWidth; float fieldWidth1 = EditorGUIUtility.fieldWidth; this.m_PropertyDrawer.OnGUI(position, prop, label, editor); EditorGUIUtility.labelWidth = labelWidth1; EditorGUIUtility.fieldWidth = fieldWidth1; }
public override void OnGUI(MaterialEditor _materialEditor, MaterialProperty[] _properties) { FindProperties(this, _properties); DoGeneral(_materialEditor); DoNormalMap(_materialEditor); DoRim(_materialEditor); }
protected override void FindLightingProperties(MaterialProperty[] props) { cloudAttenuationRamp = FindProperty("_CloudAttenuationRamp", props); cloudBackScattering = FindProperty("_CloudBackScattering", props); fakeLightDirection = FindProperty("_FakeLightDirection", props); fakeLightColor = FindProperty("_FakeLightColor", props); fakeLightIntensity = FindProperty("_FakeLightIntensity", props); }
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { if (prop.type != MaterialProperty.PropType.Range) { return 40f; } return base.GetPropertyHeight(prop, label, editor); }
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { if (prop.type != MaterialProperty.PropType.Float && prop.type != MaterialProperty.PropType.Range) { return(EditorGUI.kSingleLineHeight * 2.5f); } return(base.GetPropertyHeight(prop, label, editor)); }
public override void Apply(MaterialProperty prop) { base.Apply(prop); if (IsPropertyTypeSuitable(prop) && !prop.hasMixedValue) { this.SetKeyword(prop, Math.Abs(prop.floatValue) > 0.001f); } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { FindProperties(properties); if (ShaderPropertiesGUI(materialEditor) || _initial) foreach (Material m in materialEditor.targets) UpdateMaterial(m); _initial = false; }
void Vector3Property(MaterialEditor materialEditor, MaterialProperty prop, string label) { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; var newValue = EditorGUILayout.Vector3Field(label, prop.vectorValue); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) prop.vectorValue = newValue; }
void FindProperties(MaterialProperty[] props) { _blendMode = FindProperty("_BlendMode", props); _colorMode = FindProperty("_ColorMode", props); _color = FindProperty("_Color", props); _color2 = FindProperty("_Color2", props); _mainTex = FindProperty("_MainTex", props); }
private static bool IsPropertyTypeSuitable(MaterialProperty prop) { if (prop.type != MaterialProperty.PropType.Float) { return(prop.type == MaterialProperty.PropType.Range); } return(true); }
void FindProperties(MaterialProperty[] props) { _cubemap = FindProperty("_Cubemap", props); _tint = FindProperty("_Tint", props); _euler = FindProperty("_Euler", props); _exposure = FindProperty("_Exposure", props); _saturation = FindProperty("_Saturation", props); }
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { if (!IsPropertyTypeSuitable(prop)) { return 40f; } return base.GetPropertyHeight(prop, label, editor); }
public static bool IsAnimated(MaterialProperty materialProp, Renderer target) { if (materialProp.type == MaterialProperty.PropType.Texture) { return AnimationMode.IsPropertyAnimated(target, "material." + materialProp.name + "_ST"); } return AnimationMode.IsPropertyAnimated(target, "material." + materialProp.name); }
public override void Apply(MaterialProperty prop) { base.Apply(prop); if (IsPropertyTypeSuitable(prop) && !prop.hasMixedValue) { this.SetKeyword(prop, (int)prop.floatValue); } }
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { if (!IsPropertyTypeSuitable(prop)) { return(40f); } return(base.GetPropertyHeight(prop, label, editor)); }
public override void Apply(MaterialProperty prop) { base.Apply(prop); if (!MaterialToggleDrawer.IsPropertyTypeSuitable(prop) || prop.hasMixedValue) { return; } this.SetKeyword(prop, (double)Math.Abs(prop.floatValue) > 1.0 / 1000.0); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] props) { m_MaterialEditor = materialEditor; Material material = materialEditor.target as Material; FindProperties (material, props); ShaderPropertiesGUI (material); }
private static void ApplyMaterialModificationToAnimationRecording(MaterialProperty materialProp, UnityEngine.Object target, Color color) { UndoPropertyModification[] array = MaterialAnimationUtility.CreateUndoPropertyModifications(4, target); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".r", color.r, array[0]); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".g", color.g, array[1]); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".b", color.b, array[2]); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".a", color.a, array[3]); Undo.postprocessModifications(array); }
private static void ApplyMaterialModificationToAnimationRecording(MaterialProperty materialProp, Object target, Color color) { UndoPropertyModification[] modifications = CreateUndoPropertyModifications(4, target); SetupPropertyModification(materialProp.name + ".r", color.r, modifications[0]); SetupPropertyModification(materialProp.name + ".g", color.g, modifications[1]); SetupPropertyModification(materialProp.name + ".b", color.b, modifications[2]); SetupPropertyModification(materialProp.name + ".a", color.a, modifications[3]); Undo.postprocessModifications(modifications); }
private static void ApplyMaterialModificationToAnimationRecording(MaterialProperty materialProp, Object target, Color color) { UndoPropertyModification[] propertyModifications = MaterialAnimationUtility.CreateUndoPropertyModifications(4, target); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".r", color.r, propertyModifications[0]); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".g", color.g, propertyModifications[1]); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".b", color.b, propertyModifications[2]); MaterialAnimationUtility.SetupPropertyModification(materialProp.name + ".a", color.a, propertyModifications[3]); UndoPropertyModification[] propertyModificationArray = Undo.postprocessModifications(propertyModifications); }
override public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { bool inactiveFlag=false; if (!checkSpecUsage(editor.target as Material, label)) return -2; if (!checkEmissiveUsage(editor.target as Material, label)) return -2; if (checkVisible(editor, ref inactiveFlag)) { return MaterialEditor.GetDefaultPropertyHeight(prop); } return -2; }
void FindProperties(MaterialProperty[] props) { _cubemap = FindProperty("_Tex", props); _tint = FindProperty("_Tint", props); _euler = FindProperty("_Euler", props); _exposure = FindProperty("_Exposure", props); _saturation = FindProperty("_Saturation", props); _lod = FindProperty("_Lod", props); _lodLevel = FindProperty("_LodLevel", props); }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (prop.type != MaterialProperty.PropType.Range) { GUIContent label2 = EditorGUIUtility.TempContent("PowerSlider used on a non-range property: " + prop.name, EditorGUIUtility.GetHelpIcon(MessageType.Warning)); EditorGUI.LabelField(position, label2, EditorStyles.helpBox); return; } MaterialEditor.DoPowerRangeProperty(position, prop, label, this.power); }
private void SetKeyword(MaterialProperty prop, bool on) { string keyword = !string.IsNullOrEmpty(this.keyword) ? this.keyword : prop.name.ToUpperInvariant() + "_ON"; foreach (Material target in prop.targets) { if (on) target.EnableKeyword(keyword); else target.DisableKeyword(keyword); } }
/// <summary> /// <para>Find shader properties.</para> /// </summary> /// <param name="propertyName">Name of the material property.</param> /// <param name="properties">The array of available properties.</param> /// <param name="propertyIsMandatory">If true then this method will throw an exception if a property with propertyName was not found.</param> /// <returns> /// <para>The material property found, otherwise null.</para> /// </returns> protected static MaterialProperty FindProperty(string propertyName, MaterialProperty[] properties, bool propertyIsMandatory) { for (int index = 0; index < properties.Length; ++index) { if (properties[index] != null && properties[index].name == propertyName) return properties[index]; } if (propertyIsMandatory) throw new ArgumentException("Could not find MaterialProperty: '" + propertyName + "', Num properties: " + (object) properties.Length); return (MaterialProperty) null; }
public void BeginAnimatedCheck(MaterialProperty prop) { if (this.m_RendererForAnimationMode != null) { this.m_PreviousGUIColor = GUI.color; if (MaterialAnimationUtility.IsAnimated(prop, this.m_RendererForAnimationMode)) { GUI.color = AnimationMode.animatedPropertyColor; } } }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (prop.type != MaterialProperty.PropType.Range) { GUIContent c = EditorGUIUtility.TempContent("IntRange used on a non-range property: " + prop.name, EditorGUIUtility.GetHelpIcon(MessageType.Warning)); EditorGUI.LabelField(position, c, EditorStyles.helpBox); return; } MaterialEditor.DoIntRangeProperty(position, prop, label); }
public override float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { float height = base.GetPropertyHeight(prop, label, editor); if (prop.type == MaterialProperty.PropType.Vector) { return(height * 2); } else { return(height); } }
public virtual void FindProperties(MaterialProperty[] properties) { surfaceTypeProp = FindProperty("_Surface", properties); blendModeProp = FindProperty("_Blend", properties); cullingProp = FindProperty("_Cull", properties); alphaClipProp = FindProperty("_AlphaClip", properties); alphaCutoffProp = FindProperty("_Cutoff", properties); receiveShadowsProp = FindProperty("_ReceiveShadows", properties, false); baseMapProp = FindProperty("_BaseMap", properties, false); baseColorProp = FindProperty("_BaseColor", properties, false); emissionMapProp = FindProperty("_EmissionMap", properties, false); emissionColorProp = FindProperty("_EmissionColor", properties, false); queueOffsetProp = FindProperty("_QueueOffset", properties, false); }
public override void Apply(MaterialProperty prop) { base.Apply(prop); if (!IsPropertyTypeSuitable(prop)) { return; } if (prop.hasMixedValue) { return; } SetKeyword(prop, (int)prop.floatValue); }
private void SetKeyword(MaterialProperty prop, bool on) { string keyword = !string.IsNullOrEmpty(this.keyword) ? this.keyword : prop.name.ToUpperInvariant() + "_ON"; foreach (Material target in prop.targets) { if (on) { target.EnableKeyword(keyword); } else { target.DisableKeyword(keyword); } } }
public void FindProperties(MaterialProperty[] props) { blendMode = FindProperty("_Mode", props); //mixMode = FindProperty("_Mix", props); albedoMap = FindProperty("_MainTex", props); albedoColor = FindProperty("_Color", props); alphaCutoff = FindProperty("_Cutoff", props); specularMap = FindProperty("_SpecGlossMap", props, false); specularColor = FindProperty("_SpecColor", props, false); metallicMap = FindProperty("_MetallicGlossMap", props, false); metallic = FindProperty("_Metallic", props, false); if (specularMap != null && specularColor != null) { m_WorkflowMode = WorkflowMode.Specular; } else if (metallicMap != null && metallic != null) { m_WorkflowMode = WorkflowMode.Metallic; } else { m_WorkflowMode = WorkflowMode.Dielectric; } smoothness = FindProperty("_Glossiness", props); smoothnessScale = FindProperty("_GlossMapScale", props, false); smoothnessMapChannel = FindProperty("_SmoothnessTextureChannel", props, false); highlights = FindProperty("_SpecularHighlights", props, false); reflections = FindProperty("_GlossyReflections", props, false); bumpScale = FindProperty("_BumpScale", props); bumpMap = FindProperty("_BumpMap", props); heigtMapScale = FindProperty("_Parallax", props); heightMap = FindProperty("_ParallaxMap", props); occlusionStrength = FindProperty("_OcclusionStrength", props); occlusionMap = FindProperty("_OcclusionMap", props); emissionColorForRendering = FindProperty("_EmissionColor", props); emissionMap = FindProperty("_EmissionMap", props); detailMask = FindProperty("_DetailMask", props); detailAlbedoMap = FindProperty("_DetailAlbedoMap", props); detailSpecMap = FindProperty("_DetailSpecMap", props); detailSmoothness = FindProperty("_DetailSmoothness", props); detailSmoothnessScale = FindProperty("_DetailSmoothMapScale", props, false); detailSpecularColor = FindProperty("_DetailSpecColor", props, false); detailNormalMapScale = FindProperty("_DetailNormalMapScale", props); detailNormalMap = FindProperty("_DetailNormalMap", props); uvSetSecondary = FindProperty("_UVSec", props); //mixDetailColors = FindProperty("_Mix", props); }
// Mini texture slot, with two extra controls on the same line (allocates rect in GUILayout) // Have up to 3 controls on one line public Rect TexturePropertySingleLine(GUIContent label, MaterialProperty textureProp, MaterialProperty extraProperty1, MaterialProperty extraProperty2) { Rect r = GetControlRectForSingleLine(); TexturePropertyMiniThumbnail(r, textureProp, label.text, label.tooltip); // No extra properties: early out if (extraProperty1 == null && extraProperty2 == null) { return(r); } // Temporarily reset the indent level as it was already used earlier to compute the positions of the layout items. See issue 946082. int oldIndentLevel = EditorGUI.indentLevel; EditorGUI.indentLevel = 0; // One extra property if (extraProperty1 == null || extraProperty2 == null) { var prop = extraProperty1 ?? extraProperty2; if (prop.type == MaterialProperty.PropType.Color) { ExtraPropertyAfterTexture(GetLeftAlignedFieldRect(r), prop); } else { ExtraPropertyAfterTexture(GetRectAfterLabelWidth(r), prop); } } else // Two extra properties { if (extraProperty1.type == MaterialProperty.PropType.Color) { ExtraPropertyAfterTexture(GetFlexibleRectBetweenFieldAndRightEdge(r), extraProperty2); ExtraPropertyAfterTexture(GetLeftAlignedFieldRect(r), extraProperty1); } else { ExtraPropertyAfterTexture(GetRightAlignedFieldRect(r), extraProperty2); ExtraPropertyAfterTexture(GetFlexibleRectBetweenLabelAndField(r), extraProperty1); } } // Restore the indent level EditorGUI.indentLevel = oldIndentLevel; return(r); }
void ExtraPropertyAfterTexture(Rect r, MaterialProperty property) { if ((property.type == MaterialProperty.PropType.Float || property.type == MaterialProperty.PropType.Color) && r.width > EditorGUIUtility.fieldWidth) { // We want color fields and float fields to have same width as EditorGUIUtility.fieldWidth // so controls aligns vertically. // This also makes us able to have a draggable area in front of the float fields. We therefore ensures // the property has a label (here we use a whitespace) and adjust label width. float oldLabelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = r.width - EditorGUIUtility.fieldWidth; ShaderProperty(r, property, " "); EditorGUIUtility.labelWidth = oldLabelWidth; return; } ShaderProperty(r, property, string.Empty); }
internal static void DrawFloatToggleProperty(GUIContent styles, MaterialProperty prop) { if (prop == null) { return; } EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; bool newValue = EditorGUILayout.Toggle(styles, prop.floatValue == 1); if (EditorGUI.EndChangeCheck()) { prop.floatValue = newValue ? 1.0f : 0.0f; } EditorGUI.showMixedValue = false; }
public float GetPropertyHeight(MaterialProperty prop, string label, MaterialEditor editor) { var height = 0f; if (m_DecoratorDrawers != null) { foreach (var drawer in m_DecoratorDrawers) { height += drawer.GetPropertyHeight(prop, label, editor); } } if (m_PropertyDrawer != null) { height += m_PropertyDrawer.GetPropertyHeight(prop, label, editor); } return(height); }
private bool?ToggleShaderProperty(MaterialProperty prop, bool enable, bool hasMixedEnable) { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = hasMixedEnable; enable = EditorGUI.ToggleLeft(EditorGUILayout.GetControlRect(false, GUILayout.ExpandWidth(false)), prop.displayName, enable); EditorGUI.showMixedValue = false; bool?retValue = EditorGUI.EndChangeCheck() ? (bool?)enable : null; GUILayout.Space(-EditorGUIUtility.singleLineHeight); using (new EditorGUI.DisabledScope(!enable && !hasMixedEnable)) { EditorGUI.showMixedValue = prop.hasMixedValue; ShaderProperty(prop, " "); EditorGUI.showMixedValue = false; } return(retValue); }
public void FindProperties(MaterialProperty[] props) { blendMode = FindProperty("_Mode", props); cullMode = FindProperty("_CullMode", props, false); albedoMap = FindProperty("_MainTex", props); albedoColor = FindProperty("_Color", props); alphaCutoff = FindProperty("_Cutoff", props); specularMap = FindProperty("_SpecGlossMap", props, false); specularColor = FindProperty("_SpecColor", props, false); metallicMap = FindProperty("_MetallicGlossMap", props, false); metallic = FindProperty("_Metallic", props, false); if (specularMap != null && specularColor != null) { m_WorkflowMode = WorkflowMode.Specular; } else if (metallicMap != null && metallic != null) { m_WorkflowMode = WorkflowMode.Metallic; } else { m_WorkflowMode = WorkflowMode.Dielectric; } smoothness = FindProperty("_Glossiness", props); smoothnessTweak1 = FindProperty("_SmoothnessTweak1", props, false); smoothnessTweak2 = FindProperty("_SmoothnessTweak2", props, false); smoothnessTweaks = FindProperty("_SmoothnessTweaks", props, false); specularMapColorTweak = FindProperty("_SpecularMapColorTweak", props, false); bumpScale = FindProperty("_BumpScale", props); bumpMap = FindProperty("_BumpMap", props); orthoNormalize = FindProperty("_Orthonormalize", props, false); heigtMapScale = FindProperty("_Parallax", props); heightMap = FindProperty("_ParallaxMap", props); occlusionStrength = FindProperty("_OcclusionStrength", props); occlusionMap = FindProperty("_OcclusionMap", props); emissionColorForRendering = FindProperty("_EmissionColor", props); emissionMap = FindProperty("_EmissionMap", props); detailMask = FindProperty("_DetailMask", props); detailAlbedoMap = FindProperty("_DetailAlbedoMap", props); detailNormalMapScale = FindProperty("_DetailNormalMapScale", props); detailNormalMap = FindProperty("_DetailNormalMap", props); uvSetSecondary = FindProperty("_UVSec", props); smoothnessInAlbedo = FindProperty("_SmoothnessInAlbedo", props, false); }
protected void SetKeywordInternal(MaterialProperty prop, bool on, string defaultKeywordSuffix) { // if no keyword is provided, use <uppercase property name> + defaultKeywordSuffix string kw = string.IsNullOrEmpty(keyword) ? prop.name.ToUpperInvariant() + defaultKeywordSuffix : keyword; // set or clear the keyword foreach (Material material in prop.targets) { if (on) { material.EnableKeyword(kw); } else { material.DisableKeyword(kw); } } }
void SetKeyword(MaterialProperty prop, int index) { for (int i = 0; i < keywords.Length; ++i) { string keyword = GetKeywordName(prop.name, keywords[i].text); foreach (Material material in prop.targets) { if (index == i) { material.EnableKeyword(keyword); } else { material.DisableKeyword(keyword); } } } }
private void SetKeyword(MaterialProperty prop, int index) { for (int i = 0; i < this.keywords.Length; i++) { string keywordName = GetKeywordName(prop.name, this.keywords[i]); foreach (Material material in prop.targets) { if (index == i) { material.EnableKeyword(keywordName); } else { material.DisableKeyword(keywordName); } } } }
//////////////////////////////////// // Helper Functions // //////////////////////////////////// #region HelperFunctions public static void TwoFloatSingleLine(GUIContent title, MaterialProperty prop1, GUIContent prop1Label, MaterialProperty prop2, GUIContent prop2Label, MaterialEditor materialEditor, float labelWidth = 30f) { const int kInterFieldPadding = 2; Rect rect = EditorGUILayout.GetControlRect(); EditorGUI.PrefixLabel(rect, title); var indent = EditorGUI.indentLevel; var preLabelWidth = EditorGUIUtility.labelWidth; EditorGUI.indentLevel = 0; EditorGUIUtility.labelWidth = labelWidth; Rect propRect1 = new Rect(rect.x + preLabelWidth, rect.y, (rect.width - preLabelWidth) * 0.5f - 1, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop1.hasMixedValue; var prop1val = EditorGUI.FloatField(propRect1, prop1Label, prop1.floatValue); if (EditorGUI.EndChangeCheck()) { prop1.floatValue = prop1val; } Rect propRect2 = new Rect(propRect1.x + propRect1.width + kInterFieldPadding, rect.y, propRect1.width, EditorGUIUtility.singleLineHeight); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop2.hasMixedValue; var prop2val = EditorGUI.FloatField(propRect2, prop2Label, prop2.floatValue); if (EditorGUI.EndChangeCheck()) { prop2.floatValue = prop2val; } EditorGUI.indentLevel = indent; EditorGUIUtility.labelWidth = preLabelWidth; EditorGUI.showMixedValue = false; }
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) { blendMode = FindProperty("_Mode", props); albedoMap = FindProperty("_MainTex", props); albedoColor = FindProperty("_Color", props); alphaCutoff = FindProperty("_Cutoff", props); specularMap = FindProperty("_SpecGlossMap", props, false); specularColor = FindProperty("_SpecColor", props, false); metallicMap = FindProperty("_MetallicGlossMap", props, false); metallic = FindProperty("_Metallic", props, false); if (specularMap != null && specularColor != null) { m_WorkflowMode = WorkflowMode.Specular; } else if (metallicMap != null && metallic != null) { m_WorkflowMode = WorkflowMode.Metallic; } else { m_WorkflowMode = WorkflowMode.Dielectric; } smoothness = FindProperty("_Glossiness", props); bumpScale = FindProperty("_BumpScale", props); bumpMap = FindProperty("_BumpMap", props); heigtMapScale = FindProperty("_Parallax", props); heightMap = FindProperty("_ParallaxMap", props); occlusionStrength = FindProperty("_OcclusionStrength", props); occlusionMap = FindProperty("_OcclusionMap", props); emissionColorForRendering = FindProperty("_EmissionColor", props); emissionMap = FindProperty("_EmissionMap", props); detailMask = FindProperty("_DetailMask", props); detailAlbedoMap = FindProperty("_DetailAlbedoMap", props); detailNormalMapScale = FindProperty("_DetailNormalMapScale", props); detailNormalMap = FindProperty("_DetailNormalMap", props); uvSetSecondary = FindProperty("_UVSec", props); // RTP - geom blend _TERRAIN_HeightMap = FindProperty("_TERRAIN_HeightMap", props); _TERRAIN_Control = FindProperty("_TERRAIN_Control", props); _TERRAIN_PosSize = FindProperty("_TERRAIN_PosSize", props); _TERRAIN_Tiling = FindProperty("_TERRAIN_Tiling", props); }
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { // Sync the lighting flag for the unlit shader if (newShader.name.Contains("Unlit")) { material.SetFloat("_LightingEnabled", 0.0f); } else { material.SetFloat("_LightingEnabled", 1.0f); } // _Emission property is lost after assigning Standard shader to the material // thus transfer it before assigning the new shader if (material.HasProperty("_Emission")) { material.SetColor("_EmissionColor", material.GetColor("_Emission")); } base.AssignNewShaderToMaterial(material, oldShader, newShader); if (oldShader == null || !oldShader.name.Contains("Legacy Shaders/")) { SetupMaterialWithBlendMode(material, (BlendMode)material.GetFloat("_Mode")); return; } BlendMode blendMode = BlendMode.Opaque; if (oldShader.name.Contains("/Transparent/Cutout/")) { blendMode = BlendMode.Cutout; } else if (oldShader.name.Contains("/Transparent/")) { // NOTE: legacy shaders did not provide physically based transparency // therefore Fade mode blendMode = BlendMode.Fade; } material.SetFloat("_Mode", (float)blendMode); MaterialChanged(material); }
public void FindProperties(MaterialProperty[] props) { unlit = FindProperty("g_bUnlit", props); blendMode = FindProperty("_Mode", props); specularMode = FindProperty("_SpecularMode", props); albedoMap = FindProperty("_MainTex", props); albedoColor = FindProperty("_Color", props); alphaCutoff = FindProperty("_Cutoff", props); specularMap = FindProperty("_SpecGlossMap", props, false); specularColor = FindProperty("_SpecColor", props, false); reflectanceMin = FindProperty("g_flReflectanceMin", props); reflectanceMax = FindProperty("g_flReflectanceMax", props); metallicMap = FindProperty("_MetallicGlossMap", props, false); metallic = FindProperty("_Metallic", props, false); smoothness = FindProperty("_Glossiness", props); bumpScale = FindProperty("_BumpScale", props); bumpMap = FindProperty("_BumpMap", props); heigtMapScale = FindProperty("_Parallax", props); heightMap = FindProperty("_ParallaxMap", props); cubeMapScalar = FindProperty("g_flCubeMapScalar", props); occlusionStrength = FindProperty("_OcclusionStrength", props); occlusionStrengthDirectDiffuse = FindProperty("_OcclusionStrengthDirectDiffuse", props); occlusionStrengthDirectSpecular = FindProperty("_OcclusionStrengthDirectSpecular", props); occlusionStrengthIndirectDiffuse = FindProperty("_OcclusionStrengthIndirectDiffuse", props); occlusionStrengthIndirectSpecular = FindProperty("_OcclusionStrengthIndirectSpecular", props); occlusionMap = FindProperty("_OcclusionMap", props); emissionColorForRendering = FindProperty("_EmissionColor", props); emissionMap = FindProperty("_EmissionMap", props); detailMask = FindProperty("_DetailMask", props); detailAlbedoMap = FindProperty("_DetailAlbedoMap", props); detailNormalMapScale = FindProperty("_DetailNormalMapScale", props); detailNormalMap = FindProperty("_DetailNormalMap", props); uvSetSecondary = FindProperty("_UVSec", props); receiveShadows = FindProperty("g_bReceiveShadows", props); renderBackfaces = FindProperty("g_bRenderBackfaces", props); overrideLightmap = FindProperty("g_tOverrideLightmap", props); worldAlignedTexture = FindProperty("g_bWorldAlignedTexture", props, false); worldAlignedTextureSize = FindProperty("g_vWorldAlignedTextureSize", props, worldAlignedTexture != null); worldAlignedTextureNormal = FindProperty("g_vWorldAlignedTextureNormal", props, worldAlignedTexture != null); worldAlignedTexturePosition = FindProperty("g_vWorldAlignedTexturePosition", props, worldAlignedTexture != null); }
public static void DoPopup(GUIContent label, MaterialProperty property, string[] options, MaterialEditor materialEditor) { if (property == null) { throw new ArgumentNullException("property"); } EditorGUI.showMixedValue = property.hasMixedValue; var mode = property.floatValue; EditorGUI.BeginChangeCheck(); mode = EditorGUILayout.Popup(label, (int)mode, options); if (EditorGUI.EndChangeCheck()) { materialEditor.RegisterPropertyChangeUndo(label.text); property.floatValue = mode; } EditorGUI.showMixedValue = false; }
public static void DrawNormalArea(MaterialEditor materialEditor, MaterialProperty bumpMap, MaterialProperty bumpMapScale = null) { if (bumpMapScale != null) { materialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap, bumpMap.textureValue != null ? bumpMapScale : null); if (bumpMapScale.floatValue != 1 && UnityEditorInternal.InternalEditorUtility.IsMobilePlatform( EditorUserBuildSettings.activeBuildTarget)) { if (materialEditor.HelpBoxWithButton(Styles.bumpScaleNotSupported, Styles.fixNormalNow)) { bumpMapScale.floatValue = 1; } } } else { materialEditor.TexturePropertySingleLine(Styles.normalMapText, bumpMap); } }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (!IsPropertyTypeSuitable(prop)) { GUIContent content = EditorGUIUtility.TempContent("KeywordEnum used on a non-float property: " + prop.name, EditorGUIUtility.GetHelpIcon(MessageType.Warning)); EditorGUI.LabelField(position, content, EditorStyles.helpBox); } else { EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; int floatValue = (int)prop.floatValue; floatValue = EditorGUI.Popup(position, label, floatValue, this.keywords); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { prop.floatValue = floatValue; this.SetKeyword(prop, floatValue); } } }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { if (!MaterialToggleDrawer.IsPropertyTypeSuitable(prop)) { GUIContent label1 = EditorGUIUtility.TempContent("Toggle used on a non-float property: " + prop.name, (Texture)EditorGUIUtility.GetHelpIcon(MessageType.Warning)); EditorGUI.LabelField(position, label1, EditorStyles.helpBox); } else { EditorGUI.BeginChangeCheck(); bool flag = (double)Math.Abs(prop.floatValue) > 1.0 / 1000.0; EditorGUI.showMixedValue = prop.hasMixedValue; bool on = EditorGUI.Toggle(position, label, flag); EditorGUI.showMixedValue = false; if (!EditorGUI.EndChangeCheck()) { return; } prop.floatValue = !on ? 0.0f : 1f; this.SetKeyword(prop, on); } }