Skip to content

Commit

Permalink
feat: strip shaders using ShaderVariantCollection instead of 'Always …
Browse files Browse the repository at this point in the history
…Include Shaders'

close #211
  • Loading branch information
mob-sakai committed Nov 23, 2024
1 parent 17b3dcf commit 19f9289
Show file tree
Hide file tree
Showing 13 changed files with 489 additions and 263 deletions.
21 changes: 0 additions & 21 deletions Assets/ProjectSettings/UISoftMask.asset

This file was deleted.

43 changes: 43 additions & 0 deletions Assets/ProjectSettings/UISoftMaskProjectSettings.asset
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
%YAML 1.1
%TAG !u! tag:unity3d.com,2011:
--- !u!200 &-3771181682974605552
ShaderVariantCollection:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_Name: ShaderVariants
m_Shaders:
- first: {fileID: 4800000, guid: 9839189d918374a318d397a86e90aa73, type: 3}
second:
variants:
- keywords: SOFTMASKABLE
passType: 0
- keywords: SOFTMASKABLE UNITY_UI_ALPHACLIP
passType: 0
- first: {fileID: 4800000, guid: 2933b413a51fc4ff3a83c7ef4177ae84, type: 3}
second:
variants:
- keywords:
passType: 0
--- !u!114 &11400000
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 0}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: eb5b5e33068c14a2bacdd6575e94f505, type: 3}
m_Name: UISoftMaskProjectSettings
m_EditorClassIdentifier:
m_SoftMaskEnabled: 1
m_StereoEnabled: 1
m_TransformSensitivity: 1
m_HideGeneratedComponents: 1
m_ShaderVariantRegistry:
m_ErrorOnUnregisteredVariant: 0
m_OptionalShaders: []
m_UnregisteredVariants: []
m_Asset: {fileID: -3771181682974605552}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

48 changes: 0 additions & 48 deletions Packages/src/Editor/ShaderPreProcessor.cs

This file was deleted.

43 changes: 15 additions & 28 deletions Packages/src/Editor/UISoftMaskProjectSettingsEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,47 +7,34 @@ namespace Coffee.UISoftMask
[CustomEditor(typeof(UISoftMaskProjectSettings))]
internal class UISoftMaskProjectSettingsEditor : Editor
{
private static readonly GUIContent s_ContentRemove = new GUIContent("-");
private static readonly GUIContent s_ContentReset = new GUIContent("Reset");
private static readonly GUIContent s_ContentIncluded = new GUIContent("Included Shaders");
private static readonly GUIContent s_ContentUpgrade = new GUIContent("Upgrade");
private static readonly GUIContent s_ContentUpgradeButton = new GUIContent("Upgrade All Assets V1 to V2");
private ShaderVariantRegistryEditor _shaderVariantRegistryEditor;

public override void OnInspectorGUI()
{
EditorGUIUtility.labelWidth = 180;
base.OnInspectorGUI();

// Draw SoftMask/SoftMaskable/TerminalShape Shaders;
EditorGUILayout.BeginHorizontal();
// Shader registry.
EditorGUILayout.Space();
EditorGUILayout.LabelField("Shader", EditorStyles.boldLabel);
if (_shaderVariantRegistryEditor == null)
{
EditorGUILayout.PrefixLabel(s_ContentIncluded);
if (GUILayout.Button(s_ContentReset, EditorStyles.miniButton, GUILayout.Width(80)))
{
UISoftMaskProjectSettings.instance.ReloadShaders(true);
}
var property = serializedObject.FindProperty("m_ShaderVariantRegistry");
_shaderVariantRegistryEditor = new ShaderVariantRegistryEditor(property, "(SoftMaskable)");
}
EditorGUILayout.EndHorizontal();

foreach (var shader in AlwaysIncludedShadersProxy.GetShaders())
{
if (!UISoftMaskProjectSettings.CanIncludeShader(shader)) continue;

EditorGUILayout.BeginHorizontal();
EditorGUILayout.ObjectField(shader, typeof(Shader), false);
if (GUILayout.Button(s_ContentRemove, EditorStyles.miniButton, GUILayout.Width(20)))
{
AlwaysIncludedShadersProxy.Remove(shader);
}

EditorGUILayout.EndHorizontal();
}
_shaderVariantRegistryEditor.Draw();
serializedObject.ApplyModifiedProperties();

// Upgrade v1 to v2.
EditorGUILayout.Space();
EditorGUILayout.LabelField(s_ContentUpgrade, EditorStyles.boldLabel);
if (GUILayout.Button(s_ContentUpgradeButton))
EditorGUILayout.LabelField("Upgrade", EditorStyles.boldLabel);
if (GUILayout.Button("Upgrade All Assets V1 to V2"))
{
EditorApplication.delayCall += () => new UISoftMaskModifierRunner().RunIfUserWantsTo();
}

GUILayout.FlexibleSpace();
}
}
}
Loading

0 comments on commit 19f9289

Please sign in to comment.