Allow DrawWithTriInspector attribute on assembly level

This commit is contained in:
VladV 2022-05-25 10:05:29 +03:00
parent 892cfdf07d
commit fda4fe744e
5 changed files with 45 additions and 8 deletions

View File

@ -1,5 +1,6 @@
using System;
using Sirenix.OdinInspector.Editor;
using Sirenix.Utilities;
using Sirenix.Utilities.Editor;
using TriInspector.Utilities;
using UnityEngine;
@ -7,7 +8,7 @@ using UnityEngine;
namespace TriInspector.Editor.Integrations.Odin
{
[DrawerPriority(0.0, 10000.0, 1.0)]
public class OdinFieldDrawer<T> : OdinAttributeDrawer<DrawWithTriInspectorAttribute, T>, IDisposable
public class OdinFieldDrawer<T> : OdinValueDrawer<T>, IDisposable
{
private TriPropertyTree _propertyTree;
@ -18,10 +19,16 @@ namespace TriInspector.Editor.Integrations.Odin
return false;
}
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
{
return false;
}
return true;
}
protected override bool CanDrawAttributeValueProperty(InspectorProperty property)
protected override bool CanDrawValueProperty(InspectorProperty property)
{
if (property.IsTreeRoot)
{

View File

@ -1,4 +1,5 @@
using System;
using Sirenix.Utilities;
using Sirenix.OdinInspector.Editor;
using Sirenix.OdinInspector.Editor.Validation;
using TriInspector.Editor.Integrations.Odin;
@ -7,7 +8,7 @@ using TriInspector.Editor.Integrations.Odin;
namespace TriInspector.Editor.Integrations.Odin
{
public class OdinFieldValidator<T> : AttributeValidator<DrawWithTriInspectorAttribute, T>, IDisposable
public class OdinFieldValidator<T> : ValueValidator<T>, IDisposable
{
private TriPropertyTreeForOdin<T> _propertyTree;
@ -16,7 +17,15 @@ namespace TriInspector.Editor.Integrations.Odin
public override bool CanValidateProperty(InspectorProperty property)
{
if (typeof(UnityEngine.Object).IsAssignableFrom(property.Info.TypeOfValue))
var type = property.Info.TypeOfValue;
if (typeof(UnityEngine.Object).IsAssignableFrom(type))
{
return false;
}
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
{
return false;
}

View File

@ -1,16 +1,28 @@
using System;
using Sirenix.Utilities;
using Sirenix.OdinInspector.Editor;
using UnityEngine;
namespace TriInspector.Editor.Integrations.Odin
{
[DrawerPriority(0.0, 10000.0, 1.0)]
public class OdinObjectDrawer<T> : OdinAttributeDrawer<DrawWithTriInspectorAttribute, T>, IDisposable
public class OdinObjectDrawer<T> : OdinValueDrawer<T>, IDisposable
where T : UnityEngine.Object
{
private TriPropertyTree _propertyTree;
protected override bool CanDrawAttributeValueProperty(InspectorProperty property)
public override bool CanDrawTypeFilter(Type type)
{
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
{
return false;
}
return true;
}
protected override bool CanDrawValueProperty(InspectorProperty property)
{
if (!property.IsTreeRoot)
{

View File

@ -1,4 +1,5 @@
using System;
using Sirenix.Utilities;
using Sirenix.OdinInspector.Editor;
using Sirenix.OdinInspector.Editor.Validation;
using TriInspector.Editor.Integrations.Odin;
@ -8,7 +9,7 @@ using UnityEditor;
namespace TriInspector.Editor.Integrations.Odin
{
public class OdinObjectValidator<T> : AttributeValidator<DrawWithTriInspectorAttribute, T>, IDisposable
public class OdinObjectValidator<T> : ValueValidator<T>, IDisposable
where T : UnityEngine.Object
{
private TriPropertyTreeForSerializedObject _propertyTree;
@ -19,6 +20,14 @@ namespace TriInspector.Editor.Integrations.Odin
public override bool CanValidateProperty(InspectorProperty property)
{
var type = property.Info.TypeOfValue;
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
{
return false;
}
if (!property.IsTreeRoot)
{
return false;

View File

@ -3,7 +3,7 @@ using System.Diagnostics;
namespace TriInspector
{
[AttributeUsage(AttributeTargets.Class)]
[AttributeUsage(AttributeTargets.Class | AttributeTargets.Assembly)]
[Conditional("UNITY_EDITOR")]
public class DrawWithTriInspectorAttribute : Attribute
{