Odin Inspector 系列教程 — SearchableAttribute「建议收藏」

Odin Inspector 系列教程 — SearchableAttribute「建议收藏」通过添加SearchableAttribute特性为其添加一个搜索框,可用于搜索对应的类或其子类的成员,但目前不可用于字典类型。imageusingSirenix.OdinInspector;usingSystem;usingSystem.Collections.Generic;usingUnityEngine;publicclassSearchableExam…

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

通过添加SearchableAttribute特性为其添加一个搜索框,可用于搜索对应的类或其子类的成员,但目前不可用于字典类型。
Odin Inspector 系列教程 --- SearchableAttribute「建议收藏」

image

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

public class SearchableExample_0 : MonoBehaviour
{
    [Searchable]
    public List<Perk> Perks = new List<Perk>()
{
    new Perk()
    {
        Name = "Old Sage",
        Effects = new List<Effect>()
        {
            new Effect() { Skill = Skill.Wisdom, Value = 2, },
            new Effect() { Skill = Skill.Intelligence, Value = 1, },
            new Effect() { Skill = Skill.Strength, Value = -2 },
        },
    },
    new Perk()
    {
        Name = "Hardened Criminal",
        Effects = new List<Effect>()
        {
            new Effect() { Skill = Skill.Dexterity, Value = 2, },
            new Effect() { Skill = Skill.Strength, Value = 1, },
            new Effect() { Skill = Skill.Charisma, Value = -2 },
        },
    },
    new Perk()
    {
        Name = "Born Leader",
        Effects = new List<Effect>()
        {
            new Effect() { Skill = Skill.Charisma, Value = 2, },
            new Effect() { Skill = Skill.Intelligence, Value = -3 },
        },
    },
    new Perk()
    {
        Name = "Village Idiot",
        Effects = new List<Effect>()
        {
            new Effect() { Skill = Skill.Charisma, Value = 4, },
            new Effect() { Skill = Skill.Constitution, Value = 2, },
            new Effect() { Skill = Skill.Intelligence, Value = -3 },
            new Effect() { Skill = Skill.Wisdom, Value = -3 },
        },
    },
};

    [Serializable]
    public class Perk
    {
        public string Name;

        [TableList]
        public List<Effect> Effects;
    }

    [Serializable]
    public class Effect
    {
        public Skill Skill;
        public float Value;
    }

    public enum Skill
    {
        Strength,
        Dexterity,
        Constitution,
        Intelligence,
        Wisdom,
        Charisma,
    }
}

放置在类顶进行全局搜索

Odin Inspector 系列教程 --- SearchableAttribute「建议收藏」

image

using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor.Examples;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

[Searchable]
public class SearchableExample_1 : MonoBehaviour
{
    public List<string> strings = new List<string>(Enumerable.Range(1, 10).Select(i => "Str Element " + i));

    public List<ExampleStruct> searchableList = new List<ExampleStruct>(Enumerable.Range(1, 10).Select(i => new ExampleStruct(i)));

    [Serializable]
    public struct ExampleStruct
    {
        public string Name;
        public int Number;
        public ExampleEnum Enum;

        public ExampleStruct(int nr) : this()
        {
            this.Name = "Element " + nr;
            this.Number = nr;
            this.Enum = (ExampleEnum)ExampleHelper.RandomInt(0, 5);
        }
    }

    public enum ExampleEnum
    {
        One, Two, Three, Four, Five
    }
}

Searchable应用到对应的类型上后,使用对应的类型都会出现搜索栏,也可以通过 ISearchFilterable接口自定义搜索规则

Odin Inspector 系列教程 --- SearchableAttribute「建议收藏」

image

using Sirenix.OdinInspector;
using Sirenix.OdinInspector.Editor.Examples;
using System;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;

public class SearchableExample_2 : MonoBehaviour
{
    [Searchable]
    public ExampleClass searchableClass = new ExampleClass();

    [Searchable]
    public List<ExampleStruct> searchableList = new List<ExampleStruct>(Enumerable.Range(1, 10).Select(i => new ExampleStruct(i)));

    [Searchable(FilterOptions = SearchFilterOptions.ISearchFilterableInterface)]
    public List<FilterableBySquareStruct> customFiltering = new List<FilterableBySquareStruct>(Enumerable.Range(1, 10).Select(i => new FilterableBySquareStruct(i)));

    [Serializable]
    public class ExampleClass
    {
        public string SomeString = "Saehrimnir is a tasty delicacy";
        public int SomeInt = 13579;

        public DataContainer DataContainerOne = new DataContainer() { Name = "Example Data Set One" };
        public DataContainer DataContainerTwo = new DataContainer() { Name = "Example Data Set Two" };
    }

    [Serializable, Searchable] // You can also apply it on a type like this, and it will become searchable wherever it appears
    public class DataContainer
    {
        public string Name;
        public List<ExampleStruct> Data = new List<ExampleStruct>(Enumerable.Range(1, 10).Select(i => new ExampleStruct(i)));
    }

    [Serializable]
    public struct FilterableBySquareStruct : ISearchFilterable
    {
        public int Number;

        [ShowInInspector, DisplayAsString, EnableGUI]
        public int Square { get { return this.Number * this.Number; } }

        public FilterableBySquareStruct(int nr)
        {
            this.Number = nr;
        }

        public bool IsMatch(string searchString)
        {
            return searchString.Contains(Square.ToString());
        }
    }

    [Serializable]
    public struct ExampleStruct
    {
        public string Name;
        public int Number;
        public ExampleEnum Enum;

        public ExampleStruct(int nr) : this()
        {
            this.Name = "Element " + nr;
            this.Number = nr;

            this.Enum = (ExampleEnum)ExampleHelper.RandomInt(0, 5);
        }
    }

    public enum ExampleEnum
    {
        One, Two, Three, Four, Five
    }
}

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

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

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

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


相关推荐

  • NetSetMan Pro(ip快速切换工具)官方中文版V5.1.0 | 电脑ip切换软件下载

    NetSetMan Pro(ip快速切换工具)官方中文版V5.1.0 | 电脑ip切换软件下载NetSetManPro是一款短小精悍且方便实用的网络ip快速切换工具,界面简洁易于使用,可以轻松地在用户的预配置配置文件之间切换,可以设置六组不同的网络参数值,一目了然地管理所有网络设置,预先设置好一切,让使用者可以针对不同的网络环境,而调用不同的参数,可以快速设置计算机IP地址、子网掩码、默认网关、DNS、计算机名、DNS域、工作组、WINS、打印机等,如果大家需要一款电脑ip切换软件的话,威航软件园认为NetSetManPro是一个不错的选择哦。

    2025年7月9日
    2
  • exit与return的区别

    exit与return的区别

    2021年11月3日
    56
  • linux fusion io简介,linux – 收集FusionIO库存

    linux fusion io简介,linux – 收集FusionIO库存我需要编写一个脚本,从Linux服务器收集FusionIO驱动器的库存数据.我能找到的唯一方法是fio-status实用程序,但它的目的是输出人类可读的文本,而不是机器可解析的文本.我可以刮它,但那很脏.我检查/proc/fusion但它没有足够的信息可供任何使用.我希望有更好的方法,可以通过某种方式与libiodrivesdk.so或已经存在的实用程序进行交互来完成这项工作.我最初使用的是…

    2025年8月21日
    2
  • ArrayList扩容机制JDK1.8

    ArrayList扩容机制JDK1.8本题的所有的讲解都是基于JDK8这道题考察了ArrayList的构造器和对扩容机制的了解,本篇博客基于此出发讲解ArrayList的扩容机制想要做出这道题必须了解ArrayList的构造函数,ArrayList的构造函数总共有三个:ArrayList()构造一个空的数组。JDK7中构造一个初始容量为10的空列表但是JDK8中只是构造一个空的数组ArrayList(Collection<?extendsE>c)构造一个包含指定collection的元素的数组,这些元素是按.

    2022年6月9日
    27
  • datagrid激活码(破解版激活)「建议收藏」

    datagrid激活码(破解版激活),https://javaforall.net/100143.html。详细ieda激活码不妨到全栈程序员必看教程网一起来了解一下吧!

    2022年3月16日
    50
  • pycharm qt designer_pycharm怎么运行py文件

    pycharm qt designer_pycharm怎么运行py文件pycharm集成QTdesigner+ui转py工具前言一、前期安装二、pycharm配置QTdesigner1.外部工具配置2.pycharm可直接调用designer三、pycharm配置pyuic(将ui文件转换为py文件)1.外部工具配置2.pycharm可直接调用pyuic工具四、显示代码和逻辑代码分离1.使用designer设计示意界面总结前言后面使用PyQt5开始设计界面、使用pycharm这个IDE进行逻辑代码和界面代码的融合。一、前期安装前提:按照《PythonGUI.

    2022年8月29日
    2

发表回复

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

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