Skip to content

Commit e0331a1

Browse files
Add README url to ErrorMessage.
1 parent 7a53fce commit e0331a1

File tree

3 files changed

+20
-10
lines changed

3 files changed

+20
-10
lines changed

Assets/CustomMethodButton/Attributes/MethodButtonAttribute.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,11 @@ public class MethodButtonAttribute : PropertyAttribute
1313
/// Array of different method names for which a button will be displayed.
1414
/// <para>"MethodOne", MethodTwo" ... "MethodN"</para>
1515
/// </summary>
16-
public string[] MethodNames { get; set; }
16+
public string[] MethodNames { get; private set; }
1717

18+
/// <summary>
19+
/// Default constructor.
20+
/// </summary>
1821
public MethodButtonAttribute(params string[] args)
1922
{
2023
MethodNames = args;

Assets/CustomMethodButton/Drawers/MethodButtonAttributeDrawer.cs

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
[CustomPropertyDrawer(typeof(MethodButtonAttribute))]
66
public class MethodButtonAttributeDrawer : PropertyDrawer
77
{
8-
private int i;
8+
private int buttonCount;
99
private float buttonHeight = EditorGUIUtility.singleLineHeight;
1010
private MethodButtonAttribute attr;
1111

@@ -17,17 +17,24 @@ public override void OnGUI(Rect position, SerializedProperty editorFoldout, GUIC
1717
return;
1818
}
1919

20-
i = 0;
20+
buttonCount = 0;
21+
2122
Rect foldoutRect = new Rect(position.x, position.y, position.width, buttonHeight);
23+
2224
editorFoldout.boolValue = EditorGUI.Foldout(foldoutRect, editorFoldout.boolValue, "Buttons", true);
25+
2326
if (editorFoldout.boolValue)
2427
{
25-
i++;
28+
buttonCount++;
29+
2630
attr = (MethodButtonAttribute)base.attribute;
31+
2732
foreach (var name in attr.MethodNames)
2833
{
29-
i++;
30-
Rect buttonRect = new Rect(position.x, position.y + (buttonHeight * i), position.width, buttonHeight);
34+
buttonCount++;
35+
36+
Rect buttonRect = new Rect(position.x, position.y + (buttonHeight * buttonCount), position.width, buttonHeight);
37+
3138
if (GUI.Button(buttonRect, name))
3239
{
3340
InvokeMethod(editorFoldout, name);
@@ -38,7 +45,7 @@ public override void OnGUI(Rect position, SerializedProperty editorFoldout, GUIC
3845

3946
public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
4047
{
41-
return EditorGUI.GetPropertyHeight(property, label, true) + buttonHeight * i + 2;
48+
return EditorGUI.GetPropertyHeight(property, label, true) + buttonHeight * buttonCount + 2;
4249
}
4350

4451
private void InvokeMethod(SerializedProperty property, string name)
@@ -52,10 +59,10 @@ private void LogErrorMessage(SerializedProperty editorFoldout)
5259
Debug.LogError("<color=red><b>Possible improper usage of method button attribute!</b></color>");
5360
#if NET_4_6
5461
Debug.LogError($"Got field name: <b>{editorFoldout.name}</b>, Expected: <b>editorFoldout</b>");
55-
Debug.LogError($"Please see <b>{"Usage"}</b> at <b><i><color=blue>{"https://github/address"}</color></i></b>");
62+
Debug.LogError($"Please see <b>{"Usage"}</b> at <b><i><color=blue>{"https://github.com/GlassToeStudio/UnityMethodButtonAttribute/blob/master/README.md"}</color></i></b>");
5663
#else
5764
Debug.LogError(string.Format("Got field name: <b>{0}</b>, Expected: <b>editorFoldout</b>", editorFoldout.name));
58-
Debug.LogError("Please see <b>\"Usage\"</b> at <b><i><color=blue>\"https://github/address\"</color></i></b>");
65+
Debug.LogError("Please see <b>\"Usage\"</b> at <b><i><color=blue>\"https://github.com/GlassToeStudio/UnityMethodButtonAttribute/blob/master/README.md \"</color></i></b>");
5966
#endif
6067
}
6168
}

Assets/Demo/Scenes/MethodButton.unity

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,7 @@ MonoBehaviour:
142142
m_EditorClassIdentifier:
143143
ExampleInt: 0
144144
ExampleBool: 0
145-
editorFoldout: 0
145+
editorFoldout: 1
146146
--- !u!4 &398710250
147147
Transform:
148148
m_ObjectHideFlags: 0

0 commit comments

Comments
 (0)