Skip to content

Commit

Permalink
[ME] Add Category attribute, SortPropertiesByType, `SortPropertie…
Browse files Browse the repository at this point in the history
…sByAlphabet` config and color work (#302)

- Add property `Category` attribute to the shader manifest.
- Add two configs: `SortPropertiesByType` and `SortPropertiesByAlphabet` to control the property sorting.
- Add different colors to separator items to improve distinction in a lengthy context.
- Update shader manifest template.

* [ME] Add property `Category` attribute and two configs: `SortPropertiesByType` and `SortPropertiesByAlphabet`
* [ME] Add different colors to separator items to improve distinction in a lengthy context
* [ME] Update shader manifest template
* [ME] Some optimizations
* Some formatting for merging this
* [ME] Change the config name to `SortPropertiesByName`
* Formatting
* Consistent style
* [ME] Add a data holder `PropertyOrganizer` to avoid repeated grouping and sorting.
* [ME] Hide categories without properties due to blacklist or property filtering
  • Loading branch information
acezen3d authored Jan 25, 2025
1 parent 1592e4a commit 1f817ef
Show file tree
Hide file tree
Showing 10 changed files with 2,117 additions and 1,983 deletions.
16 changes: 16 additions & 0 deletions Guides/Material Editor Guide/shader_manifest_template.xml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
<!-- Optional `Hidden` attribute -->
<Property Name="{{PropertyName}}" Type="Float" Hidden="{{boolean}}"/>
<!-- Example: <Property Name="PropertyName" Type="Float" Hidden="True"/> -->
<!-- -->
<!-- Optional `Category` attribute -->
<Property Name="{{PropertyName}}" Type="Float" Category="{{category_name}}"/>
<!-- Example: <Property Name="PropertyName" Type="Float" Category="Category Name"/> -->

<!-- Color or vector property -->
<Property Name="{{PropertyName}}" Type="Color"/>
Expand All @@ -47,6 +51,10 @@
<!-- Optional `Hidden` attribute -->
<Property Name="{{PropertyName}}" Type="Color" Hidden="{{boolean}}"/>
<!-- Example: <Property Name="PropertyName" Type="Color" Hidden="True"/> -->
<!-- -->
<!-- Optional `Category` attribute -->
<Property Name="{{PropertyName}}" Type="Color" Category="{{category_name}}"/>
<!-- Example: <Property Name="PropertyName" Type="Color" Category="Category Name"/> -->

<!-- Texture property -->
<Property Name="{{PropertyName}}" Type="Texture"/>
Expand All @@ -58,6 +66,10 @@
<!-- Optional `Hidden` attribute -->
<Property Name="{{PropertyName}}" Type="Texture" Hidden="{{boolean}}"/>
<!-- Example: <Property Name="PropertyName" Type="Texture" Hidden="True"/> -->
<!-- -->
<!-- Optional `Category` attribute -->
<Property Name="{{PropertyName}}" Type="Texture" Category="{{category_name}}"/>
<!-- Example: <Property Name="PropertyName" Type="Texture" Category="Category Name"/> -->

<!-- Keyword -->
<Property Name="{{KEYWORD_NAME}}" Type="Keyword"/>
Expand All @@ -69,6 +81,10 @@
<!-- Optional `Hidden` attribute -->
<Property Name="{{KEYWORD_NAME}}" Type="Keyword" Hidden="{{boolean}}"/>
<!-- Example: <Property Name="KEYWORD_NAME" Type="Keyword" Hidden="True"/> -->
<!-- -->
<!-- Optional `Category` attribute -->
<Property Name="{{PropertyName}}" Type="Keyword" Category="{{category_name}}"/>
<!-- Example: <Property Name="PropertyName" Type="Keyword" Category="Category Name"/> -->


<!-- Notes -->
Expand Down
1 change: 1 addition & 0 deletions src/MaterialEditor.Base/MaterialEditor.Base.projitems
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Export.UV.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Extensions.cs" />
<Compile Include="$(MSBuildThisFileDirectory)PluginBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\UI.PropertyOrganizer.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\UI.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\UI.AutoScrollToCenter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)UI\UI.FloatLabelDragTrigger.cs" />
Expand Down
652 changes: 333 additions & 319 deletions src/MaterialEditor.Base/PluginBase.cs

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions src/MaterialEditor.Base/UI/UI.ItemInfo.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;

namespace MaterialEditorAPI
Expand Down Expand Up @@ -99,6 +99,6 @@ public ItemInfo(RowItemType itemType, string labelText = "")
LabelText = labelText;
}

public enum RowItemType { Renderer, RendererEnabled, RendererShadowCastingMode, RendererReceiveShadows, RendererUpdateWhenOffscreen, RendererRecalculateNormals, Material, Shader, ShaderRenderQueue, TextureProperty, TextureOffsetScale, ColorProperty, FloatProperty, KeywordProperty }
public enum RowItemType { Renderer, RendererEnabled, RendererShadowCastingMode, RendererReceiveShadows, RendererUpdateWhenOffscreen, RendererRecalculateNormals, Material, Shader, ShaderRenderQueue, PropertyCategory, TextureProperty, TextureOffsetScale, ColorProperty, FloatProperty, KeywordProperty }
}
}
}
1,143 changes: 579 additions & 564 deletions src/MaterialEditor.Base/UI/UI.ItemTemplate.cs

Large diffs are not rendered by default.

23 changes: 20 additions & 3 deletions src/MaterialEditor.Base/UI/UI.ListEntry.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using UnityEngine;
using UnityEngine.UI;
using static UILib.Extensions;
Expand Down Expand Up @@ -59,6 +59,9 @@ internal class ListEntry : MonoBehaviour
public InputField ShaderRenderQueueInput;
public Button ShaderRenderQueueResetButton;

public CanvasGroup PropertyCategoryPanel;
public Text PropertyCategoryLabel;

public CanvasGroup TexturePanel;
public Text TextureLabel;
public Button SelectInterpolableTextureButton;
Expand Down Expand Up @@ -125,7 +128,7 @@ public void SetItem(ItemInfo item, bool force)
{
case ItemInfo.RowItemType.Renderer:
ShowRenderer();
SetLabelText(RendererLabel, item.LabelText, false, null, RendererPanel);
SetLabelText(RendererLabel, item.LabelText);
ExportUVButton.onClick.RemoveAllListeners();
ExportUVButton.onClick.AddListener(() => item.ExportUVOnClick());
TooltipManager.AddTooltip(ExportUVButton.gameObject, "Export the UV map of this renderer.\n\nThe UV map is the 2d projection of the renderer with which to map textures to the 3d model. You can use this UV map as a guide to drawing on textures");
Expand Down Expand Up @@ -247,7 +250,7 @@ public void SetItem(ItemInfo item, bool force)
break;
case ItemInfo.RowItemType.Material:
ShowMaterial();
SetLabelText(MaterialLabel, item.LabelText, false, null, MaterialPanel);
SetLabelText(MaterialLabel, item.LabelText);
MaterialText.text = item.MaterialName;
MaterialCopyButton.onClick.RemoveAllListeners();
MaterialCopyButton.onClick.AddListener(() => item.MaterialOnCopy.Invoke());
Expand Down Expand Up @@ -363,6 +366,10 @@ public void SetItem(ItemInfo item, bool force)
});
TooltipManager.AddTooltip(ShaderRenderQueueResetButton.gameObject, "Reset this property to its original value");

break;
case ItemInfo.RowItemType.PropertyCategory:
ShowPropertyCategory();
SetLabelText(PropertyCategoryLabel, item.LabelText);
break;
case ItemInfo.RowItemType.TextureProperty:
ShowTexture();
Expand Down Expand Up @@ -762,6 +769,10 @@ public void SetVisible(bool visible)
gameObject.SetActive(visible);
}

private static void SetLabelText(Text label, string text) {
label.text = text ?? "";
}

private static void SetLabelText(Text label, string text, bool valueChanged, Button resetBtn, CanvasGroup panel)
{
label.text = text ?? "";
Expand Down Expand Up @@ -790,6 +801,7 @@ private void HideAll()
ShowMaterial(false);
ShowShader(false);
ShowShaderRenderQueue(false);
ShowPropertyCategory(false);
ShowTexture(false);
ShowOffsetScale(false);
ShowColor(false);
Expand Down Expand Up @@ -844,6 +856,11 @@ private void ShowShaderRenderQueue(bool visible = true)
ShaderRenderQueuePanel.blocksRaycasts = visible;
}

private void ShowPropertyCategory(bool visible = true) {
PropertyCategoryPanel.alpha = visible ? 1 : 0;
PropertyCategoryPanel.blocksRaycasts = visible;
}

private void ShowTexture(bool visible = true)
{
TexturePanel.alpha = visible ? 1 : 0;
Expand Down
46 changes: 46 additions & 0 deletions src/MaterialEditor.Base/UI/UI.PropertyOrganizer.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
using System;
using System.Collections.Generic;
using System.Text;
using UnityEngine;
using System.Linq;
using static MaterialEditorAPI.MaterialEditorPluginBase;

namespace MaterialEditorAPI
{
internal class PropertyOrganizer
{
// Shader, category, property
internal static Dictionary<string, Dictionary<string, List<ShaderPropertyData>>> PropertyOrganization = new Dictionary<string, Dictionary<string, List<ShaderPropertyData>>>();
internal static string UncategorizedName = "Uncategorized";
internal static void Refresh() {
foreach (var shader in XMLShaderProperties)
{
PropertyOrganization[shader.Key] = shader.Value
.Where(kv => !kv.Value.Hidden)
.GroupBy(kv => string.IsNullOrEmpty(kv.Value.Category) ? UncategorizedName : char.ToUpper(kv.Value.Category[0]) + kv.Value.Category.Substring(1))
.OrderBy(g => g.Key == UncategorizedName ? 1 : 0) // Ensure "Uncategorized" goes to the end
.ToDictionary(
g => g.Key,
g =>
{
var kvs = g.AsEnumerable();
if (SortPropertiesByType.Value && SortPropertiesByName.Value)
{
kvs = kvs.OrderBy(kv => kv.Value.Type).ThenBy(kv => kv.Value.Name);
}
else if (SortPropertiesByType.Value)
{
kvs = kvs.OrderBy(kv => kv.Value.Type);
}
else if (SortPropertiesByName.Value)
{
kvs = kvs.OrderBy(kv => kv.Value.Name);
}
return kvs.Select(kv=>kv.Value).ToList();
}
);

}
}
}
}
3 changes: 3 additions & 0 deletions src/MaterialEditor.Base/UI/UI.VirtualList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,9 @@ private void SetupEntryTemplate()
listEntry.ShaderRenderQueueInput = listEntry.GetUIComponent<InputField>("ShaderRenderQueueInput");
listEntry.ShaderRenderQueueResetButton = listEntry.GetUIComponent<Button>("ShaderRenderQueueResetButton");

listEntry.PropertyCategoryPanel = listEntry.GetUIComponent<CanvasGroup>("PropertyCategoryPanel");
listEntry.PropertyCategoryLabel = listEntry.GetUIComponent<Text>("PropertyCategoryLabel");

listEntry.TexturePanel = listEntry.GetUIComponent<CanvasGroup>("TexturePanel");
listEntry.TextureLabel = listEntry.GetUIComponent<Text>("TextureLabel");
listEntry.SelectInterpolableTextureButton = listEntry.GetUIComponent<Button>("SelectInterpolableTextureButton");
Expand Down
Loading

0 comments on commit 1f817ef

Please sign in to comment.