Skip to content

Commit

Permalink
DisplayInspector now will show warning if used on property of the wro…
Browse files Browse the repository at this point in the history
…ng type
  • Loading branch information
Deadcows committed Aug 20, 2021
1 parent 712bb0a commit 7da724c
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Attributes/DisplayInspectorAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ private SerializedObject GetTargetSO(Object targetObject)

public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
bool notValidType = property.propertyType != SerializedPropertyType.ObjectReference;
if (notValidType)
{
EditorGUI.LabelField(position, label.text, "Use [DisplayInspector] with MB or SO");
return;
}

if (((DisplayInspectorAttribute)attribute).DisplayScript || property.objectReferenceValue == null)
{
position.height = EditorGUI.GetPropertyHeight(property);
Expand Down Expand Up @@ -109,7 +116,8 @@ public override void OnGUI(Rect position, SerializedProperty property, GUIConten

public override float GetPropertyHeight(SerializedProperty property, GUIContent label)
{
if (property.objectReferenceValue == null) return base.GetPropertyHeight(property, label);
bool notValidType = property.propertyType != SerializedPropertyType.ObjectReference;
if (notValidType || property.objectReferenceValue == null) return base.GetPropertyHeight(property, label);
if (_buttonMethods == null) _buttonMethods = new ButtonMethodHandler(property.objectReferenceValue);

float height = ((DisplayInspectorAttribute)attribute).DisplayScript ? EditorGUI.GetPropertyHeight(property) + 4 : 0;
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ All notable changes to this package will be documented in this file.
- Extensions: IList.ExclusiveSample() returns collection of random elements. Thanks to @tonygiang!
- Extensions: Rigidbody.ToggleConstraints extension. Thanks to @tonygiang!
- Fix: FPSCounter now works correctly if EditorOnly is toggled. Thanks to @TheWalruzz!
- Fix: DisplayInspector now will show warning if used on property of the wrong type
- Fix: FoldoutAttribute visual improvements

## [1.7.0] - 2021-06-09
Expand Down

0 comments on commit 7da724c

Please sign in to comment.