Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions Editor/Helper/PresetHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ public static LwguiShaderPropertyPreset GetPresetAsset(string presetFileName)
public static void ApplyPresetsInMaterial(Material material)
{
var props = MaterialEditor.GetMaterialProperties(new UnityEngine.Object[] { material });
var presets = new List<LwguiShaderPropertyPreset.Preset>();
foreach (var prop in props)
{
var drawer = ReflectionHelper.GetPropertyDrawer(material.shader, prop, out _);
Expand All @@ -75,10 +76,15 @@ public static void ApplyPresetsInMaterial(Material material)
if (drawer is IPresetDrawer presetDrawer)
{
var activePreset = presetDrawer.GetActivePreset(prop, GetPresetAsset(presetDrawer.GetPresetFileName()));
activePreset?.ApplyToDefaultMaterial(material);
if (activePreset?.order > -1) presets.Add(activePreset);
}
}
UnityEditorExtension.ApplyMaterialPropertyAndDecoratorDrawers(material);
if (presets.Count > 0)
{
presets.Sort((x, y) => x.order.CompareTo(y.order));
foreach (var preset in presets) preset.ApplyToDefaultMaterial(material);
UnityEditorExtension.ApplyMaterialPropertyAndDecoratorDrawers(material);
}
}
}
}
4 changes: 4 additions & 0 deletions Editor/ScriptableObject/LwguiShaderPropertyPreset.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ public enum PropertyType
Integer,
}

[SerializeField]
public int order;

[Serializable]
public class PropertyValue
{
Expand Down Expand Up @@ -161,6 +164,7 @@ public class Preset
public List<string> enabledPasses = new List<string>();
public List<string> disabledPasses = new List<string>();
public int renderQueue = -1;
public int order = -1;


public void ApplyToDefaultMaterial(Material material)
Expand Down
1 change: 1 addition & 0 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -724,6 +724,7 @@ public static LwguiShaderPropertyPreset.Preset GetActivePresetFromFloatProperty(
if (lwguiShaderPropertyPreset && index >= 0 && index < lwguiShaderPropertyPreset.GetPresetCount())
{
preset = lwguiShaderPropertyPreset.GetPreset(index);
preset.order = index != 0 ? lwguiShaderPropertyPreset.order : -1;
}
return preset;
}
Expand Down