From 52f84abfba9d2ca9559e50ab1a3acd9754d31342 Mon Sep 17 00:00:00 2001 From: Lee23 <31892011+LeeTwentyThree@users.noreply.github.com> Date: Wed, 18 Dec 2024 19:27:17 -0500 Subject: [PATCH] Add material labels, grouping and texture names --- .../MaterialEditorPropertyTypes.cs | 20 ++ .../MaterialEditor/PropertyTypeTexture.cs | 24 ++ .../SubnauticaRuntimeEditorCore.cs | 2 +- .../MaterialEditor/MaterialEditorViewer.cs | 308 ++++++++++++------ 4 files changed, 249 insertions(+), 105 deletions(-) create mode 100644 SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/PropertyTypeTexture.cs diff --git a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/MaterialEditorPropertyTypes.cs b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/MaterialEditorPropertyTypes.cs index 28f17cd..6c250bf 100644 --- a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/MaterialEditorPropertyTypes.cs +++ b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/MaterialEditorPropertyTypes.cs @@ -25,43 +25,59 @@ public static class MaterialEditorPropertyTypes { MaterialEditorProperties.Cutoff, new PropertyTypeFloat("_Cutoff", 0f, 1f) }, { MaterialEditorProperties.EnableDitherAlpha, new PropertyTypeFloat("_EnableDitherAlpha", true) }, { MaterialEditorProperties.EnableVrFadeOut, new PropertyTypeFloat("_EnableVrFadeOut", true) }, + { MaterialEditorProperties.VrFadeMask, new PropertyTypeTexture("_VrFadeMask") }, { MaterialEditorProperties.EnableLighting, new PropertyTypeFloat("_EnableLighting", true) }, { MaterialEditorProperties.IBLreductionAtNight, new PropertyTypeFloat("_IBLreductionAtNight", 0f, 1f) }, { MaterialEditorProperties.EnableSimpleGlass, new PropertyTypeFloat("_EnableSimpleGlass", true) }, { MaterialEditorProperties.EnableVertexColor, new PropertyTypeFloat("_EnableVertexColor", true) }, { MaterialEditorProperties.EnableSchoolFish, new PropertyTypeFloat("_EnableSchoolFish", true) }, { MaterialEditorProperties.EnableMainMaps, new PropertyTypeFloat("_EnableMainMaps", true) }, + { MaterialEditorProperties.MainTex, new PropertyTypeTexture("_MainTex") }, + { MaterialEditorProperties.BumpMap, new PropertyTypeTexture("_BumpMap") }, { MaterialEditorProperties.MarmoSpecEnum, new PropertyTypeFloat("_MarmoSpecEnum", 0.0f, 100f) }, + { MaterialEditorProperties.SIGMap, new PropertyTypeTexture("_SIGMap") }, + { MaterialEditorProperties.SpecTex, new PropertyTypeTexture("_SpecTex") }, { MaterialEditorProperties.SpecColor, new PropertyTypeColor("_SpecColor", true) }, { MaterialEditorProperties.SpecInt, new PropertyTypeFloat("_SpecInt", 0.0f, 100f) }, { MaterialEditorProperties.Shininess, new PropertyTypeFloat("_Shininess", 2f, 8f) }, { MaterialEditorProperties.Fresnel, new PropertyTypeFloat("_Fresnel", 0f, 1f) }, { MaterialEditorProperties.EnableGlow, new PropertyTypeFloat("_EnableGlow", true) }, { MaterialEditorProperties.GlowColor, new PropertyTypeColor("_GlowColor", true) }, + { MaterialEditorProperties.Illum, new PropertyTypeTexture("_Illum") }, { MaterialEditorProperties.GlowUVfromVC, new PropertyTypeFloat("_GlowUVfromVC", 0.0f, 100f) }, { MaterialEditorProperties.GlowStrength, new PropertyTypeFloat("_GlowStrength", 0.0f, 100f) }, { MaterialEditorProperties.GlowStrengthNight, new PropertyTypeFloat("_GlowStrengthNight", 0.0f, 100f) }, { MaterialEditorProperties.EmissionLM, new PropertyTypeFloat("_EmissionLM", 0.0f, 100f) }, { MaterialEditorProperties.EmissionLMNight, new PropertyTypeFloat("_EmissionLMNight", 0.0f, 100f) }, { MaterialEditorProperties.EnableDetailMaps, new PropertyTypeFloat("_EnableDetailMaps", true) }, + { MaterialEditorProperties.DetailDiffuseTex, new PropertyTypeTexture("_DetailDiffuseTex") }, + { MaterialEditorProperties.DetailBumpTex, new PropertyTypeTexture("_DetailBumpTex") }, + { MaterialEditorProperties.DetailSpecTex, new PropertyTypeTexture("_DetailSpecTex") }, { MaterialEditorProperties.DetailIntensities, new PropertyTypeVector4("_DetailIntensities") }, { MaterialEditorProperties.EnableLightmap, new PropertyTypeFloat("_EnableLightmap", true) }, + { MaterialEditorProperties.Lightmap, new PropertyTypeTexture("_Lightmap") }, { MaterialEditorProperties.LightmapStrength, new PropertyTypeFloat("_LightmapStrength", 0.0f, 100f) }, { MaterialEditorProperties.Enable3Color, new PropertyTypeFloat("_Enable3Color", true) }, + { MaterialEditorProperties.MultiColorMask, new PropertyTypeTexture("_MultiColorMask") }, { MaterialEditorProperties.Color2, new PropertyTypeColor("_Color2", true) }, { MaterialEditorProperties.Color3, new PropertyTypeColor("_Color3", true) }, { MaterialEditorProperties.SpecColor2, new PropertyTypeColor("_SpecColor2", true) }, { MaterialEditorProperties.SpecColor3, new PropertyTypeColor("_SpecColor3", true) }, { MaterialEditorProperties.FX, new PropertyTypeFloat("FX", true) }, + { MaterialEditorProperties.DeformMap, new PropertyTypeTexture("_DeformMap") }, { MaterialEditorProperties.DeformParams, new PropertyTypeVector4("_DeformParams") }, { MaterialEditorProperties.FillSack, new PropertyTypeFloat("_FillSack", 0f, 1f) }, { MaterialEditorProperties.OverlayStrength, new PropertyTypeFloat("_OverlayStrength", 0f, 1f) }, { MaterialEditorProperties.GlowScrollColor, new PropertyTypeColor("_GlowScrollColor", true) }, + { MaterialEditorProperties.GlowScrollMask, new PropertyTypeTexture("_GlowScrollMask") }, { MaterialEditorProperties.Hypnotize, new PropertyTypeFloat("_Hypnotize", 0f, 1f) }, { MaterialEditorProperties.ScrollColor, new PropertyTypeColor("_ScrollColor", true) }, { MaterialEditorProperties.ColorStrength, new PropertyTypeColor("_ColorStrength", true) }, + { MaterialEditorProperties.ScrollTex, new PropertyTypeTexture("_ScrollTex") }, + { MaterialEditorProperties.GlowMask, new PropertyTypeTexture("_GlowMask") }, { MaterialEditorProperties.GlowMaskSpeed, new PropertyTypeVector4("_GlowMaskSpeed") }, { MaterialEditorProperties.ScrollSpeed, new PropertyTypeVector4("_ScrollSpeed") }, + { MaterialEditorProperties.NoiseTex, new PropertyTypeTexture("_NoiseTex") }, { MaterialEditorProperties.DetailsColor, new PropertyTypeColor("_DetailsColor", true) }, { MaterialEditorProperties.SquaresColor, new PropertyTypeColor("_SquaresColor", true) }, { MaterialEditorProperties.SquaresTile, new PropertyTypeFloat("_SquaresTile", 0.0f, 100f) }, @@ -74,12 +90,14 @@ public static class MaterialEditorPropertyTypes { MaterialEditorProperties.Built, new PropertyTypeFloat("_Built", 0.0f, 100f) }, { MaterialEditorProperties.BuildParams, new PropertyTypeVector4("_BuildParams") }, { MaterialEditorProperties.BuildLinear, new PropertyTypeFloat("_BuildLinear", 0.0f, 100f) }, + { MaterialEditorProperties.EmissiveTex, new PropertyTypeTexture("_EmissiveTex") }, { MaterialEditorProperties.NoiseThickness, new PropertyTypeFloat("_NoiseThickness", 0.0f, 100f) }, { MaterialEditorProperties.NoiseStr, new PropertyTypeFloat("_NoiseStr", 0.0f, 100f) }, { MaterialEditorProperties.FX_Vertex, new PropertyTypeFloat("FX_Vertex", true) }, { MaterialEditorProperties.Scale, new PropertyTypeVector4("_Scale") }, { MaterialEditorProperties.Frequency, new PropertyTypeVector4("_Frequency") }, { MaterialEditorProperties.Speed, new PropertyTypeVector4("_Speed") }, + { MaterialEditorProperties.AnimMask, new PropertyTypeTexture("_AnimMask") }, { MaterialEditorProperties.ObjectUp, new PropertyTypeVector4("_ObjectUp") }, { MaterialEditorProperties.WaveUpMin, new PropertyTypeFloat("_WaveUpMin", 0.0f, 100f) }, { MaterialEditorProperties.Fallof, new PropertyTypeFloat("_Fallof", 0.0f, 100f) }, @@ -87,6 +105,7 @@ public static class MaterialEditorPropertyTypes { MaterialEditorProperties.minYpos, new PropertyTypeFloat("_minYpos", 0.0f, 100f) }, { MaterialEditorProperties.maxYpos, new PropertyTypeFloat("_maxYpos", 0.0f, 100f) }, { MaterialEditorProperties.EnableBurst, new PropertyTypeFloat("_EnableBurst", true) }, + { MaterialEditorProperties.DispTex, new PropertyTypeTexture("_DispTex") }, { MaterialEditorProperties.Displacement, new PropertyTypeFloat("_Displacement", 0f, 5f) }, { MaterialEditorProperties.BurstStrength, new PropertyTypeFloat("_BurstStrength", 0f, 1f) }, { MaterialEditorProperties.Range, new PropertyTypeVector4("_Range") }, @@ -96,6 +115,7 @@ public static class MaterialEditorPropertyTypes { MaterialEditorProperties.InfectionHeightStrength, new PropertyTypeFloat("_InfectionHeightStrength", 0.0f, 100f) }, { MaterialEditorProperties.InfectionScale, new PropertyTypeVector4("_InfectionScale") }, { MaterialEditorProperties.InfectionOffset, new PropertyTypeVector4("_InfectionOffset") }, + { MaterialEditorProperties.InfectionNoiseTex, new PropertyTypeTexture("_InfectionNoiseTex") }, { MaterialEditorProperties.InfectionSpeed, new PropertyTypeVector4("_InfectionSpeed") }, { MaterialEditorProperties.ColorStrengthAtNight, new PropertyTypeColor("_ColorStrengthAtNight", true) }, { MaterialEditorProperties.EmissUV, new PropertyTypeVector4("_EmissUV") }, diff --git a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/PropertyTypeTexture.cs b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/PropertyTypeTexture.cs new file mode 100644 index 0000000..2841f66 --- /dev/null +++ b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/MaterialEditor/PropertyTypeTexture.cs @@ -0,0 +1,24 @@ +using System; +using UnityEngine; + +namespace SubnauticaRuntimeEditor.Core.MaterialEditor +{ + public class PropertyTypeTexture : PropertyType + { + public PropertyTypeTexture(string property) : base(property) + { + } + + protected override void Draw(Material material) + { + var texture = material.GetTexture(Property); + var text = texture == null ? "Unassigned" : texture.name; + GUILayout.Label(text); + } + + public override string GenerateSetPropertyCode(Material material) + { + return "Unimplemented"; + } + } +} \ No newline at end of file diff --git a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/SubnauticaRuntimeEditorCore.cs b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/SubnauticaRuntimeEditorCore.cs index 62a6de8..2499487 100644 --- a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/SubnauticaRuntimeEditorCore.cs +++ b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/SubnauticaRuntimeEditorCore.cs @@ -15,7 +15,7 @@ namespace SubnauticaRuntimeEditor.Core { public class SubnauticaRuntimeEditorCore { - public const string Version = "1.0.4"; + public const string Version = "1.1.0"; public const string GUID = "SubnauticaRuntimeEditor"; [Obsolete("Use window Instance instead")] public Inspector.Inspector Inspector => Core.Inspector.Inspector.Initialized ? Core.Inspector.Inspector.Instance : null; diff --git a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/Windows/MaterialEditor/MaterialEditorViewer.cs b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/Windows/MaterialEditor/MaterialEditorViewer.cs index 6c11a91..1b5957b 100644 --- a/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/Windows/MaterialEditor/MaterialEditorViewer.cs +++ b/SubnauticaRuntimeEditor/SubnauticaRuntimeEditor.Core/Windows/MaterialEditor/MaterialEditorViewer.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Linq; +using System.Text; using UnityEngine; using SubnauticaRuntimeEditor.Core.Utils; @@ -15,30 +16,40 @@ public class MaterialEditorViewer : Window public static readonly string MARMOSETUBER_SHADER_NAME = "MarmosetUBER"; - private static readonly string NO_MATERIAL_SELECTED = "No material selected!\nSelect the 'Open in Material Editor' button on a valid Renderer or Material."; + private static readonly string NO_MATERIAL_SELECTED = + "No material selected!\nSelect the 'Open in Material Editor' button on a valid Renderer or Material."; private const float SHADER_EDITOR_WIDTH = 500f; private readonly GUILayoutOption _propertyColumnWidth = GUILayout.Width(75f); + private readonly GUILayoutOption _propertyDescriptionColumnWidth = GUILayout.Width(400f); + private readonly GUILayoutOption _pinColumnWidth = GUILayout.Width(30f); private readonly GUILayoutOption _keywordColumnWidth = GUILayout.Width(400f); + private readonly GUILayoutOption _headerColumnWidth = GUILayout.Width(400f); + private readonly GUILayoutOption _headerHeight = GUILayout.Height(35f); + private readonly GUILayoutOption _textLabelWidth = GUILayout.Width(400f); - private readonly StringListPref pinnedProperties = StringListPref.Get("PINNEDMATERIALPROPERTIES", false); + private readonly StringListPref _pinnedProperties = StringListPref.Get("PINNEDMATERIALPROPERTIES", false); + + private Vector2 _scrollPosition = Vector2.zero; + + private Material _editingMaterial; - private Vector2 scrollPosition = Vector2.zero; + private bool _materialKeywordsExpanded; - private Material editingMaterial; + private bool _materialPropertiesExpanded = true; - private bool materialKeywordsExpanded; + private bool _pinnedMaterialPropertiesExpanded = true; - private bool materialPropertiesExpanded = true; + private readonly Dictionary _propertyHeadersExpanded = new Dictionary(); + + private const bool DefaultPropertyExpandedValue = false; - private bool pinnedMaterialPropertiesExpanded = true; - public static string FloatPropertyFormattingString { get; private set; } protected override void Initialize(InitSettings initSettings) @@ -55,7 +66,7 @@ protected override void Initialize(InitSettings initSettings) public static void StartEditing(Material material) { main.Enabled = true; - main.editingMaterial = material; + main._editingMaterial = material; main.Title = main.CurrentTitle; } @@ -63,8 +74,8 @@ public string CurrentTitle { get { - if (editingMaterial == null) return DEFAULT_TITLE; - return editingMaterial.name + " - " + editingMaterial.shader.name; + if (_editingMaterial == null) return DEFAULT_TITLE; + return _editingMaterial.name + " - " + _editingMaterial.shader.name; } } @@ -76,45 +87,39 @@ protected override Rect GetDefaultWindowRect(Rect screenRect) protected override void DrawContents() { // scroll view - scrollPosition = GUILayout.BeginScrollView(this.scrollPosition, new GUILayoutOption[] + _scrollPosition = GUILayout.BeginScrollView(this._scrollPosition, new GUILayoutOption[] { GUILayout.Width(SHADER_EDITOR_WIDTH), GUILayout.ExpandHeight(true), }); // no material selected warning - if (editingMaterial == null) + if (_editingMaterial == null) { - GUILayout.BeginVertical(GUI.skin.box, Array.Empty()); - GUILayout.Label(NO_MATERIAL_SELECTED, new GUILayoutOption[] - { - _textLabelWidth, - }) ; + GUILayout.BeginVertical(GUI.skin.box); + GUILayout.Label(NO_MATERIAL_SELECTED, _textLabelWidth); GUILayout.EndVertical(); GUILayout.EndScrollView(); return; } + // title - GUILayout.BeginVertical(GUI.skin.box, Array.Empty()); - GUILayout.Label("Selected: " + CurrentTitle, new GUILayoutOption[] - { - _textLabelWidth - }); + GUILayout.BeginVertical(GUI.skin.box); + GUILayout.Label("Selected: " + CurrentTitle, _textLabelWidth); GUILayout.EndVertical(); // keywords - if (editingMaterial.shader.name.Equals(MARMOSETUBER_SHADER_NAME)) + if (_editingMaterial.shader.name.Equals(MARMOSETUBER_SHADER_NAME)) { - GUILayout.BeginVertical(GUI.skin.box, Array.Empty()); - if (GUILayout.Button("Keywords", new GUILayoutOption[] - { - GUILayout.ExpandWidth(true) - })) + GUILayout.BeginVertical(GUI.skin.box); + if (GUILayout.Button("Keywords", GUILayout.ExpandWidth(true))) { - materialKeywordsExpanded = !materialKeywordsExpanded; + _materialKeywordsExpanded = !_materialKeywordsExpanded; } - if (materialKeywordsExpanded) + + if (_materialKeywordsExpanded) { DrawKeywords(); } + GUILayout.EndVertical(); } // properties (pinned) @@ -123,42 +128,43 @@ protected override void DrawContents() GUILayout.BeginHorizontal(GUI.skin.box); if (GUILayout.Button("Pinned properties", new GUILayoutOption[] + { + GUILayout.ExpandWidth(true) + })) { - GUILayout.ExpandWidth(true) - })) - { - pinnedMaterialPropertiesExpanded = !pinnedMaterialPropertiesExpanded; + _pinnedMaterialPropertiesExpanded = !_pinnedMaterialPropertiesExpanded; } if (GUILayout.Button("Unpin all", new GUILayoutOption[] + { + GUILayout.Width(100) + })) { - GUILayout.Width(100) - })) - { - pinnedProperties.array.Clear(); + _pinnedProperties.array.Clear(); } + GUILayout.EndHorizontal(); - if (pinnedMaterialPropertiesExpanded) + if (_pinnedMaterialPropertiesExpanded) { DrawProperties(true); } + GUILayout.EndVertical(); // properties (normal) - GUILayout.BeginVertical(GUI.skin.box, Array.Empty()); - if (GUILayout.Button("Properties", new GUILayoutOption[] + GUILayout.BeginVertical(GUI.skin.box); + if (GUILayout.Button("Properties", GUILayout.ExpandWidth(true))) { - GUILayout.ExpandWidth(true) - })) - { - materialPropertiesExpanded = !materialPropertiesExpanded; + _materialPropertiesExpanded = !_materialPropertiesExpanded; } - if (materialPropertiesExpanded) + + if (_materialPropertiesExpanded) { DrawProperties(false); } + GUILayout.EndVertical(); GUILayout.EndScrollView(); @@ -166,109 +172,203 @@ protected override void DrawContents() private void DrawKeywords() { - HashSet shaderKeywords = new HashSet(this.editingMaterial.shaderKeywords); - this.DrawKeywordTableHeader(); + HashSet shaderKeywords = new HashSet(_editingMaterial.shaderKeywords); + DrawKeywordTableHeader(); foreach (object obj in Enum.GetValues(typeof(Keywords))) { Keywords keyword = (Keywords)obj; - GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty()); - this.DrawKeywordTableRow(shaderKeywords, keyword); + GUILayout.BeginHorizontal(GUI.skin.box); + DrawKeywordTableRow(shaderKeywords, keyword); GUILayout.EndHorizontal(); } } private void DrawKeywordTableHeader() { - GUILayout.BeginHorizontal(Array.Empty()); - GUILayout.Label("Keyword", GUI.skin.box, new GUILayoutOption[] - { - _keywordColumnWidth - }); - GUILayout.Label("Toggled", GUI.skin.box, new GUILayoutOption[] - { - GUILayout.ExpandWidth(true) - }); + GUILayout.BeginHorizontal(); + GUILayout.Label("Keyword", GUI.skin.box, _keywordColumnWidth); + GUILayout.Label("Toggled", GUI.skin.box, GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); } private void DrawKeywordTableRow(ICollection shaderKeywords, Keywords keyword) { - GUILayout.BeginHorizontal(Array.Empty()); - GUILayout.Label(keyword.ToString(), new GUILayoutOption[] - { - _keywordColumnWidth - }); + GUILayout.BeginHorizontal(); + GUILayout.Label(keyword.ToString(), _keywordColumnWidth); bool flag = shaderKeywords.Contains(keyword.ToString()); - bool flag2 = GUILayout.Toggle(flag, "", new GUILayoutOption[] - { - GUILayout.ExpandWidth(true) - }); + bool flag2 = GUILayout.Toggle(flag, "", GUILayout.ExpandWidth(true)); if (flag != flag2) { if (flag2) { - editingMaterial.EnableKeyword(keyword.ToString()); + _editingMaterial.EnableKeyword(keyword.ToString()); } else { - editingMaterial.DisableKeyword(keyword.ToString()); + _editingMaterial.DisableKeyword(keyword.ToString()); } } + GUILayout.EndHorizontal(); } private void DrawProperties(bool pinnedOnly) { + bool opened = true; + DrawPropertiesTableHeader(); - foreach (KeyValuePair keyValuePair in from possibleProperty in MaterialEditorPropertyTypes.TYPES - where editingMaterial.HasProperty(possibleProperty.Value.Property) - select possibleProperty) + foreach (KeyValuePair keyValuePair in from possibleProperty in + MaterialEditorPropertyTypes.TYPES + where _editingMaterial.HasProperty(possibleProperty.Value.Property) + select possibleProperty) { - bool pinned = pinnedProperties.Contains(keyValuePair.Key.ToString()); + bool pinned = _pinnedProperties.Contains(keyValuePair.Key.ToString()); if (!pinned && pinnedOnly) continue; - GUILayout.BeginHorizontal(GUI.skin.box, Array.Empty()); - DrawPropertiesTableRow(keyValuePair.Key, keyValuePair.Value, pinned); + if (!keyValuePair.Value.IsHeader && !opened) + { + continue; + } + GUILayout.BeginHorizontal(GUI.skin.box); + DrawPropertiesTableRow(keyValuePair.Key, keyValuePair.Value, pinned, ref opened); GUILayout.EndHorizontal(); } } private void DrawPropertiesTableHeader() { - GUILayout.BeginHorizontal(Array.Empty()); - GUILayout.Label("Name", GUI.skin.box, new GUILayoutOption[] - { - this._propertyColumnWidth - }); - GUILayout.Label("Value", GUI.skin.box, new GUILayoutOption[] - { - GUILayout.ExpandWidth(true) - }); + GUILayout.BeginHorizontal(); + GUILayout.Label("Name", GUI.skin.box, _propertyColumnWidth); + GUILayout.Label("Value", GUI.skin.box, GUILayout.ExpandWidth(true)); GUILayout.EndHorizontal(); } - private void DrawPropertiesTableRow(MaterialEditorProperties property, PropertyType type, bool pinned) + private void DrawPropertiesTableRow(MaterialEditorProperties property, PropertyType type, bool pinned, ref bool opened) { - GUILayout.BeginHorizontal(Array.Empty()); + GUILayout.BeginVertical(); + GUILayout.BeginHorizontal(); + + // Color if disabled if (!IsPropertyActiveByKeywords(property)) { GUI.color = Color.gray; } - GUILayout.Label(type.Property, new GUILayoutOption[] + + var hasDescription = TryGetPropertyDescription(type, out var description); + + // Name + if (type.IsHeader) { - _propertyColumnWidth - }); - type.DrawGUI(editingMaterial); - GUILayout.FlexibleSpace(); - if (pinned) GUI.color = Styling.Colors.genericSelectionColorButton; - if (GUILayout.Button(UI.InterfaceMaker.PinIcon, new GUILayoutOption[] + GUILayout.BeginHorizontal(); + var headerText = GetFullHeaderText(hasDescription ? description : type.Property, property); + var oldFontSize = GUI.skin.label.fontSize; + GUI.skin.label.fontSize = 18; + var oldAlignment = GUI.skin.label.alignment; + GUI.skin.label.alignment = TextAnchor.MiddleCenter; + bool pressed = GUILayout.Button($"{headerText}", _headerColumnWidth, _headerHeight); + opened = ManagePropertyGroupExpansion(type.Property, pressed); + GUI.skin.label.fontSize = oldFontSize; + GUI.skin.label.alignment = oldAlignment; + GUILayout.EndHorizontal(); + } + else { - _pinColumnWidth - })) + GUILayout.Label(type.Property, _propertyColumnWidth); + } + + if (!type.IsHeader) { - TogglePropertyPinned(property, type); + type.DrawGUI(_editingMaterial); + GUILayout.FlexibleSpace(); + if (pinned) GUI.color = Styling.Colors.genericSelectionColorButton; + if (GUILayout.Button(UI.InterfaceMaker.PinIcon, _pinColumnWidth)) + { + TogglePropertyPinned(property, type); + } } - GUI.color = Styling.Colors.defaultColor; + GUILayout.EndHorizontal(); + + GUI.color = IsPropertyActiveByKeywords(property) ? Styling.Colors.defaultColor : Color.gray; + + // Description + if (hasDescription && !type.IsHeader) + { + GUILayout.BeginHorizontal(); + var oldFontSize = GUI.skin.label.fontSize; + GUI.skin.label.fontSize = 10; + GUILayout.Label(description, _propertyDescriptionColumnWidth); + GUI.skin.label.fontSize = oldFontSize; + GUILayout.FlexibleSpace(); + GUILayout.EndHorizontal(); + } + + GUI.color = Styling.Colors.defaultColor; + + GUILayout.EndVertical(); + } + + private bool ManagePropertyGroupExpansion(string headerPropertyName, bool pressed) + { + var hasValue = _propertyHeadersExpanded.TryGetValue(headerPropertyName, out var currentlyOpened); + if (!hasValue) currentlyOpened = DefaultPropertyExpandedValue; + + if (pressed) + { + currentlyOpened = !currentlyOpened; + if (hasValue) + { + _propertyHeadersExpanded[headerPropertyName] = currentlyOpened; + } + else + { + _propertyHeadersExpanded.Add(headerPropertyName, currentlyOpened); + } + } + + return currentlyOpened; + } + + private string GetFullHeaderText(string name, MaterialEditorProperties propertyType) + { + if (MaterialEditorPropertyKeywords.KEYWORDS.TryGetValue(propertyType, out var relevantKeywords) && + relevantKeywords != null && relevantKeywords.Length > 0) + { + StringBuilder fullName = new StringBuilder(name); + fullName.Append("\nEnabled by: "); + for (int i = 0; i < relevantKeywords.Length; i++) + { + fullName.Append(' '); + fullName.Append(relevantKeywords[i]); + if (i < relevantKeywords.Length - 1) + { + fullName.Append(","); + } + } + + return fullName.ToString(); + } + + return name; + } + + private bool TryGetPropertyDescription(PropertyType property, out string description) + { + int index = _editingMaterial.shader.FindPropertyIndex(property.Property); + if (index < 0) + { + description = "Not found in shader property list"; + return true; + } + + var propertyDescription = _editingMaterial.shader.GetPropertyDescription(index); + if (propertyDescription == property.Property) + { + description = null; + return false; + } + + description = propertyDescription; + return true; } private bool IsPropertyActiveByKeywords(MaterialEditorProperties property) @@ -278,7 +378,7 @@ private bool IsPropertyActiveByKeywords(MaterialEditorProperties property) if (relevantKeywords == null || relevantKeywords.Length == 0) return true; foreach (var keyword in relevantKeywords) { - if (editingMaterial.IsKeywordEnabled(keyword.ToString())) + if (_editingMaterial.IsKeywordEnabled(keyword.ToString())) { return true; } @@ -290,18 +390,18 @@ private bool IsPropertyActiveByKeywords(MaterialEditorProperties property) return true; } - private void IsPinned(MaterialEditorProperties property) => pinnedProperties.Contains(property.ToString()); + private void IsPinned(MaterialEditorProperties property) => _pinnedProperties.Contains(property.ToString()); private void TogglePropertyPinned(MaterialEditorProperties property, PropertyType type) { var propertyId = property.ToString(); - if (!pinnedProperties.Contains(propertyId)) + if (!_pinnedProperties.Contains(propertyId)) { - pinnedProperties.Add(propertyId); + _pinnedProperties.Add(propertyId); } else { - pinnedProperties.Remove(propertyId); + _pinnedProperties.Remove(propertyId); } } }