1.8.4: Added PopupFromScriptableObjectType

This commit is contained in:
Anders Ejlersen 2023-12-09 22:38:27 +01:00
parent 3259b62387
commit 81906d49dd
12 changed files with 202 additions and 1 deletions

View file

@ -7,6 +7,7 @@ namespace Module.Inspector.Editor.Utilities
{
private static GUIContent CONTENT_WARNING;
private static GUIContent CONTENT_ERROR;
private static GUIContent CONTENT_OBJECT;
private static GUIContent GetWarningIconContent()
{
@ -23,6 +24,14 @@ namespace Module.Inspector.Editor.Utilities
return CONTENT_ERROR;
}
public static GUIContent GetScriptableObjectIconContent()
{
if (CONTENT_ERROR == null)
CONTENT_ERROR = EditorGUIUtility.IconContent("d_ScriptableObject Icon");
return CONTENT_ERROR;
}
public static void SetWarningIcon(GUIContent content)
{

View file

@ -0,0 +1,59 @@
using System;
using System.Collections.Generic;
using UnityEditor;
using UnityEngine;
using Object = UnityEngine.Object;
namespace Module.Inspector.Editor
{
internal static class EditorUtilitySearchObject
{
private static readonly Dictionary<Type, SearchObject> TYPE_TO_ASSETS = new();
public static SearchObject SearchAndCache(Type type)
{
if (TYPE_TO_ASSETS.TryGetValue(type, out SearchObject searchObject))
return searchObject;
string[] guids = AssetDatabase.FindAssets($"t:{type.Name}");
searchObject = new();
for (var i = 0; i < guids.Length; i++)
{
string path = AssetDatabase.GUIDToAssetPath(guids[i]);
Object asset = AssetDatabase.LoadAssetAtPath(path, type);
if (asset != null)
searchObject.assets.Add(asset);
}
searchObject.CreateNamesFromAssets();
TYPE_TO_ASSETS.Add(type, searchObject);
return searchObject;
}
public static void Clear()
{
TYPE_TO_ASSETS.Clear();
}
public sealed class SearchObject
{
public readonly List<Object> assets = new();
public GUIContent[] names;
public void CreateNamesFromAssets()
{
assets.Sort((a0, a1) => string.Compare(a0.name, a1.name, StringComparison.Ordinal));
names = new GUIContent[assets.Count + 1];
names[0] = new GUIContent("None");
for (var i = 0; i < assets.Count; i++)
{
names[i + 1] = new GUIContent(assets[i].name);
}
}
}
}
}

View file

@ -0,0 +1,3 @@
fileFormatVersion: 2
guid: 8083be0f988541b294da46beca2224d9
timeCreated: 1702156783