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

相关推荐

  • vim下一页

    vim下一页整页翻页ctrl-fctrl-bf就是forwordb就是backward翻半页ctrl-dctlr-ud=downu=up滚一行ctrl-ectrl-yzz让光标所在的行居屏幕中央zt让光标所在的行居屏幕最上一行t=topzb让光标所在的行居屏幕最下一行b=bottomctrl+f(forward)往前翻一页ctrl+b(backward)往后翻一页ctrl+d(down)往前翻半页ctrl+u(up)往后翻半页zz让光标所在行.

    2022年5月5日
  • pycharm安装pandas「建议收藏」

    pycharm安装pandas「建议收藏」在控制台输入pipinstallpandas后出现Requirementalreadysatisfied之后按照下面的步骤安装就可以了。安装完成后importpandas就不会报错了。

    2022年8月25日
  • phpstorm2020激活码【2021最新】[通俗易懂]

    (phpstorm2020激活码)这是一篇idea技术相关文章,由全栈君为大家提供,主要知识点是关于2021JetBrains全家桶永久激活码的内容IntelliJ2021最新激活注册码,破解教程可免费永久激活,亲测有效,下面是详细链接哦~https://javaforall.net/100143.html00OE5RWT28-eyJsa…

    2022年3月30日
  • 2022年流动式起重机司机考试题库模拟考试平台操作「建议收藏」

    2022年流动式起重机司机考试题库模拟考试平台操作「建议收藏」题库来源:安全生产模拟考试一点通公众号小程序2022年流动式起重机司机特种作业证考试题库系流动式起重机司机考题的多种练习模式!2022年流动式起重机司机考试题库模拟考试平台操作根据流动式起重机司机考前押题。流动式起重机司机全部考试题库通过安全生产模拟考试一点通上错题练习。1、【多选题】《中华人民共和国特种设备安全法》规定,特种设备生产、经营、使用单位()被查封、扣押的特种设备或者其主要部件的,责令改正,处五万元以上二十万元以下罚款;情节严重的,吊销生产许可证,注销特种设备使用登记证书。(A..

    2022年9月6日
  • 在HTML中添加背景音乐[通俗易懂]

    在HTML中添加背景音乐[通俗易懂]方法一:在源代码中编写以下几句代码将能实现在HTML网页内添加背景音乐; 你的浏览器版本太低,不支持audi

    2022年7月25日
  • C++在使用Qt中SLOT宏须要注意的一个小细节

    C++在使用Qt中SLOT宏须要注意的一个小细节

    2021年11月23日

发表回复

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

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