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)
全栈程序员-站长的头像全栈程序员-站长


相关推荐

  • 前后端分离 vue spring boot_springbootvue集成

    前后端分离 vue spring boot_springbootvue集成源码链接:https://pan.baidu.com/s/1E0e72K6P3_xtkFscL6iEtQ提取码:t2te一、环境、工具jdk1.8mavenspring-bootideaVSVodevue二、搭建后台spring-boot框架步骤:1、new-project选择SpringInitializrnext2、创建项目文件结构以…

    2022年8月22日
    9
  • String字符串操作之截取

    String字符串操作之截取1、截取字符串substring1.1、java中截取publicstaticvoidmain(String[]args){//uuid获取,importjava.util.UUID;Stringuuid36=UUID.randomUUID().toString();System.out.println(uuid36);////565a58bc-d87a-411d-8a09-e7c3ef28dc4bSt

    2022年5月19日
    64
  • Java volatile关键字作用[通俗易懂]

    Java volatile关键字作用[通俗易懂]当一个共享变量被volatile修饰时,它会保证修改的值立即被更新到主存“,这里的”保证“是如何做到的?和JIT的具体编译后的CPU指令相关吧?  volatile特性  内存可见性:通俗来说就是,线程A对一个volatile变量的修改,对于其它线程来说是可见的,即线程每次获取volatile变量的值都是最新的。  volatile的使用场景  通过关键字sychronize…

    2022年6月1日
    27
  • dubbo 异步调用

    dubbo 异步调用dubbo异步调用使用总结

    2022年7月11日
    21
  • 判断 iPhone 是否插入了 SIM 卡

    判断 iPhone 是否插入了 SIM 卡判断iPhone是否插入了SIM卡,可以参考苹果官网的systemconfigureframework教程,将下面的代码复制到头文件externNSString*constkCTSMSMessageReceivedNotification;externNSString*constkCTSMSMessageReplaceReceivedNotificat…

    2022年5月13日
    93
  • mysql econnreset_MySQL在node.js服务器上的空闲时间后给出“ read ECONNRESET”错误「建议收藏」

    mysql econnreset_MySQL在node.js服务器上的空闲时间后给出“ read ECONNRESET”错误「建议收藏」我正在运行通过node-mysql模块连接到MySQL的Node服务器。连接和查询MySQL最初运行良好,没有任何错误,但是,将Node服务器闲置几个小时后的第一个查询会导致错误。错误是熟悉的readECONNRESET,来自node-mysql模块的内部。堆栈跟踪(请注意,跟踪的三个条目属于我的应用程序的错误报告代码):Erroratexports.Error.utils.createClas…

    2022年6月17日
    32

发表回复

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

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