Tri-Inspector/Editor.Integrations/Odin/TriOdinUtility.cs
2022-08-28 15:29:49 +03:00

40 lines
1.2 KiB
C#

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;
}
}
}