// Giving assetWithHDMetaData will directly try to get ids from an HDMetaData object from the given asset internal static bool ResetMaterialKeywords(Material material, UnityEngine.Object assetWithHDMetaData = null) { MaterialResetter resetter; (ShaderID id, GUID extMaterialGUID) = GetShaderIDsFromShader(material.shader, assetWithHDMetaData); // If we send a non HDRP material we don't throw an exception, the return type already handles errors. try { k_PlainShadersMaterialResetters.TryGetValue(id, out resetter); if (resetter == null) { k_HDSubTargetsMaterialResetters.TryGetValue(extMaterialGUID, out resetter); } } catch { return(false); } if (resetter != null) { CoreEditorUtils.RemoveMaterialKeywords(material); // We need to reapply ToggleOff/Toggle keyword after reset via ApplyMaterialPropertyDrawers MaterialEditor.ApplyMaterialPropertyDrawers(material); resetter(material); EditorUtility.SetDirty(material); return(true); } return(false); }
/// <summary> /// Reset the dedicated Keyword and Pass regarding the shader kind. /// Also re-init the drawers and set the material dirty for the engine. /// </summary> /// <param name="material">The material that needs to be setup</param> /// <returns> /// True: managed to do the operation. /// False: unknown shader used in material /// </returns> public static bool ResetMaterialKeywords(Material material) { MaterialResetter resetter; // If we send a non HDRP material we don't throw an exception, the return type already handles errors. try { k_MaterialResetters.TryGetValue(GetShaderEnumFromShader(material.shader), out resetter); } catch { return(false); } if (resetter != null) { CoreEditorUtils.RemoveMaterialKeywords(material); // We need to reapply ToggleOff/Toggle keyword after reset via ApplyMaterialPropertyDrawers MaterialEditor.ApplyMaterialPropertyDrawers(material); resetter(material); EditorUtility.SetDirty(material); return(true); } return(false); }
public void ApplyDrawers() { foreach (Material target in Materials) { MaterialEditor.ApplyMaterialPropertyDrawers(target); } }
private void CloseTabNow(string toggleName) { GetProperty(MaterialProperty.PropType.Float, toggleName).floatValue = 0.0f; SerializedObject.ApplyModifiedProperties(); MaterialEditor.ApplyMaterialPropertyDrawers(Targets); SceneView.lastActiveSceneView.Repaint(); }
public void DisableTab(string tab, MaterialProperty prop, int matInst) { prop.floatValue = 0.0f; MaterialEditor.ApplyMaterialPropertyDrawers(Targets); RepaintScene(); m_openCloseAnim[prop.name].target = false; TabGroup.SetOpen(tab + matInst, false); }
void Revert() { for (int i = 0; i < shaderEditor.Materials.Length; i++) { shaderEditor.Materials[i].CopyPropertiesFromMaterial(beforePreset[i]); MaterialEditor.ApplyMaterialPropertyDrawers(shaderEditor.Materials[i]); } mainStruct.Reset(); shaderEditor.Repaint(); }
public void EnableTab(string tab, string toggleName, int matInst) { m_openCloseAnim[toggleName].value = false; TabGroup.SetOpen(tab + matInst, true); GetProperty(MaterialProperty.PropType.Float, toggleName).floatValue = 1.0f; SerializedObject.ApplyModifiedProperties(); MaterialEditor.ApplyMaterialPropertyDrawers(Targets); SceneView.lastActiveSceneView.Repaint(); }
public static bool ResetMaterialKeywords(Material material) { MaterialResetter resetter; if (k_MaterialResetters.TryGetValue(material.shader.name, out resetter)) { CoreEditorUtils.RemoveMaterialKeywords(material); // We need to reapply ToggleOff/Toggle keyword after reset via ApplyMaterialPropertyDrawers MaterialEditor.ApplyMaterialPropertyDrawers(material); resetter(material); EditorUtility.SetDirty(material); return(true); } return(false); }
public override void Draw(AlloyFieldDrawerArgs args) { int current = (int)Property.floatValue; var label = new GUIContent(DisplayName); BeginMaterialProperty(Property); int newVal = EditorGUILayout.Popup(label, current, DropOptions.Select(option => new GUIContent(option.Name)).ToArray()); EditorGUI.showMixedValue = false; if (!OnSetOption(newVal, args) && EditorGUI.EndChangeCheck()) { Property.floatValue = newVal; MaterialEditor.ApplyMaterialPropertyDrawers(args.Materials); } MatEditor.EndAnimatedCheck(); args.PropertiesSkip.AddRange(DropOptions[current].HideFields); }
public override void OnGUI(MaterialEditor materialEditor, MaterialProperty[] properties) { MatEditor = materialEditor; IsValid = true; if (!m_inited) { AlloySceneDrawer.Register(this, MatEditor); OnEnable(); } if (!IsValid) { EditorGUILayout.LabelField("There's a problem with the inspector. Reselect the material to fix"); EditorApplication.delayCall += () => MatEditor.Repaint(); return; } if (Target != null) { var ns = Target.shader; if (ns != m_oldShader) { EditorApplication.delayCall += OnEnable; MatEditor.Repaint(); return; } } OnInspectorGUI(); if (GUI.changed) { MaterialEditor.ApplyMaterialPropertyDrawers(Targets); } m_inited = true; }
public override void Draw(AlloyFieldDrawerArgs args) { bool current = Property.floatValue > 0.5f; var label = new GUIContent(DisplayName); //EditorGUI.BeginProperty(new Rect(), label, Serialized); EditorGUI.showMixedValue = Property.hasMixedValue; EditorGUI.BeginChangeCheck(); current = EditorGUILayout.Toggle(label, current); if (EditorGUI.EndChangeCheck()) { Property.floatValue = current ? 1.0f : 0.0f; MaterialEditor.ApplyMaterialPropertyDrawers(args.Materials); } //EditorGUI.EndProperty(); EditorGUI.showMixedValue = false; if (!current) { if (OffHideFields != null) { args.PropertiesSkip.AddRange(OffHideFields); } } else { if (OnHideFields != null) { args.PropertiesSkip.AddRange(OnHideFields); } } }
/// <summary> /// Reset the dedicated Keyword and Pass regarding the shader kind. /// Also re-init the drawers and set the material dirty for the engine. /// </summary> /// <param name="material">The material that nees to be setup</param> /// <returns> /// True: managed to do the operation. /// False: unknown shader used in material /// </returns> public static bool ResetMaterialKeywords(Material material) { MaterialResetter resetter = null; // For shader graphs, we retrieve the master node type to get the materials resetter if (material.shader.IsShaderGraph()) { Type masterNodeType = null; try { // GraphUtil.GetOutputNodeType can throw if it's not able to parse the graph masterNodeType = GraphUtil.GetOutputNodeType(AssetDatabase.GetAssetPath(material.shader)); } catch {} if (masterNodeType != null) { k_ShaderGraphMaterialResetters.TryGetValue(masterNodeType, out resetter); } } else { k_MaterialResetters.TryGetValue(material.shader.name, out resetter); } if (resetter != null) { CoreEditorUtils.RemoveMaterialKeywords(material); // We need to reapply ToggleOff/Toggle keyword after reset via ApplyMaterialPropertyDrawers MaterialEditor.ApplyMaterialPropertyDrawers(material); resetter(material); EditorUtility.SetDirty(material); return(true); } return(false); }