Odin Inspector 系列教程 — Dictionary Drawer Settings Attribute[通俗易懂]

Odin Inspector 系列教程 — Dictionary Drawer Settings Attribute[通俗易懂]DictionaryDrawerSettings自定义字典绘制方式默认以左侧为key,右侧为value的形式展示,如果需要进行序列化,需要继承自SerializedMonoBehaviour[DictionaryDrawerSettings()][ShowInInspector][InfoBox(“为了序列化字典,我们需要做…

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

Dictionary Drawer Settings 自定义字典绘制方式

7643202-a77c6a657ab1853a.png

默认以左侧为key,右侧为value 的形式展示,如果需要进行序列化,需要继承自SerializedMonoBehaviour
    [DictionaryDrawerSettings()]
    [ShowInInspector]
    [InfoBox("为了序列化字典,我们需要做的就是从SerializedMonoBehaviour继承类")]
    public Dictionary<int, Material> IntMaterialLookup = new Dictionary<int, Material>()
{
};
【KeyLabel和ValueLabel】自定义标签
7643202-041b4dbc98b338b8.png

    [ShowInInspector]
    [DictionaryDrawerSettings(KeyLabel = "自定义 Key 标签名称", ValueLabel = "自定义 Value 标签名称")]
    public Dictionary<SomeEnum, MyCustomType> CustomLabels = new Dictionary<SomeEnum, MyCustomType>()
{
    { SomeEnum.First, new MyCustomType() },
    { SomeEnum.Second, new MyCustomType() },
};
【DictionaryDisplayOptions】控制value默认以折叠还是展开形式显示
7643202-440505f1033e02be.png

    [InfoBox("默认是<color=green><size=15><b>Value折叠</b></size></color>方式打开,只在第一次生效")]
    [ShowInInspector]
    [DictionaryDrawerSettings(DisplayMode = DictionaryDisplayOptions.CollapsedFoldout)]
    public Dictionary<string, List<int>> StringListDictionary = new Dictionary<string, List<int>>()
{
    { "Numbers", new List<int>(){ 1, 2, 3, 4, } },
    { "Numbers1", new List<int>(){ 1, 2, 3, 4, } },
};

    [InfoBox("默认是<color=green><size=15><b>Value展开</b></size></color>方式打开,只在第一次生效")]
    [ShowInInspector]
    [DictionaryDrawerSettings(DisplayMode = DictionaryDisplayOptions.CollapsedFoldout)]
    public Dictionary<SomeEnum, MyCustomType> EnumObjectLookup = new Dictionary<SomeEnum, MyCustomType>()
{
    { SomeEnum.Third, new MyCustomType() },
    { SomeEnum.Fourth, new MyCustomType() },
};
完整示例代码
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class DictionaryDrawerSettingsExample : MonoBehaviour
{
    [DictionaryDrawerSettings()]
    [ShowInInspector]
    [InfoBox("为了序列化字典,我们需要做的就是从SerializedMonoBehaviour继承类")]
    public Dictionary<int, Material> IntMaterialLookup = new Dictionary<int, Material>()
{
};

    [ShowInInspector]
    [DictionaryDrawerSettings(KeyLabel = "自定义 Key 标签名称", ValueLabel = "自定义 Value 标签名称")]
    public Dictionary<SomeEnum, MyCustomType> CustomLabels = new Dictionary<SomeEnum, MyCustomType>()
{
    { SomeEnum.First, new MyCustomType() },
    { SomeEnum.Second, new MyCustomType() },
};

    [DictionaryDrawerSettings(DisplayMode = DictionaryDisplayOptions.Foldout)]
    [ShowInInspector]
    public Dictionary<string, string> StringStringDictionary = new Dictionary<string, string>()
{
    { "One", ExampleHelper.GetString() },
    { "Two", ExampleHelper.GetString() },
};

    [InfoBox("默认是<color=green><size=15><b>Value折叠</b></size></color>方式打开,只在第一次生效")]
    [ShowInInspector]
    [DictionaryDrawerSettings(DisplayMode = DictionaryDisplayOptions.CollapsedFoldout)]
    public Dictionary<string, List<int>> StringListDictionary = new Dictionary<string, List<int>>()
{
    { "Numbers", new List<int>(){ 1, 2, 3, 4, } },
    { "Numbers1", new List<int>(){ 1, 2, 3, 4, } },
};

    [InfoBox("默认是<color=green><size=15><b>Value展开</b></size></color>方式打开,只在第一次生效")]
    [ShowInInspector]
    [DictionaryDrawerSettings(DisplayMode = DictionaryDisplayOptions.CollapsedFoldout)]
    public Dictionary<SomeEnum, MyCustomType> EnumObjectLookup = new Dictionary<SomeEnum, MyCustomType>()
{
    { SomeEnum.Third, new MyCustomType() },
    { SomeEnum.Fourth, new MyCustomType() },
};



    [InlineProperty(LabelWidth = 100)]
    public struct MyCustomType
    {
        public int SomeMember;
        public GameObject SomePrefab;
    }

    public enum SomeEnum
    {
        First, Second, Third, Fourth, AndSoOn
    }
}

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

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

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

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


相关推荐

  • 51单片机按键控制步进电机加减速及正反转

    51单片机按键控制步进电机加减速及正反转之前尝试用单片机控制42步进电机正反转,电机连接导轨实现滑台前进后退,在这里分享一下测试程序及接线图,程序部分参考网上找到的,已经实际测试过,可以实现控制功能。所用硬件:步进电机及驱动器、STC89C52单片机、直流电源1、硬件连接图注意:上图为共阳极接法,实际连接参考总体线路连接。 驱动器信号端定义:PUL+:脉冲信号输入正。(C…

    2022年6月1日
    44
  • CentOS7 网络配置超详细ip、网关设置

    CentOS7 网络配置超详细ip、网关设置CentOS7网络配置一、在虚拟机中安装CentOS操作系统安装好虚拟机创建新的虚拟机,选择自定义(高级),点击下一步虚拟机硬件兼容性默认,浏览需要安装的CentOS6.5镜像文件自定义用户名和密码(用于登录)设置虚拟机名称和存储路径处理器设置默认(后面可以修改),内存设为1GB网络类型选择NAT模式选择创建新虚拟磁盘最大磁盘大小设为20GB,然后将虚拟磁盘存储为单个文件将创建好的磁盘文件存储在虚拟机指定目录下虚拟机创建完成二、虚拟网络配置编辑虚拟网络设置

    2022年6月14日
    81
  • springboot和springframework以及jdk版本的对应关系

    springboot和springframework以及jdk版本的对应关系Springboot版本 SpringFramework jdk版本 maven版本 1.2.0版本之前 6 3.0 1.2.0 4.1.3+ 6 3.2+ 1.2.1 4.1.3+ 7 3.2+ 1.2.3 4.1.5+ 7 3.2+ 1.3.4 4.2.6+ 7 3.2+ 1.3.6 4.2.7+ 7 3.2+ 1.3.7 4.2.

    2022年5月16日
    258
  • 数据库 之 关系模式范式

    数据库 之 关系模式范式主要有6种范式:第一范式(1NF),第二范式(2NF),第三范式(3NF),巴德斯科范式(BCNF),第四范式(4NF),第五范式(5NF),按从左至右的顺序一种比一种要求更严格。要符合某一种范式必须

    2022年7月1日
    25
  • 5G信道建模

    5G信道建模5G毫米波一般认为毫米波波段的信道具有稀疏性,即径数远小于天线数,因此直接在角度域上通过估计各条径的AoD/AoA和增益系数做信道估计,比起在天线域上做信道估计更简单。但这么做还隐含了每条可分辨径的角度扩展很小这样的假设,在mmWavemMIMO系统中,信道估计等同于估计AoA和AoD以及每条path的散射系数,就是毫米波波段的情况。而在低频NLoS情况下,由于散射传播路径非常丰富,信道不存在稀疏性,也没有一个清晰的几何结构,因此一般建模为随机的比如Rayleigh信道。对于这种信道我们就对其整体进行估

    2022年5月2日
    75
  • oracle中从指定日期中获取月份或者部分数据

    oracle中从指定日期中获取月份或者部分数据

    2022年2月1日
    50

发表回复

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

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