From 536c16b1554dac231da6e2d3e4d24ba6a45a09b2 Mon Sep 17 00:00:00 2001 From: Stanislav Osipov Date: Thu, 2 Apr 2020 02:16:45 +0300 Subject: [PATCH 1/2] ShowIfMaterialPropertyDrawer minor enhancement --- .../Shading/ShowIfMaterialPropertyDrawer.cs | 35 +++++++++++-------- 1 file changed, 21 insertions(+), 14 deletions(-) diff --git a/Editor/Shading/ShowIfMaterialPropertyDrawer.cs b/Editor/Shading/ShowIfMaterialPropertyDrawer.cs index b73ed40..b53817b 100644 --- a/Editor/Shading/ShowIfMaterialPropertyDrawer.cs +++ b/Editor/Shading/ShowIfMaterialPropertyDrawer.cs @@ -17,51 +17,51 @@ namespace StansAssets.Foundation.Editor.Shading /// [ShowIf(_BASE_COLOR_ON)] _BaseColor("", Color) = (1,1,1,1) /// /// - public class ShowIfDrawer : MaterialPropertyDrawer + public class ShowIfMaterialPropertyDrawer : MaterialPropertyDrawer { - string[] m_RequiredKeywords; + readonly string[] m_RequiredKeywords; bool m_IsElementHidden; /// /// Creates ShowIfDrawer with one required keyword. /// - public ShowIfDrawer( + public ShowIfMaterialPropertyDrawer( string keyword0) { - m_RequiredKeywords = new string[] {keyword0}; + m_RequiredKeywords = new[] {keyword0}; } /// /// Creates ShowIfDrawer with two required keywords. /// - public ShowIfDrawer( + public ShowIfMaterialPropertyDrawer( string keyword0, string keyword1) { - m_RequiredKeywords = new string[] {keyword0, keyword1}; + m_RequiredKeywords = new[] {keyword0, keyword1}; } /// /// Creates ShowIfDrawer with three required keywords. /// - public ShowIfDrawer( + public ShowIfMaterialPropertyDrawer( string keyword0, string keyword1, string keyword2) { - m_RequiredKeywords = new string[] {keyword0, keyword1, keyword2}; + m_RequiredKeywords = new[] {keyword0, keyword1, keyword2}; } /// /// Creates ShowIfDrawer with four required keywords. /// - public ShowIfDrawer( + public ShowIfMaterialPropertyDrawer( string keyword0, string keyword1, string keyword2, string keyword3) { - m_RequiredKeywords = new string[] {keyword0, keyword1, keyword2, keyword3}; + m_RequiredKeywords = new[] {keyword0, keyword1, keyword2, keyword3}; } public override void OnGUI( @@ -72,15 +72,15 @@ public override void OnGUI( { m_IsElementHidden = false; - for (int i = 0; i < editor.targets.Length; ++i) + foreach (var target in editor.targets) { - Material mat = editor.targets[i] as Material; + var mat = target as Material; if (mat != null) { - for (int j = 0; j < m_RequiredKeywords.Length; ++j) + foreach (var keyword in m_RequiredKeywords) { - if (!mat.IsKeywordEnabled(m_RequiredKeywords[j])) + if (!mat.IsKeywordEnabled(keyword)) { m_IsElementHidden = true; break; @@ -95,6 +95,13 @@ public override void OnGUI( } } + /// + /// Will always return 0 + /// + /// The to make the custom GUI for. + /// The label of this property. + /// Current material editor. + /// Property height in pixels public override float GetPropertyHeight ( MaterialProperty prop, string label, From 5ae60059c06494c3f197afc35d369d17e714ba30 Mon Sep 17 00:00:00 2001 From: Stanislav Osipov Date: Thu, 2 Apr 2020 15:06:35 +0300 Subject: [PATCH 2/2] pr feedback --- ...ShowIfMaterialPropertyDrawer.cs => ShowIfDrawer.cs} | 10 +++++----- ...rialPropertyDrawer.cs.meta => ShowIfDrawer.cs.meta} | 0 2 files changed, 5 insertions(+), 5 deletions(-) rename Editor/Shading/{ShowIfMaterialPropertyDrawer.cs => ShowIfDrawer.cs} (92%) rename Editor/Shading/{ShowIfMaterialPropertyDrawer.cs.meta => ShowIfDrawer.cs.meta} (100%) diff --git a/Editor/Shading/ShowIfMaterialPropertyDrawer.cs b/Editor/Shading/ShowIfDrawer.cs similarity index 92% rename from Editor/Shading/ShowIfMaterialPropertyDrawer.cs rename to Editor/Shading/ShowIfDrawer.cs index b53817b..01b9382 100644 --- a/Editor/Shading/ShowIfMaterialPropertyDrawer.cs +++ b/Editor/Shading/ShowIfDrawer.cs @@ -17,7 +17,7 @@ namespace StansAssets.Foundation.Editor.Shading /// [ShowIf(_BASE_COLOR_ON)] _BaseColor("", Color) = (1,1,1,1) /// /// - public class ShowIfMaterialPropertyDrawer : MaterialPropertyDrawer + public class ShowIfDrawer : MaterialPropertyDrawer { readonly string[] m_RequiredKeywords; bool m_IsElementHidden; @@ -25,7 +25,7 @@ public class ShowIfMaterialPropertyDrawer : MaterialPropertyDrawer /// /// Creates ShowIfDrawer with one required keyword. /// - public ShowIfMaterialPropertyDrawer( + public ShowIfDrawer( string keyword0) { m_RequiredKeywords = new[] {keyword0}; @@ -34,7 +34,7 @@ public ShowIfMaterialPropertyDrawer( /// /// Creates ShowIfDrawer with two required keywords. /// - public ShowIfMaterialPropertyDrawer( + public ShowIfDrawer( string keyword0, string keyword1) { @@ -44,7 +44,7 @@ public ShowIfMaterialPropertyDrawer( /// /// Creates ShowIfDrawer with three required keywords. /// - public ShowIfMaterialPropertyDrawer( + public ShowIfDrawer( string keyword0, string keyword1, string keyword2) @@ -55,7 +55,7 @@ public ShowIfMaterialPropertyDrawer( /// /// Creates ShowIfDrawer with four required keywords. /// - public ShowIfMaterialPropertyDrawer( + public ShowIfDrawer( string keyword0, string keyword1, string keyword2, diff --git a/Editor/Shading/ShowIfMaterialPropertyDrawer.cs.meta b/Editor/Shading/ShowIfDrawer.cs.meta similarity index 100% rename from Editor/Shading/ShowIfMaterialPropertyDrawer.cs.meta rename to Editor/Shading/ShowIfDrawer.cs.meta