mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 00:08:51 -05:00
Add DrawWithUnity attribute
This commit is contained in:
parent
1327d8d544
commit
9182a6268c
@ -1,5 +1,6 @@
|
||||
using System;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.Utilities.Editor;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editor.Integrations.Odin
|
||||
@ -77,6 +78,11 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
{
|
||||
_propertyTree.Draw();
|
||||
}
|
||||
|
||||
if (_propertyTree.RepaintRequired)
|
||||
{
|
||||
GUIHelper.RequestRepaint();
|
||||
}
|
||||
}
|
||||
|
||||
private class LabelOverrideContext : TriPropertyOverrideContext
|
||||
|
@ -1,6 +1,7 @@
|
||||
using System;
|
||||
using Sirenix.Utilities;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.Utilities.Editor;
|
||||
using TriInspector.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
@ -74,6 +75,11 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
{
|
||||
_propertyTree.Draw();
|
||||
}
|
||||
|
||||
if (_propertyTree.RepaintRequired)
|
||||
{
|
||||
GUIHelper.RequestRepaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,7 +1,6 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.Utilities.Editor;
|
||||
using UnityEditor;
|
||||
using Object = UnityEngine.Object;
|
||||
|
||||
@ -88,13 +87,6 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
_odinProperty.RecordForUndo(forceCompleteObjectUndo: true);
|
||||
}
|
||||
|
||||
public override void RequestRepaint()
|
||||
{
|
||||
base.RequestRepaint();
|
||||
|
||||
GUIHelper.RequestRepaint();
|
||||
}
|
||||
|
||||
private void OnPropertyChanged(TriProperty changedProperty)
|
||||
{
|
||||
ApplyEmittedScriptableObject();
|
||||
|
@ -29,6 +29,13 @@ namespace TriInspector.Elements
|
||||
{
|
||||
EditorGUI.BeginChangeCheck();
|
||||
|
||||
if (_property.IsArrayElement &&
|
||||
_serializedProperty.propertyType == SerializedPropertyType.Generic &&
|
||||
_serializedProperty.hasVisibleChildren)
|
||||
{
|
||||
position.xMin += 12;
|
||||
}
|
||||
|
||||
_propertyHandler.OnGUI(position, _serializedProperty, _property.DisplayNameContent, true);
|
||||
|
||||
if (EditorGUI.EndChangeCheck())
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using TriInspector.Utilities;
|
||||
using TriInspectorUnityInternalBridge;
|
||||
using UnityEditor;
|
||||
using UnityEngine;
|
||||
@ -75,7 +76,10 @@ namespace TriInspector.Elements
|
||||
? ScriptAttributeUtilityProxy.GetHandler(serializedProperty)
|
||||
: default(PropertyHandlerProxy?);
|
||||
|
||||
if (!handler.HasValue || !handler.Value.hasPropertyDrawer)
|
||||
var drawWithUnity = handler.HasValue && handler.Value.hasPropertyDrawer ||
|
||||
handler.HasValue && TriUnityInspectorUtilities.MustDrawWithUnity(property);
|
||||
|
||||
if (!drawWithUnity)
|
||||
{
|
||||
var propertyType = property.PropertyType;
|
||||
|
||||
|
@ -113,7 +113,14 @@ namespace TriInspector
|
||||
}
|
||||
}
|
||||
|
||||
if (!IsArrayElement)
|
||||
if (IsArrayElement)
|
||||
{
|
||||
if (TriUnityInspectorUtilities.TryGetSpecialArrayElementName(this, out var specialName))
|
||||
{
|
||||
_displayNameBackingField.text = specialName;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (_definition.CustomLabel != null)
|
||||
{
|
||||
|
@ -85,7 +85,7 @@ namespace TriInspector
|
||||
RootProperty.EnumerateValidationResults(call);
|
||||
}
|
||||
|
||||
public virtual void RequestRepaint()
|
||||
public void RequestRepaint()
|
||||
{
|
||||
RepaintRequired = true;
|
||||
}
|
||||
|
44
Editor/Utilities/TriUnityInspectorUtilities.cs
Normal file
44
Editor/Utilities/TriUnityInspectorUtilities.cs
Normal file
@ -0,0 +1,44 @@
|
||||
using System.Reflection;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Utilities
|
||||
{
|
||||
public class TriUnityInspectorUtilities
|
||||
{
|
||||
private static readonly FieldInfo GUIStyleNameBackingField = typeof(GUIStyle)
|
||||
.GetField("m_Name", BindingFlags.Instance | BindingFlags.NonPublic);
|
||||
|
||||
public static bool MustDrawWithUnity(TriProperty property)
|
||||
{
|
||||
if (property.FieldType == typeof(GUIStyle))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
return !property.IsArray && property.TryGetAttribute(out DrawWithUnityAttribute _);
|
||||
}
|
||||
|
||||
public static bool TryGetSpecialArrayElementName(TriProperty property, out string name)
|
||||
{
|
||||
if (property.FieldType == typeof(GUIStyle) && property.Value is GUIStyle guiStyle)
|
||||
{
|
||||
GUIStyleNameBackingField?.SetValue(guiStyle, null);
|
||||
name = guiStyle.name;
|
||||
return true;
|
||||
}
|
||||
|
||||
if (property.PropertyType == TriPropertyType.Generic &&
|
||||
property.ChildrenProperties.Count > 0 &&
|
||||
property.ChildrenProperties[0] is var firstChild &&
|
||||
firstChild.ValueType == typeof(string) &&
|
||||
firstChild.Value is string firstChildValueStr)
|
||||
{
|
||||
name = firstChildValueStr;
|
||||
return true;
|
||||
}
|
||||
|
||||
name = default;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
3
Editor/Utilities/TriUnityInspectorUtilities.cs.meta
Normal file
3
Editor/Utilities/TriUnityInspectorUtilities.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 239f16a6fc1543b8b131493585c954b3
|
||||
timeCreated: 1668183919
|
11
Runtime/Attributes/DrawWithUnityAttribute.cs
Normal file
11
Runtime/Attributes/DrawWithUnityAttribute.cs
Normal file
@ -0,0 +1,11 @@
|
||||
using System;
|
||||
using System.Diagnostics;
|
||||
|
||||
namespace TriInspector
|
||||
{
|
||||
[AttributeUsage(AttributeTargets.Field)]
|
||||
[Conditional("UNITY_EDITOR")]
|
||||
public class DrawWithUnityAttribute : Attribute
|
||||
{
|
||||
}
|
||||
}
|
3
Runtime/Attributes/DrawWithUnityAttribute.cs.meta
Normal file
3
Runtime/Attributes/DrawWithUnityAttribute.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 72a4f37291e74452877df4701818e180
|
||||
timeCreated: 1668181199
|
Loading…
Reference in New Issue
Block a user