public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor) { var stylePopup = new GUIStyle(EditorStyles.popup) { fontSize = 9, alignment = TextAnchor.MiddleCenter, }; var internalReference = MaterialEditor.GetMaterialProperty(editor.targets, reference); Vector4 propVector = prop.vectorValue; GUILayout.Space(top); EditorGUI.BeginChangeCheck(); EditorGUI.showMixedValue = prop.hasMixedValue; GUILayout.BeginHorizontal(); GUILayout.Space(-1); GUILayout.Label(label, GUILayout.Width(EditorGUIUtility.labelWidth)); if (propVector.w == 0) { propVector.y = EditorGUILayout.FloatField(propVector.y); } else if (propVector.w == 1) { propVector.z = EditorGUILayout.FloatField(propVector.z); } GUILayout.Space(2); propVector.w = (float)EditorGUILayout.Popup((int)propVector.w, new string[] { "Nits", "EV100" }, stylePopup, GUILayout.Width(50)); GUILayout.EndHorizontal(); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { if (propVector.w == 0) { propVector.x = propVector.y; } else if (propVector.w == 1) { propVector.x = ConvertEvToLuminance(propVector.z); } if (internalReference.displayName != null) { internalReference.floatValue = propVector.x; } prop.vectorValue = propVector; } GUILayout.Space(down); }
/// <summary> /// Make a field to receive any object type. /// </summary> public static Texture TextureField(MaterialEditor materialEditor, string property, GUIContent label, bool scaleOffset, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; Texture t = (Texture)EditorGUILayout.ObjectField(label, p.textureValue, typeof(Texture), false, options); Vector2 textureTiling = Vector2.one; Vector2 textureOffset = Vector2.one; if (scaleOffset) { EditorGUI.indentLevel++; textureTiling = EditorGUILayout.Vector2Field("Tiling", new Vector2(p.textureScaleAndOffset.x, p.textureScaleAndOffset.y)); textureOffset = EditorGUILayout.Vector2Field("Offset", new Vector2(p.textureScaleAndOffset.z, p.textureScaleAndOffset.w)); EditorGUI.indentLevel--; EditorGUILayout.Space(); } EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { p.textureValue = t; if (scaleOffset) { p.textureScaleAndOffset = new Vector4(textureTiling.x, textureTiling.y, textureOffset.x, textureOffset.y); ; } } return(t); }
public static object GetMaterialPropertyValue(SearchSelectorArgs args) { if (!(args["propertyPath"] is string propertyPath)) { return(null); } var item = args.current; var material = item.ToObject <Material>(); if (!material) { return(null); } var matProp = MaterialEditor.GetMaterialProperty(new Object[] { material }, propertyPath); if (matProp == null || matProp.name == null) { var materialProperties = MaterialEditor.GetMaterialProperties(new Object[] { material }); for (var i = 0; i < materialProperties.Length; i++) { if (!materialProperties[i].name.EndsWith(propertyPath, System.StringComparison.OrdinalIgnoreCase)) { continue; } matProp = materialProperties[i]; break; } } return(GetMaterialPropertyValue(matProp)); }
internal static MaterialProperty GetMaterialProperty(SearchItem item, SearchColumn column) { var mat = item.ToObject <Material>(); if (!mat) { return(null); } foreach (var m in SelectorManager.Match(column.selector, item.provider?.type)) { var selectorArgs = new SearchSelectorArgs(m, item); if (selectorArgs.name == null) { continue; } if (!mat.HasProperty(selectorArgs.name)) { continue; } return(MaterialEditor.GetMaterialProperty(new Object[] { mat }, selectorArgs.name)); } return(null); }
public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor) { // Find properties var assetProperty = MaterialEditor.GetMaterialProperty(editor.targets, prop.name + "_Asset"); DiffusionProfileMaterialUI.OnGUI(editor, assetProperty, prop, 0, prop.displayName); }
public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { if (!IsPropertyTypeSuitable(prop)) { EditorGUI.HelpBox(position, "EZTextureSingleLine used on a non-texture property: " + prop.name, MessageType.Warning); return; } if (!string.IsNullOrEmpty(extraPropertyName1)) { extraProperty1 = MaterialEditor.GetMaterialProperty(editor.targets, extraPropertyName1); } if (!string.IsNullOrEmpty(extraPropertyName2)) { extraProperty2 = MaterialEditor.GetMaterialProperty(editor.targets, extraPropertyName2); } float labelWidth = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = 0; editor.TexturePropertySingleLine(label, prop, extraProperty1, extraProperty2); EditorGUI.indentLevel++; editor.TextureScaleOffsetProperty(prop); EditorGUI.indentLevel--; EditorGUIUtility.labelWidth = labelWidth; }
/// <summary> /// Displays fields fpr all magic light parameters /// </summary> /// <param name="me"></param> /// <param name="isSurfaceShader"></param> protected void ShowMagicLightParams(MaterialEditor me, bool isSurfaceShader) { // Toggle to use magic light MultiMaterialEditorGUI.ShaderPropertyField(me, "_UseMagicLight", "Use Magic Light"); MaterialProperty useMagicLight = MaterialEditor.GetMaterialProperty(me.targets, "_UseMagicLight"); // only show the rest if the magic light is used if (useMagicLight.floatValue > 0) { ++EditorGUI.indentLevel; bool useStencil = MultiMaterialEditorGUI.ToggleLeft(me, "_UseStencil", "Use Stencil"); // display stencil map if stencil is used if (useStencil) { ++EditorGUI.indentLevel; MultiMaterialEditorGUI.TextureField(me, "_StencilMap", new GUIContent("Stencil Map (RGB)", "R -> Cutout, G -> Border 1, B -> Border 2"), true); --EditorGUI.indentLevel; } else // display scale factor and invert option if no stencil is used { MultiMaterialEditorGUI.ToggleLeft(me, "_Inverted", "Inverted"); MultiMaterialEditorGUI.FloatField(me, "_RadiusScaleFactor", "Light Radius Scale Factor"); } ShowAnimationParams(me); ShowBorderOptions(me, useStencil, isSurfaceShader); --EditorGUI.indentLevel; } }
public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor) { var guid = HDUtilsEx.ConvertVector4ToGUID(prop.vectorValue); var profile = AssetDatabase.LoadAssetAtPath(AssetDatabase.GUIDToAssetPath(guid), DiffusionProfileSettingsEx.Type); EditorGUI.BeginChangeCheck(); profile = EditorGUI.ObjectField(position, new GUIContent(label), profile, DiffusionProfileSettingsEx.Type, false); if (EditorGUI.EndChangeCheck()) { Vector4 newGuid = Vector4.zero; float hash = 0; if (profile != null) { var guid2 = AssetDatabase.AssetPathToGUID(AssetDatabase.GetAssetPath(profile)); newGuid = HDUtilsEx.ConvertGUIDToVector4(guid2); hash = HDShadowUtilsEx.Asfloat(DiffusionProfileSettingsEx.Hash(profile)); } prop.vectorValue = newGuid; var hashField = MaterialEditor.GetMaterialProperty(new UnityEngine.Object[] { editor.target }, m_hashField); if (hashField != null) { hashField.floatValue = hash; } } if (profile == null) { prop.vectorValue = Vector4.zero; } DiffusionProfileMaterialUIEx.DrawDiffusionProfileWarning(profile); }
protected virtual bool HasToggle(MaterialProperty prop) { var targets = prop.targets; var toggle = MaterialEditor.GetMaterialProperty(targets, togglePropertyName); return(toggle != null && toggle.type == MaterialProperty.PropType.Float || toggle.type == MaterialProperty.PropType.Range); }
void DrawTransparencyMode(MaterialEditor materialEditor, Object[] materials) { // TODO: This could be way better bool hasMixed = false; int baseVal = (materials[0] as Material).renderQueue; int index = (baseVal < (int)RenderQueue.Transparent) ? 0 : 1; if (materials.Length > 1) { for (int i = 1; i < materials.Length; i++) { if ((materials[i] as Material).renderQueue != baseVal) { hasMixed = true; index = -1; break; } } } EditorGUI.showMixedValue = hasMixed; EditorGUI.BeginChangeCheck(); { index = EditorGUILayout.Popup("Mode", index, TransparencyModeKeys); } if (EditorGUI.EndChangeCheck()) { if (index > -1) { foreach (Material m in materials) { m.renderQueue = (int)TransparencyModeVals[index]; } } } EditorGUI.showMixedValue = false; EditorGUILayout.Space(); if (index > 0) // Transparent? { MaterialProperty BlendSrc = MaterialEditor.GetMaterialProperty( materials, MaterialProps.BlendSrc); MaterialProperty BlendDst = MaterialEditor.GetMaterialProperty( materials, MaterialProps.BlendDst); MaterialProperty ZTest = MaterialEditor.GetMaterialProperty( materials, MaterialProps.ZTest); MaterialProperty ZWrite = MaterialEditor.GetMaterialProperty( materials, MaterialProps.ZWrite); MaterialProperty CullMode = MaterialEditor.GetMaterialProperty( materials, MaterialProps.CullMode); GUILayout.Label("Transparent Properties", EditorStyles.boldLabel); materialEditor.ShaderProperty(BlendSrc, BlendSrc.displayName); materialEditor.ShaderProperty(BlendDst, BlendDst.displayName); materialEditor.ShaderProperty(ZTest, ZTest.displayName); materialEditor.ShaderProperty(ZWrite, ZWrite.displayName); materialEditor.ShaderProperty(CullMode, CullMode.displayName); } }
public static void ShaderPropertyField(MaterialEditor materialEditor, string property, string label, Rect position) { MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; materialEditor.ShaderProperty(position, p, label); EditorGUI.showMixedValue = false; }
public static void ShaderPropertyField(MaterialEditor materialEditor, string property, GUIContent label) { MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; materialEditor.ShaderProperty(p, label); EditorGUI.showMixedValue = false; }
public static void PropertyField(string property, Material material, string context = "") { MaterialProperty lProp = MaterialEditor.GetMaterialProperty(new Object[] { material }, property); if (scopeMaterial.HasProperty(property) && lProp != null) { PropertyField(lProp, material, context); } }
public override void OnGUI(Rect position, MaterialProperty prop, string label, MaterialEditor editor) { var property = MaterialEditor.GetMaterialProperty(editor.targets, propertyName); if (property.floatValue == value) { editor.DefaultShaderProperty(prop, label); } }
// Draw the property inside the given rect public override void OnGUI(Rect position, MaterialProperty prop, String label, MaterialEditor editor) { if (InputError) { EditorGUI.LabelField(position, "EditableIf Attribute Error: Input parameters are invalid!"); return; } var LHSprop = MaterialEditor.GetMaterialProperty(prop.targets, FieldName); if (string.IsNullOrEmpty(LHSprop.name)) { LHSprop = MaterialEditor.GetMaterialProperty(prop.targets, "_" + FieldName.Replace(" ", "")); if (string.IsNullOrEmpty(LHSprop.name)) { EditorGUI.LabelField(position, "EditableIf Attribute Error: " + FieldName + " Does not exist!"); return; } } object LHSVal = null; bool test = false; switch (LHSprop.type) { case MaterialProperty.PropType.Color: case MaterialProperty.PropType.Vector: LHSVal = LHSprop.type == MaterialProperty.PropType.Color ? (Vector4)LHSprop.colorValue : LHSprop.vectorValue; var v4 = ExpectedValue as Vector4?; v4 = v4.HasValue ? v4 : new Vector4((System.Single)ExpectedValue, float.NegativeInfinity, float.NegativeInfinity, float.NegativeInfinity); if (LHSprop.type == MaterialProperty.PropType.Color) { test = VectorCheck((Vector4)LHSVal, op, v4 / 255); } else { test = VectorCheck((Vector4)LHSVal, op, v4); } break; case MaterialProperty.PropType.Range: case MaterialProperty.PropType.Float: LHSVal = LHSprop.floatValue; test = (Check(LHSVal, op, ExpectedValue)); break; case MaterialProperty.PropType.Texture: LHSVal = LHSprop.textureValue; test = (CheckObject(LHSVal, op, ExpectedValue)); break; } GUI.enabled = test; editor.DefaultShaderProperty(position, prop, label); GUI.enabled = true; }
public ThryEditorHeader(MaterialEditor materialEditor, string propertyName) { this.propertyes = new List <MaterialProperty>(); foreach (Material materialEditorTarget in materialEditor.targets) { UnityEngine.Object[] asArray = new UnityEngine.Object[] { materialEditorTarget }; propertyes.Add(MaterialEditor.GetMaterialProperty(asArray, propertyName)); } this.currentState = fetchState(); }
public void TexturesSection() { GUILayout.Space(10); MaterialProperty tex = MaterialEditor.GetMaterialProperty(targets, "_DistortionTexture"); TextureProperty(tex, "Distortion Texture (Multi Channel)"); MaterialProperty tex2 = MaterialEditor.GetMaterialProperty(targets, "_FoamTexture"); TextureProperty(tex2, "Foam Texture"); }
public void MaterialPropertyField(string varName, string displayName, float dropWidth) { var matProp = MaterialEditor.GetMaterialProperty(Targets, varName); float old = EditorGUIUtility.labelWidth; EditorGUIUtility.labelWidth = Screen.width - dropWidth - 20.0f; MatEditor.ShaderProperty(matProp, ObjectNames.NicifyVariableName(displayName)); EditorGUIUtility.labelWidth = old; }
private MaterialProperty GetMaterialProperty() { if (_materialInsteadOfEditor) { return(MaterialEditor.GetMaterialProperty(new Material[] { _materialInsteadOfEditor }, _obj)); } if (_propertyObj != null) { return(_propertyObj.MaterialProperty); } return(null); }
public Texture TextureField(string label, Material material, string propertyName) { Texture texture = material.GetTexture(propertyName): MaterialProperty property = MaterialEditor.GetMaterialProperty(new[] { material }, propertyName): Texture newTexture = base.TextureProperty(property, label): if (newTexture != texture) { Undo.RecordObject(material, label + " change"): material.SetTexture(propertyName, newTexture): } return newTexture: }
public override void AssignNewShaderToMaterial(Material material, Shader oldShader, Shader newShader) { Debug.Log("Assign new Shader"); base.AssignNewShaderToMaterial(material, oldShader, newShader); MaterialProperty prop = MaterialEditor.GetMaterialProperty(new Object[1] { material }, MaterialProps.ZWrite); if (prop != null) { material.SetShaderPassEnabled(Passes.ZPRIME, prop.floatValue != 0); } }
void OnInspectorMaterialParameters(Object[] materialList, int number) { GUILayout.Label("Material " + number.ToString(), TitlesStyle); GUILayout.BeginVertical("box"); DrawProperty(MaterialEditor.GetMaterialProperty(materialList, "Material" + number.ToString() + "_Scale"), "Material " + number.ToString() + " coords"); DrawProperty(MaterialEditor.GetMaterialProperty(materialList, "Material" + number.ToString() + "_NormalIntensity"), "Normal intensity " + number.ToString()); if (m_UseNormalFromMask && number > 1) { DrawProperty(MaterialEditor.GetMaterialProperty(materialList, "Material" + number.ToString() + "_NormalFromMaskIntensity"), "Normal from Mask Intensity " + number.ToString()); DrawProperty(MaterialEditor.GetMaterialProperty(materialList, "Material" + number.ToString() + "_NormalFromMaskOffset"), "Normal from Mask " + (number - 1).ToString() + " Offset"); } GUILayout.EndVertical(); }
protected void AssignMaterialPropertiesFromEdges(List <SerializableEdge> edges, Material material) { // Update material settings when processing the graph: foreach (var edge in edges) { var prop = MaterialEditor.GetMaterialProperty(new [] { material }, edge.inputPort.portData.identifier); switch (prop.type) { case MaterialProperty.PropType.Color: prop.colorValue = (Color)edge.passThroughBuffer; break; case MaterialProperty.PropType.Texture: // TODO: texture scale and offset prop.textureValue = (Texture)edge.passThroughBuffer; break; case MaterialProperty.PropType.Float: case MaterialProperty.PropType.Range: switch (edge.passThroughBuffer) { case float f: prop.floatValue = f; break; case Vector2 v: prop.floatValue = v.x; break; case Vector3 v: prop.floatValue = v.x; break; case Vector4 v: prop.floatValue = v.x; break; default: throw new Exception($"Can't assign {edge.passThroughBuffer.GetType()} to material float property"); } break; case MaterialProperty.PropType.Vector: prop.vectorValue = MixtureConversions.ConvertObjectToVector4(edge.passThroughBuffer); break; } } }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { //base.OnGUI(materialEditor, properties); Object[] materials = materialEditor.targets; // Gather Properties MaterialProperty _MainTex = MaterialEditor.GetMaterialProperty( materials, MaterialProps._MainTex); MaterialProperty _Color = MaterialEditor.GetMaterialProperty( materials, MaterialProps._Color); MaterialProperty _NormalTex = MaterialEditor.GetMaterialProperty( materials, MaterialProps._NormalTex); MaterialProperty SPEC = MaterialEditor.GetMaterialProperty( materials, MaterialProps.SPEC); MaterialProperty _SpecColor = MaterialEditor.GetMaterialProperty( materials, MaterialProps._SpecColor); MaterialProperty _CubeTex = MaterialEditor.GetMaterialProperty( materials, MaterialProps._CubeTex); MaterialProperty OVERRIDE_FOG = MaterialEditor.GetMaterialProperty( materials, MaterialProps.OVERRIDE_FOG); MaterialProperty _LocalFogColor = MaterialEditor.GetMaterialProperty( materials, MaterialProps._LocalFogColor); // Draw Properties DrawTransparencyMode(materialEditor, materials); // Transparency Mode EditorGUILayout.Space(); materialEditor.ShaderProperty(_MainTex, _MainTex.displayName); materialEditor.ShaderProperty(_Color, _Color.displayName); materialEditor.ShaderProperty(_NormalTex, _NormalTex.displayName); // TODO: This can be turned on once there are separate variants for no normals //if (_NormalTex.textureValue != null) // EnableKeyword(materials, Keywords.NORMAL_MAP); //else // DisableKeyword(materials, Keywords.NORMAL_MAP); DrawSpecularControl(materials, SPEC); materialEditor.ShaderProperty(_SpecColor, _SpecColor.displayName); DrawReflectionControls(materialEditor, materials, _CubeTex); DrawLocalFogControls(materialEditor, materials, OVERRIDE_FOG, _LocalFogColor); }
public override void OnInspectorGUI() { showFlag = true; inactiveFlag = false; helperFlag = false; MaterialProperty active_layerProp = MaterialEditor.GetMaterialProperty(targets, "active_layer"); if (active_layerProp != null) { active_layer = (int)active_layerProp.floatValue; } Profiler.BeginSample("BetterEditor OnInspectorGUI", target); base.OnInspectorGUI(); Profiler.EndSample(); }
/// <summary> /// Make a text field for entering float values. /// </summary> public static float FloatField(MaterialEditor materialEditor, string property, string label, GUIStyle style, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; float f = EditorGUILayout.FloatField(label, p.floatValue, style, options); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { p.floatValue = f; } return(f); }
/// <summary> /// Make a slider the user can drag to change a value between a min and a max. /// </summary> public static float Slider(MaterialEditor materialEditor, string property, GUIContent label, float leftValue, float rightValue, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; float f = EditorGUILayout.Slider(label, p.floatValue, leftValue, rightValue, options); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { p.floatValue = f; } return(f); }
/// <summary> /// Make a field for selecting a Color. /// </summary> public static Color ColorField(MaterialEditor materialEditor, string property, string label, bool showEyedropper, bool showAlpha, bool hdr, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; Color c = EditorGUILayout.ColorField(new GUIContent(label), p.colorValue, showEyedropper, showAlpha, hdr, options); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { p.colorValue = c; } return(c); }
/// <summary> /// Make a toggle field where the toggle is to the left and the label immediately to the right of it. /// </summary> public static bool ToggleLeft(MaterialEditor materialEditor, string property, GUIContent label, GUIStyle labelStyle, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; bool b = EditorGUILayout.ToggleLeft(label, p.floatValue > 0, labelStyle, options); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { p.floatValue = b ? 1 : 0; } return(b); }
/// <summary> /// Make an X, Y, Z & W field for entering a Vector4. /// </summary> public static Vector4 Vector4Field(MaterialEditor materialEditor, string property, string label, params GUILayoutOption[] options) { EditorGUI.BeginChangeCheck(); MaterialProperty p = MaterialEditor.GetMaterialProperty(materialEditor.targets, property); EditorGUI.showMixedValue = p.hasMixedValue; Vector4 v = EditorGUILayout.Vector4Field(label, p.vectorValue, options); EditorGUI.showMixedValue = false; if (EditorGUI.EndChangeCheck()) { p.vectorValue = v; } return(v); }