Skip to content

Commit

Permalink
fix bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
JasonMa0012 committed Sep 25, 2022
1 parent 3520d28 commit 8bd77e1
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 16 deletions.
14 changes: 9 additions & 5 deletions Editor/DrawerUtility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1035,9 +1035,9 @@ internal class MetaDataHelper
private static Dictionary<Shader, Dictionary<string /*MainProp*/, List<string /*SubProp*/>>> _mainSubDic = new Dictionary<Shader, Dictionary<string, List<string>>>();
private static Dictionary<Shader, Dictionary<string /*GroupName*/, string /*MainProp*/>> _mainGroupNameDic = new Dictionary<Shader, Dictionary<string, string>>();

private static Dictionary<Shader, Dictionary<string /*Prop*/, List<string /*ExtraProp*/>>> _extraPropDic = new Dictionary<Shader, Dictionary<string, List<string>>>();
private static Dictionary<Shader, Dictionary<string /*Prop*/, List<string /*Tooltip*/>>> _tooltipDic = new Dictionary<Shader, Dictionary<string, List<string>>>();
private static Dictionary<Shader, Dictionary<string /*Prop*/, List<string /*Helpbox*/>>> _HelpboxDic = new Dictionary<Shader, Dictionary<string, List<string>>>();
private static Dictionary<Shader, Dictionary<string /*PropName*/, List<string /*ExtraPropName*/>>>_extraPropDic = new Dictionary<Shader, Dictionary<string, List<string>>>();
private static Dictionary<Shader, Dictionary<string /*PropName*/, List<string /*Tooltip*/>>> _tooltipDic = new Dictionary<Shader, Dictionary<string, List<string>>>();
private static Dictionary<Shader, Dictionary<string /*PropName*/, List<string /*Helpbox*/>>> _HelpboxDic = new Dictionary<Shader, Dictionary<string, List<string>>>();

public static void RegisterMainProp(Shader shader, MaterialProperty prop, string group)
{
Expand Down Expand Up @@ -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}");
Expand All @@ -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);
}
}
}
}
Expand Down
21 changes: 10 additions & 11 deletions Editor/ShaderDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
{
Expand Down

0 comments on commit 8bd77e1

Please sign in to comment.