in SupportingScripts/Editor/Scripts/TileLayerListDrawer.cs [147:199]
private void GetValidTileLayerComponents(
SerializedProperty existingTypeList,
out List<Type> types,
out string[] typeNames)
{
// First, use Unity's "Unsupported" API to get a list of all valid Component types. The commands return only IDs of the
// Components that are valid, i.e. are in a script with the correct corresponding filename, or come from an assembly. If
// we were to rely only on reflected Types it's possible to get MonoBehaviors that are invalid to add from the Editor due
// to not following these constraints. Filter to the ones which are just TileLayers...
var commands = Unsupported.GetSubmenusCommands("Component");
types = new List<Type>();
for (var i = 0; i < commands.Length; i++)
{
var command = commands[i];
if (command.StartsWith("SCRIPT"))
{
var scriptIdString = command.Substring(6);
if (int.TryParse(scriptIdString, out var scriptId))
{
var script = EditorUtility.InstanceIDToObject(scriptId);
if (script is MonoScript monoScript)
{
var type = monoScript.GetClass();
if (type != null && type.IsSubclassOf(typeof(TLayer)))
{
types.Add(type);
}
}
}
}
}
// Remove any types that are already in the list and have the DisallowMultipleComponent on them.
for (var i = 0; i < existingTypeList.arraySize; ++i)
{
var objectReferenceValue = existingTypeList.GetArrayElementAtIndex(i).objectReferenceValue;
if (objectReferenceValue != null)
{
var elementType = objectReferenceValue.GetType();
if (elementType.GetCustomAttributes(typeof(DisallowMultipleComponent), true).Length > 0)
{
types.RemoveAll(type => type == elementType);
}
}
}
// Build a list of the simple type name for display.
typeNames = new string[types.Count];
for (var i = 0; i < types.Count; ++i)
{
typeNames[i] = types[i].Name;
}
}