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 系列教程

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

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

【正版授权,激活自己账号】: Jetbrains全家桶Ide使用,1年售后保障,每天仅需1毛

【官方授权 正版激活】: 官方授权 正版激活 支持Jetbrains家族下所有IDE 使用个人JB账号...

(0)
blank

相关推荐

  • 图形推理1000题pdf_数字推理题,眼尖的一眼就看出来了「建议收藏」

    图形推理1000题pdf_数字推理题,眼尖的一眼就看出来了「建议收藏」动脑往期回看>>每日推理每日推理|你能找出犯人吗?每日推理|你是哪个班的?每日推理|拿掉2根木棍,使其变成3个正方形每日推理|共同营业日每日推理|千里寻一每日推理|坏掉的8号电话亭每日推理|哪两个才是兄弟?每日推理|白马王子每日推理|神奇海螺脑筋急转弯答案笑死人的脑筋急转弯看了想打人的题目移动火柴游戏复杂的迷宫图形推理5道很难的字谜△点击…

  • BaseAdapter导致notifyDataSetChanged()无效的四个原因及处理方法

    BaseAdapter导致notifyDataSetChanged()无效的四个原因及处理方法前一段时间在做一个项目的时候遇到了一个关于BaseAdapter的notifyDataSetChanged()方法无效问题,当时在网上搜了一个解决方法,今天又遇到了一个类似的问题,我在这里做个记录,防止以后再次发生,或者其他朋友再次遇到。一、ScrollView中嵌套ListView或GridView原因:两个的滚动监听冲突解决方法:重写ListView或GridViewpackagecom.m

  • Spring Boot第八章-Spring Data JPA(续)

    Spring Boot第八章-Spring Data JPA(续)

  • 8421 BCD码 加减校正[通俗易懂]

    8421 BCD码 加减校正[通俗易懂]8421码是一种常见的BCD(Binary-CodedDecimal)码,它用4个二进制位表示1个十进制位:00000001001000110100010101100111100010011010…11110123456789x…x例如:我们要表示5和15,使用二进制编码5 -101 15 -1111…

    2022年10月28日
  • linux tar 解压命令总结

    linux tar 解压命令总结把常用的tar解压命令总结下,当作备忘:tar-c:建立压缩档案-x:解压-t:查看内容-r:向压缩归档文件末尾追加文件-u:更新原压缩包中的文件这五个是独立的命令,压缩解压都要用到其中一个,可以和别的命令连用但只能用其中一个。下面的参数是根据需要在压缩或解压档案时可选的。-z:有gzip属性的-j:有bz2属性的-Z:有compress属性的

  • 解决修改JAVAHOME后java版本不改变问题[通俗易懂]

    网上有很多解决的方法,其中删除C:\Windows\System32文件下java相关联的exe文件即可,使用wherejava命令可以发现,在Javahome配置版本之前有两个或三个java可执行文件,因此删除这个干扰项就可以解决。java版本问题unsupportedmajor.minorversion51.0jdk1.7版本错误,可能项目是1.7,运行环境是1.6unsup…

发表回复

您的电子邮箱地址不会被公开。

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