Skip to content
Open
Show file tree
Hide file tree
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
19 changes: 10 additions & 9 deletions Editor.Extras/Drawers/AnimatorParameterAttributeDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
using TriInspector;
using TriInspector.Drawers;
using TriInspector.Resolvers;
using TriInspector.VisualElements;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;

[assembly: RegisterTriAttributeDrawer(typeof(AnimatorParameterAttributeDrawer), TriDrawerOrder.Decorator, ApplyOnArrayElement = true)]

Expand All @@ -34,17 +36,20 @@ public override TriExtensionInitializationResult Initialize(TriPropertyDefinitio

return TriExtensionInitializationResult.Ok;
}
public override void OnGUI(Rect position, TriProperty property, TriElement next)
public override VisualElement CreateVisualElement(TriProperty property, VisualElement next)
{
var imgui = new IMGUIContainer(() => DrawImgui(property));
return new TriAlignedLabelVisualElement(property, imgui);
}

private void DrawImgui(TriProperty property)
{
var animator = _resolvedParams.AnimatorResolver.GetValue(property);
var label = property.DisplayNameContent;
var (allParameters, allFilteredParameters) = AnimatorParameterHelper.GetParameters(animator, Attribute.ParameterType);

if (property.ValueType == typeof(string))
{
DrawPopup(
position,
label,
property,
animator,
(string)property.Value,
Expand All @@ -58,8 +63,6 @@ public override void OnGUI(Rect position, TriProperty property, TriElement next)
else if (property.ValueType == typeof(int))
{
DrawPopup(
position,
label,
property,
animator,
(int)property.Value,
Expand All @@ -72,8 +75,6 @@ public override void OnGUI(Rect position, TriProperty property, TriElement next)
}
}
private void DrawPopup<T>(
Rect position,
GUIContent label,
TriProperty property,
Animator animator,
T currentValue,
Expand Down Expand Up @@ -106,7 +107,7 @@ private void DrawPopup<T>(
}

EditorGUI.BeginChangeCheck();
int newIndex = EditorGUI.Popup(position, label, currentIndex, displayList.ToArray());
int newIndex = EditorGUILayout.Popup(currentIndex, displayList.ToArray());

if (EditorGUI.EndChangeCheck())
{
Expand Down
23 changes: 13 additions & 10 deletions Editor.Extras/Drawers/AssetDropdownDrawer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@
using System.Linq;
using TriInspector;
using TriInspector.Drawers;
using TriInspector.Elements;
using TriInspector.Utilities;
using TriInspector.VisualElements;
using UnityEditor;
using UnityEngine;
using UnityEngine.UIElements;
using Object = UnityEngine.Object;

[assembly: RegisterTriAttributeDrawer(typeof(AssetDropdownDrawer<>), TriDrawerOrder.Decorator,
ApplyOnArrayElement = true)]
Expand All @@ -14,7 +15,7 @@ namespace TriInspector.Drawers
{
public class AssetDropdownDrawer<T> : TriAttributeDrawer<AssetDropdownAttribute>
{
private bool showNoneElement;
private bool _showNoneElement;

public override TriExtensionInitializationResult Initialize(TriPropertyDefinition propertyDefinition)
{
Expand All @@ -24,23 +25,25 @@ public override TriExtensionInitializationResult Initialize(TriPropertyDefinitio
return "AssetDropdown attribute can only be used on field with UnityEngine.Object type";
}

showNoneElement = !propertyDefinition.Attributes.TryGet<RequiredAttribute>(out _);
_showNoneElement = !propertyDefinition.Attributes.TryGet<RequiredAttribute>(out _);

return base.Initialize(propertyDefinition);
}

public override TriElement CreateElement(TriProperty property, TriElement next)
public override VisualElement CreateVisualElement(TriProperty property, VisualElement next)
{
var dropdownElement = new TriDropdownElement(property, EnumerateAssets, Attribute.Advanced);
var dropdownElement = new TriDropdownVisualElement(property, EnumerateAssets, Attribute.Advanced);

if (Attribute.HideNextDrawer)
{
return dropdownElement;
}

var line = new TriHorizontalGroupElement();
line.AddChild(dropdownElement);
line.AddChild(base.CreateElement(property, next));
var line = new VisualElement();
line.style.flexDirection = FlexDirection.Row;
dropdownElement.style.flexGrow = 1;
line.Add(dropdownElement);
line.Add(next);
return line;
}

Expand All @@ -56,7 +59,7 @@ private IEnumerable<ITriDropdownItem> EnumerateAssets(TriProperty property)
Value = (T) (object) asset,
});

if (showNoneElement)
if (_showNoneElement)
{
assets = assets.Prepend(new TriDropdownItem<T> {Text = "None", Value = default,});
}
Expand Down
38 changes: 11 additions & 27 deletions Editor.Extras/Drawers/BuiltinDrawerBase.cs
Original file line number Diff line number Diff line change
@@ -1,45 +1,29 @@
using UnityEditor;
using UnityEngine;
using TriInspector.VisualElements;
using UnityEngine.UIElements;

namespace TriInspector.Drawers
{
public abstract class BuiltinDrawerBase<T> : TriValueDrawer<T>
{
public sealed override TriElement CreateElement(TriValue<T> propertyValue, TriElement next)
public override VisualElement CreateVisualElement(TriValue<T> propertyValue, VisualElement next)
{
if (propertyValue.Property.TryGetSerializedProperty(out _))
{
return next;
}

return base.CreateElement(propertyValue, next);
}

public virtual int CompactModeLines => 1;
public virtual int WideModeLines => 1;
var field = CreateField();
if (field == null)
{
return next;
}

public sealed override float GetHeight(float width, TriValue<T> propertyValue, TriElement next)
{
var lineHeight = EditorGUIUtility.singleLineHeight;
var spacing = EditorGUIUtility.standardVerticalSpacing;
var lines = EditorGUIUtility.wideMode ? WideModeLines : CompactModeLines;
return lineHeight * lines + spacing * (lines - 1);
return TriBuiltinFieldFactory.Create(propertyValue, field);
}

public sealed override void OnGUI(Rect position, TriValue<T> propertyValue, TriElement next)
protected virtual BaseField<T> CreateField()
{
var value = propertyValue.SmartValue;

EditorGUI.BeginChangeCheck();

value = OnValueGUI(position, propertyValue.Property.DisplayNameContent, value);

if (EditorGUI.EndChangeCheck())
{
propertyValue.SetValue(value);
}
return null;
}

protected abstract T OnValueGUI(Rect position, GUIContent label, T value);
}
}
Loading