From 8bd77e1683e3e3d313dfce96f68900f368305d3e Mon Sep 17 00:00:00 2001 From: Jason Ma <1312119064@qq.com> Date: Sun, 25 Sep 2022 23:10:34 +0800 Subject: [PATCH] fix bugs --- Editor/DrawerUtility.cs | 14 +++++++++----- Editor/ShaderDrawer.cs | 21 ++++++++++----------- 2 files changed, 19 insertions(+), 16 deletions(-) diff --git a/Editor/DrawerUtility.cs b/Editor/DrawerUtility.cs index 9734d99..82ca8a1 100644 --- a/Editor/DrawerUtility.cs +++ b/Editor/DrawerUtility.cs @@ -1035,9 +1035,9 @@ internal class MetaDataHelper private static Dictionary>> _mainSubDic = new Dictionary>>(); private static Dictionary> _mainGroupNameDic = new Dictionary>(); - private static Dictionary>> _extraPropDic = new Dictionary>>(); - private static Dictionary>> _tooltipDic = new Dictionary>>(); - private static Dictionary>> _HelpboxDic = new Dictionary>>(); + private static Dictionary>>_extraPropDic = new Dictionary>>(); + private static Dictionary>> _tooltipDic = new Dictionary>>(); + private static Dictionary>> _HelpboxDic = new Dictionary>>(); public static void RegisterMainProp(Shader shader, MaterialProperty prop, string group) { @@ -1081,7 +1081,8 @@ public static void RegisterSubProp(Shader shader, MaterialProperty prop, string var mainPropName = _mainGroupNameDic[shader][groupName]; if (_mainSubDic[shader].ContainsKey(mainPropName)) { - _mainSubDic[shader][mainPropName].Add(prop.name); + if (!_mainSubDic[shader][mainPropName].Contains(prop.name)) + _mainSubDic[shader][mainPropName].Add(prop.name); } else Debug.LogError($"Unregistered Main Property:{mainPropName}"); @@ -1102,7 +1103,10 @@ public static void RegisterSubProp(Shader shader, MaterialProperty prop, string foreach (var extraProp in extraProps) { if (extraProp != null) - _extraPropDic[shader][prop.name].Add(extraProp.name); + { + if (!_extraPropDic[shader][prop.name].Contains(extraProp.name)) + _extraPropDic[shader][prop.name].Add(extraProp.name); + } } } } diff --git a/Editor/ShaderDrawer.cs b/Editor/ShaderDrawer.cs index bf43fa1..db9aff8 100644 --- a/Editor/ShaderDrawer.cs +++ b/Editor/ShaderDrawer.cs @@ -102,20 +102,24 @@ internal class SubDrawer : MaterialPropertyDrawer protected LWGUI lwgui; protected Shader shader; + public SubDrawer() { } + public SubDrawer(string group) + { + this.group = group; + } + + protected virtual bool IsMatchPropType(MaterialProperty property) { return true; } + protected virtual float GetVisibleHeight(MaterialProperty prop) { var height = MaterialEditor.GetDefaultPropertyHeight(prop); return prop.type == MaterialProperty.PropType.Vector ? EditorGUIUtility.singleLineHeight : height; } - protected virtual bool IsMatchPropType(MaterialProperty property) { return true; } - - public SubDrawer() { } - - public SubDrawer(string group) + public virtual void Init(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) { - this.group = group; + MetaDataHelper.RegisterSubProp(shader, prop, group); } public override void OnGUI(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) @@ -159,11 +163,6 @@ public override float GetPropertyHeight(MaterialProperty prop, string label, Mat return GroupStateHelper.IsSubVisible(editor.target, group) ? GetVisibleHeight(prop) : 0; } - public virtual void Init(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) - { - MetaDataHelper.RegisterSubProp(shader, prop, group); - } - // Draws a custom style property public virtual void DrawProp(Rect position, MaterialProperty prop, GUIContent label, MaterialEditor editor) {