#nullable enable using System; using System.Collections.Generic; using UnityEngine; namespace Needle.Engine { public interface IReference { string Path { get; } object? Value { get; } Type? Type { get; } object? Owner { get; } string? Name { get; } } public interface IReferenceRegistry { } public interface IImportedTypeInfo { string TypeName { get; } string FilePath { get; } bool IsInstalled { get; } } public interface ITypeRegistry { bool IsKnownType(Type type); IReadOnlyList KnownTypes { get; } bool IsInstalled(Type type); bool TryGetImportedTypeInfo(Type type, out IImportedTypeInfo info); } public static class ITypeRegistryExtensions { private static readonly List buffer = new List(); public static IList? GetKnownComponents(this GameObject obj, ITypeRegistry reg) { buffer.Clear(); obj.GetComponents(buffer); reg.FilterKnown(buffer); if (buffer.Count > 0) { return new List(buffer); } return null; } public static IList FilterKnown(this ITypeRegistry reg, IList elements) where T : class { for (var i = elements.Count-1; i >= 0; i--) { var el = elements[i]; if (el == null || !reg.IsKnownType(el.GetType())) elements.RemoveAt(i); } return elements; } } }