DisallowChildObjects

Attribute: [AttributeUsage(AttributeTargets.Field | AttributeTargets.Property)] public class DisallowChildObjectsAttribute : Attribute { }

Drawer [OdinDrawer] [DrawerPriority(DrawerPriorityLevel.WrapperPriority)] public class DisallowChildObjectsAttributeDrawe : OdinAttributeDrawer    where T : UnityEngine.Object {    public override bool CanDrawTypeFilter(Type type) {        return type.InheritsFrom || type == typeof(GameObject); }    private class Context {        public string ErrorMessage; }    protected override void DrawPropertyLayout(IPropertyValueEntry entry, DisallowChildObjectsAttribute attribute, GUIContent label) {        var context = entry.Property.Context.Get(this, "isValid", (Context)null); if (context.Value == null) {            context.Value = new Context; entry.OnValueChanged += i => Validate(entry, context.Value); Validate(entry, context.Value); }        if (context.Value.ErrorMessage != null) {            SirenixEditorGUI.ErrorMessageBox(context.Value.ErrorMessage); }        this.CallNextDrawer(entry, label); }    private static void Validate(IPropertyValueEntry entry, Context context) {        context.ErrorMessage = null; var targets = entry.Property.Tree.WeakTargets; var values = entry.WeakValues; for (int i = 0; i < targets.Count; i++) {            // Multiselection var target = targets[i] as Behaviour; var value = entry.Values[i]; if (target == null) {                break; }            if (value == null) {                continue; }            var go = value as GameObject; if (go == null) {                var behaviour = value as Behaviour; if (behaviour) {                    go = behaviour.gameObject; }            }             if (go == null) {                continue; }            if (target.GetComponentsInChildren(typeof(Transform)).Contains(go.transform)) {                context.ErrorMessage = "Child objects are not allowed."; break; }        }     } }

Usage: public class SomeMonoBehaviour : MonoBehaviour {    [DisallowChildObjects] public List Test1; [DisallowChildObjects] public List Test2; }