diff options
| author | yum <yum.food.vr@gmail.com> | 2024-09-23 01:46:23 -0700 |
|---|---|---|
| committer | yum <yum.food.vr@gmail.com> | 2024-09-23 13:41:42 -0700 |
| commit | 88a524d71bf46bca1c65c3f7ed5fcd3f6edd1d5e (patch) | |
| tree | ffc25a73064e9014921eecd08c2f76d453bb84ae /Editor/tooner.cs | |
| parent | 8bcfe9a6a31e4c4400cb0be4fb1823748ec7fcb2 (diff) | |
Begin refactoring c#
I want all the SetKeyword stuff to run whether or not the UI is shown.
Diffstat (limited to 'Editor/tooner.cs')
| -rw-r--r-- | Editor/tooner.cs | 56 |
1 files changed, 40 insertions, 16 deletions
diff --git a/Editor/tooner.cs b/Editor/tooner.cs index 1ee5135..29ff40b 100644 --- a/Editor/tooner.cs +++ b/Editor/tooner.cs @@ -47,7 +47,11 @@ public class ToonerGUI : ShaderGUI { } } - void DoBaseColor() { + void DoBaseColorLogic() { + MaterialProperty bct = FindProperty("_MainTex"); + SetKeyword("_BASECOLOR_MAP", bct.textureValue); + } + void DoBaseColorUI() { MaterialProperty bc = FindProperty("_Color"); MaterialProperty bct = FindProperty("_MainTex"); editor.TexturePropertySingleLine( @@ -57,10 +61,13 @@ public class ToonerGUI : ShaderGUI { if (bct.textureValue) { editor.TextureScaleOffsetProperty(bct); } - SetKeyword("_BASECOLOR_MAP", bct.textureValue); } - void DoNormal() { + void DoNormalLogic() { + MaterialProperty bct = FindProperty("_NormalTex"); + SetKeyword("_NORMAL_MAP", bct.textureValue); + } + void DoNormalUI() { MaterialProperty bct = FindProperty("_NormalTex"); editor.TexturePropertySingleLine( MakeLabel(bct, "Normal"), @@ -69,10 +76,13 @@ public class ToonerGUI : ShaderGUI { if (bct.textureValue) { editor.TextureScaleOffsetProperty(bct); } - SetKeyword("_NORMAL_MAP", bct.textureValue); } - void DoMetallic() { + void DoMetallicLogic() { + MaterialProperty bct = FindProperty("_MetallicTex"); + SetKeyword("_METALLIC_MAP", bct.textureValue); + } + void DoMetallicUI() { MaterialProperty bc = FindProperty("_Metallic"); MaterialProperty bct = FindProperty("_MetallicTex"); editor.TexturePropertySingleLine( @@ -82,10 +92,13 @@ public class ToonerGUI : ShaderGUI { if (bct.textureValue) { editor.TextureScaleOffsetProperty(bct); } - SetKeyword("_METALLIC_MAP", bct.textureValue); } - void DoRoughness() { + void DoRoughnessLogic() { + MaterialProperty bct = FindProperty("_RoughnessTex"); + SetKeyword("_ROUGHNESS_MAP", bct.textureValue); + } + void DoRoughnessUI() { MaterialProperty bc = FindProperty("_Roughness"); MaterialProperty bct = FindProperty("_RoughnessTex"); editor.TexturePropertySingleLine( @@ -102,8 +115,6 @@ public class ToonerGUI : ShaderGUI { EditorGUI.EndChangeCheck(); bc.floatValue = enabled ? 1.0f : 0.0f; } - - SetKeyword("_ROUGHNESS_MAP", bct.textureValue); } bool AddCollapsibleMenu(string name, string matprop) { @@ -124,16 +135,27 @@ public class ToonerGUI : ShaderGUI { Repeat, Clamp, }; - void DoPBR() { + void DoPBRLogic() { + DoBaseColorLogic(); + DoNormalLogic(); + DoMetallicLogic(); + DoRoughnessLogic(); + + MaterialProperty bc = FindProperty($"_PBR_Sampler_Mode"); + SamplerMode sampler_mode = (SamplerMode) Math.Round(bc.floatValue); + SetKeyword($"_PBR_SAMPLER_REPEAT", sampler_mode == SamplerMode.Repeat); + SetKeyword($"_PBR_SAMPLER_CLAMP", sampler_mode == SamplerMode.Clamp); + } + void DoPBRUI() { if (!AddCollapsibleMenu("PBR", "_PBR")) { return; } EditorGUI.indentLevel += 1; { - DoBaseColor(); - DoNormal(); - DoMetallic(); - DoRoughness(); + DoBaseColorUI(); + DoNormalUI(); + DoMetallicUI(); + DoRoughnessUI(); EditorGUI.BeginChangeCheck(); MaterialProperty bc = FindProperty($"_PBR_Sampler_Mode"); @@ -142,11 +164,13 @@ public class ToonerGUI : ShaderGUI { MakeLabel("Sampler mode"), sampler_mode); EditorGUI.EndChangeCheck(); bc.floatValue = (int) sampler_mode; - SetKeyword($"_PBR_SAMPLER_REPEAT", sampler_mode == SamplerMode.Repeat); - SetKeyword($"_PBR_SAMPLER_CLAMP", sampler_mode == SamplerMode.Clamp); } EditorGUI.indentLevel -= 1; } + void DoPBR() { + DoPBRLogic(); + DoPBRUI(); + } void DoClearcoat() { if (!AddCollapsibleMenu($"Clearcoat", $"_Clearcoat")) { |
