Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix LayerMask drawer #140

Merged
merged 1 commit into from
Oct 25, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions Editor.Extras/Drawers/BuiltinDrawers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using TriInspector;
using TriInspector.Drawers;
using UnityEditor;
using UnityEditorInternal;
using UnityEngine;

[assembly: RegisterTriValueDrawer(typeof(IntegerDrawer), TriDrawerOrder.Fallback)]
Expand Down Expand Up @@ -34,7 +35,7 @@ protected override string OnValueGUI(Rect position, GUIContent label, string val
return EditorGUI.TextField(position, label, value);
}
}

public class BooleanDrawer : BuiltinDrawerBase<bool>
{
protected override bool OnValueGUI(Rect position, GUIContent label, bool value)
Expand All @@ -50,13 +51,15 @@ protected override int OnValueGUI(Rect position, GUIContent label, int value)
return EditorGUI.IntField(position, label, value);
}
}

public class LongDrawer : BuiltinDrawerBase<long>
{
protected override long OnValueGUI(Rect position, GUIContent label, long value)
{
return EditorGUI.LongField(position, label, value);
}
}

public class FloatDrawer : BuiltinDrawerBase<float>
{
protected override float OnValueGUI(Rect position, GUIContent label, float value)
Expand Down Expand Up @@ -85,7 +88,11 @@ public class LayerMaskDrawer : BuiltinDrawerBase<LayerMask>
{
protected override LayerMask OnValueGUI(Rect position, GUIContent label, LayerMask value)
{
return EditorGUI.LayerField(position, label, value);
var mask = InternalEditorUtility.LayerMaskToConcatenatedLayersMask(value);
var layers = InternalEditorUtility.layers;

position = EditorGUI.PrefixLabel(position, label);
return EditorGUI.MaskField(position, mask, layers);
}
}

Expand Down Expand Up @@ -160,15 +167,15 @@ protected override Bounds OnValueGUI(Rect position, GUIContent label, Bounds val
public class GradientDrawer : BuiltinDrawerBase<Gradient>
{
private static readonly GUIContent NullLabel = new GUIContent("Gradient is null");

protected override Gradient OnValueGUI(Rect position, GUIContent label, Gradient value)
{
if (value == null)
{
EditorGUI.LabelField(position, label, NullLabel);
return null;
}

return EditorGUI.GradientField(position, label, value);
}
}
Expand Down