Gameplay Ingredients是一组用于 Unity 游戏的运行时和编辑器工具:一组脚本的集合,可在制作游戏和原型时简化简单的任务。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

54 行
1.6 KiB

using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEditor;
namespace GameplayIngredients.Editor
{
[CustomPropertyDrawer(typeof(ExcludedManagerAttribute))]
public class ExcludedManagerPropertyDrawer : PropertyDrawer
{
List<string> cachedTypes;
bool needRecache = true;
public override void OnGUI(Rect position, SerializedProperty property, GUIContent label)
{
if (cachedTypes == null || needRecache)
cachedTypes = CacheTypes();
string curValue = property.stringValue;
int index = cachedTypes.IndexOf(curValue);
EditorGUI.BeginChangeCheck();
int newIndex = EditorGUI.Popup(position, index, cachedTypes.ToArray());
if (EditorGUI.EndChangeCheck() && index != newIndex)
{
property.stringValue = cachedTypes[newIndex];
needRecache = true;
}
}
List<string> CacheTypes()
{
var types = new List<string>();
foreach(var assembly in AppDomain.CurrentDomain.GetAssemblies())
{
foreach(var type in assembly.GetTypes())
{
if(typeof(Manager).IsAssignableFrom(type)
&& !type.IsAbstract
&& !type.CustomAttributes.Any(o => o.AttributeType == typeof(NonExcludeableManager)))
{
types.Add(type.Name);
}
}
}
needRecache = false;
return types;
}
}
}