mirror of
https://github.com/codewriter-packages/Tri-Inspector.git
synced 2025-01-22 08:18:49 -05:00
Optimize odin integration
This commit is contained in:
parent
858da9e174
commit
c1cecb4285
@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEngine;
|
||||
|
||||
namespace TriInspector.Editor.Integrations.Odin
|
||||
@ -19,13 +18,12 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof(UnityEngine.Object).IsAssignableFrom(type))
|
||||
if (!TriOdinUtility.IsDrawnByTri(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
|
||||
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
|
||||
if (typeof(UnityEngine.Object).IsAssignableFrom(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -43,8 +41,7 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
for (var parent = property.Parent; parent != null; parent = parent.Parent)
|
||||
{
|
||||
var parentType = parent.ValueEntry.TypeOfValue;
|
||||
if (parentType.IsDefined<DrawWithTriInspectorAttribute>() ||
|
||||
parentType.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
|
||||
if (TriOdinUtility.IsDrawnByTri(parentType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Sirenix.Utilities;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.OdinInspector.Editor.Validation;
|
||||
using TriInspector.Editor.Integrations.Odin;
|
||||
@ -30,13 +29,12 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
return false;
|
||||
}
|
||||
|
||||
if (typeof(UnityEngine.Object).IsAssignableFrom(type))
|
||||
if (!TriOdinUtility.IsDrawnByTri(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
|
||||
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
|
||||
if (typeof(UnityEngine.Object).IsAssignableFrom(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@ -44,8 +42,7 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
for (var parent = property.Parent; parent != null; parent = parent.Parent)
|
||||
{
|
||||
var parentType = parent.Info.TypeOfValue;
|
||||
if (parentType.IsDefined<DrawWithTriInspectorAttribute>() ||
|
||||
parentType.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
|
||||
if (TriOdinUtility.IsDrawnByTri(parentType))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -20,8 +20,7 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
|
||||
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
|
||||
if (!TriOdinUtility.IsDrawnByTri(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
@ -1,5 +1,4 @@
|
||||
using System;
|
||||
using Sirenix.Utilities;
|
||||
using Sirenix.OdinInspector.Editor;
|
||||
using Sirenix.OdinInspector.Editor.Validation;
|
||||
using TriInspector.Editor.Integrations.Odin;
|
||||
@ -33,8 +32,7 @@ namespace TriInspector.Editor.Integrations.Odin
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!type.IsDefined<DrawWithTriInspectorAttribute>() &&
|
||||
!type.Assembly.IsDefined<DrawWithTriInspectorAttribute>())
|
||||
if (!TriOdinUtility.IsDrawnByTri(type))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
40
Editor.Integrations/Odin/TriOdinUtility.cs
Normal file
40
Editor.Integrations/Odin/TriOdinUtility.cs
Normal file
@ -0,0 +1,40 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Reflection;
|
||||
using Sirenix.Utilities;
|
||||
using UnityEditor;
|
||||
|
||||
namespace TriInspector.Editor.Integrations.Odin
|
||||
{
|
||||
public static class TriOdinUtility
|
||||
{
|
||||
private static readonly Dictionary<Assembly, bool> TriDrawnAssemblies = new Dictionary<Assembly, bool>();
|
||||
private static HashSet<Type> _triDrawnTypes;
|
||||
|
||||
public static bool IsDrawnByTri(Type type)
|
||||
{
|
||||
if (_triDrawnTypes == null)
|
||||
{
|
||||
var list = TypeCache.GetTypesWithAttribute<DrawWithTriInspectorAttribute>();
|
||||
var array = new Type[list.Count];
|
||||
list.CopyTo(array, 0);
|
||||
_triDrawnTypes = new HashSet<Type>(array);
|
||||
}
|
||||
|
||||
if (_triDrawnTypes.Contains(type))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
var asm = type.Assembly;
|
||||
if (TriDrawnAssemblies.TryGetValue(asm, out var assemblyDrawnByTri))
|
||||
{
|
||||
return assemblyDrawnByTri;
|
||||
}
|
||||
|
||||
assemblyDrawnByTri = asm.IsDefined<DrawWithTriInspectorAttribute>(false);
|
||||
TriDrawnAssemblies[asm] = assemblyDrawnByTri;
|
||||
return assemblyDrawnByTri;
|
||||
}
|
||||
}
|
||||
}
|
3
Editor.Integrations/Odin/TriOdinUtility.cs.meta
Normal file
3
Editor.Integrations/Odin/TriOdinUtility.cs.meta
Normal file
@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c2be8b6a4b4d44c19156b0f1c1d40fc6
|
||||
timeCreated: 1661688784
|
Loading…
Reference in New Issue
Block a user