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


相关推荐

  • vue 引入js文件中的方法,在html中使用报错的问题「建议收藏」

    vue 引入js文件中的方法,在html中使用报错的问题「建议收藏」1.创建了一个common.js2.引入到vue文件中3.在html使用它4.发现报错5.解决报错,只需要在methods中声明一下它

    2022年10月8日
  • python 二叉树中序遍历[通俗易懂]

    python 二叉树中序遍历[通俗易懂]根据树的递归性,使用List存储下面这棵树,然后编写函数对其进行中序遍历,最后删除节点D。递归实现中序遍历列表存储的二叉树python列表模拟二叉树存放,列表=[[左子树],根节点,[右子树]]列表里有列表,列表里又有列表。之前用treelist[1]==[]判断return,会有超限的问题。后来想了想,用列表长度判断是否return似乎是个不错的选择。d…

    2022年9月13日
  • linux下Mysql的简单操作

    linux下Mysql的简单操作linux下Mysql的简单操作

    2022年4月22日
  • linux服务器 Haproxy搭建Web集群环境实例

    linux服务器 Haproxy搭建Web集群环境实例

    2021年9月13日
  • UART和USART的区别(UART vs USART)[通俗易懂]

    UART和USART的区别(UART vs USART)[通俗易懂]很多工程师都知道UART和USART都是一样的,没有区别。但实际上,两者彼此不同,并且具有不同的属性。这就是我在这里写一篇文章UARTvsUSART的原因。但在研究UART和USART(UART与USART)之间的主要区别之前,我想先解释一下什么是异步和同步通信。异步串行传输:在异步通信中,发送方和接收方之间没有公共时钟。它广泛用于面向字节的传输,这意味着它一次可以发送1个字节或字符。与同步相比,异步通信速度较慢,并且还具有启动和停止位的开销。在异步通信中…

    2022年5月19日
  • docker开放2375端口,并添加安全传输层协议(TLS)和CA认证

    docker开放2375端口,并添加安全传输层协议(TLS)和CA认证为了更便捷地打包和部署,服务器需要开放2375端口才能连接docker,但如果开放了端口没有做任何安全保护,会引起安全漏洞,被人入侵、挖矿、CPU飙升这些情况都有发生,任何知道你IP的人,都可以管理这台主机上的容器和镜像,真的可怕。为了解决安全问题,只要使用安全传输层协议(TLS)进行传输并使用CA认证即可。制作证书及秘钥我们需要使用OpenSSL制作CA机构证书、服务端证书和客户端证书,以下操作均在安装Docker的Linux服务器上进行。创建一个目录用于存储生成的证书和秘钥mkdir

    2022年6月3日

发表回复

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

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