Odin Inspector 系列教程 — Type Filter Attribute

Odin Inspector 系列教程 — Type Filter AttributeTypeFilterAttribute特性:对输入的value进行自定义过滤,只显示需要的类型完整示例代码usingSirenix.OdinInspector;usingSirenix.Utilities;usingSystem;usingSystem.Collections.Generic;usingSystem.Linq;usin…

大家好,又见面了,我是你们的朋友全栈君。

Type Filter Attribute特性:对输入的value 进行自定义过滤,只显示需要的类型

7643202-82b1adbff518e404.png

完整示例代码

using Sirenix.OdinInspector;
using Sirenix.Utilities;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class TypeFilterExample : MonoBehaviour
{
    [ShowInInspector]
    [TypeFilter("GetFilteredTypeList")]
    public BaseClass A, B;

    [ShowInInspector]
    [TypeFilter("GetFilteredTypeList")]
    public BaseClass[] Array = new BaseClass[3];

    public IEnumerable<Type> GetFilteredTypeList()
    {
        var q = typeof(BaseClass).Assembly.GetTypes()
            .Where(x => !x.IsAbstract)                                          // 不包括 BaseClass
            .Where(x => !x.IsGenericTypeDefinition)                             // 不包括 C1<>
            .Where(x => typeof(BaseClass).IsAssignableFrom(x));                 // 排除不从BaseClass继承的类 

        // Adds various C1<T> type variants.
        q = q.AppendWith(typeof(C1<>).MakeGenericType(typeof(GameObject))); //添加C1泛型为GameObject 的value
        q = q.AppendWith(typeof(C1<>).MakeGenericType(typeof(AnimationCurve)));//添加C1泛型为AnimationCurve 的value
        q = q.AppendWith(typeof(C1<>).MakeGenericType(typeof(List<float>)));//添加C1泛型为List<float> 的value

        return q;
    }

    public abstract class BaseClass
    {
        public int BaseField;
    }

    public class A1 : BaseClass { public int _A1; }
    public class A2 : A1 { public int _A2; }
    public class A3 : A2 { public int _A3; }
    public class B1 : BaseClass { public int _B1; }
    public class B2 : B1 { public int _B2; }
    public class B3 : B2 { public int _B3; }
    public class C1<T> : BaseClass { public T C; }
}

更多教程内容详见:革命性Unity 编辑器扩展工具 — Odin Inspector 系列教程

版权声明:本文内容由互联网用户自发贡献,该文观点仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请联系我们举报,一经查实,本站将立刻删除。

发布者:全栈程序员-站长,转载请注明出处:https://javaforall.net/162838.html原文链接:https://javaforall.net

(0)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • Vmware安装win10的失败总结

    Vmware安装win10的失败总结下了番茄,萝卜,深度等多个win10镜像均出现各种莫名其妙的小问题,还是linux大法好哇~~失败一:          未手动分区,许久不装windows系统了,忘记了手动分区,用镜像里自带的分区工具,如diskgenius等分区后安装失败二:          分区后需进入bios设置优先从光盘启动的模式失败三:          找不到ghost文件,进入winPE手动查找光盘里…

    2022年6月22日
    276
  • SQL语句distinct的多个字段去重问题

    SQL语句distinct的多个字段去重问题经典例子selectdistinctname,idfromtable或者selectname,idfromtablegroupbyname像这样是错误的写法,distinct不起作用的曲线救国写法:selectname,idfromtablewhereidin(selectmin(id)fromtablegrou……

    2022年10月22日
    1
  • 业务测试用例模版与大数据测试用例模板

    业务测试用例模版与大数据测试用例模板前言:分享下业务测试用例模版与大数据测试用例模板业务测试用例模版与大数据测试用例模板一、业务测试用例模板二、业务测试用例模板一、业务测试用例模板需要下载模板请点击:业务测试用例模板下载二、业务测试用例模板需要下载模板请点击:大数据测试用例模板下载…

    2022年7月17日
    14
  • sqlserver2012密钥激活(server2012r2密钥)

    MicrosoftSQLServer2008R2序列号密钥 开发版32位:MC46H-JQR3C-2JRHY-XYRKY-QWPVM 开发版64位:FTMGC-B2J97-PJ4QG-V84YB-MTXX8 工组版:XQ4CB-VK9P3-4WYYH-4HQX3-K2R6Q WEB版:FP4P7-YKG22-WGRVK-MKGMX-V9MTM 数…

    2022年4月18日
    1.9K
  • 关于CommandType.StoredProcedure输出参数访问问题

    关于CommandType.StoredProcedure输出参数访问问题MSDN解释:当您将 Command 对象用于存储过程时,可以将 Command 对象的 CommandType 属性设置为 StoredProcedure。当 CommandType 为 StoredProcedure 时,可以使用 Command 的 Parameters 属性来访问输入及输出参数和返回值。无论调用哪一个 Execute 方法,都可以访问 Parameters 属性。但是,

    2022年7月26日
    6
  • cocos creator 部署微信云开发

    cocos creator 部署微信云开发cocoscreator部署微信云开发

    2025年7月17日
    0

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注

关注全栈程序员社区公众号