2024-07-16 Unity插件 Odin Inspector5 —— Conditional Attributes

文章目录

  • 1 说明
  • 2 条件特性
    • 2.1 DisableIf / EnableIf
    • 2.2 DisableIn / EnableIn / ShowIn / HideIn
    • 2.3 DisableInEditorMode / HideInEditorMode
    • 2.4 DisableInInlineEditors / ShowInInlineEditors / HideInInlineEditors
    • 2.5 DisableInPlayMode / HideInPlayMode
    • 2.6 ShowIf / HideIf
    • 2.7 ShowIfGroup / HideIfGroup

1 说明

​ 本文介绍 Odin Inspector 插件中条件特性的使用方法。

2 条件特性

2.1 DisableIf / EnableIf

如果解析的字符串计算结果为指定值,则禁用 / 启用 Inspector 窗口中的属性更改。

  • string condition

    检查值条件的解析字符串,如成员名称、表达式等。

  • object optionalValue

    要检查的值。

image-20240715225210588
// DisableIfExamplesComponent.csusing Sirenix.OdinInspector;
using UnityEngine;public class DisableIfExamplesComponent : MonoBehaviour
{public UnityEngine.Object SomeObject;[EnumToggleButtons]public InfoMessageType SomeEnum;public bool IsToggled;[DisableIf("SomeEnum", InfoMessageType.Info)]public Vector2 Info;[DisableIf("SomeEnum", InfoMessageType.Error)]public Vector2 Error;[DisableIf("SomeEnum", InfoMessageType.Warning)]public Vector2 Warning;[DisableIf("IsToggled")]public int DisableIfToggled;[DisableIf("SomeObject")]public Vector3 EnabledWhenNull;[DisableIf("@this.IsToggled && this.SomeObject != null || this.SomeEnum == InfoMessageType.Error")]public int DisableWithExpression;
}

2.2 DisableIn / EnableIn / ShowIn / HideIn

当该对象所在的脚本挂载在何种预制体上,其修饰的对象禁止 / 允许在 Inspector 窗口中的更改 / 显示。

  • PrefabKind prefabKind

    预制体的种类。

    1. None

      所有预制体,都不满足条件。

    2. InstanceInScene

      场景中的预制体实例。

    3. InstanceInPrefab

      嵌套在其他预制体中的预制件实例。

    4. Regular

      常规预制体。

    5. Variant

      预制体资产。

    6. NonPrefabInstance

      非预制体或场景中的游戏对象实例。

    7. PrefabInstance = InstanceInPrefab | InstanceInScene

      常规预制体的实例,以及场景中或嵌套在其他预制体中的预制体。

    8. PrefabAsset = Variant | Regular

      常规预制体和预制体资产。

    9. PrefabInstanceAndNonPrefabInstance = PrefabInstance | NonPrefabInstance

      预制体以及非预制实例。

    10. All = PrefabInstanceAndNonPrefabInstance | PrefabAsset

      所有预制体。

image-20240715231309872
using System.Collections;
using System.Collections.Generic;
using Sirenix.OdinInspector;
using UnityEngine;public class Test : MonoBehaviour
{[DisableIn(PrefabKind.PrefabAsset)]public int i;
}

2.3 DisableInEditorMode / HideInEditorMode

在不处于播放模式时禁用 / 隐藏对象。只希望在播放模式下可编辑 / 显示时,可使用此选项。

image-20240715233626355
// DisableInEditorModeExamplesComponent.csusing Sirenix.OdinInspector;
using UnityEngine;public class DisableInEditorModeExamplesComponent : MonoBehaviour
{[Title("Disabled in edit mode")][DisableInEditorMode]public GameObject A;[DisableInEditorMode]public Material B;
}

2.4 DisableInInlineEditors / ShowInInlineEditors / HideInInlineEditors

如果对象被 InlineEditor 特性绘制,则该对象在 Inspector 窗口中禁用更改 / 显示 / 隐藏。

补充 InlineEditor 特性:将继承 UnityEngine.Object 的类(如 ScriptableObject)的详细信息显示在 Inspector 窗口。

image-20240715234820556

​ 数据结构类:

using UnityEngine;#nullable disable
namespace Sirenix.OdinInspector.Editor.Examples
{public class DisabledInInlineEditorScriptableObject : ScriptableObject{public string AlwaysEnabled;[DisableInInlineEditors]public string DisabledInInlineEditor;}
}

​ 挂载的脚本:

// DisableInInlineEditorExampleComponent.csusing Sirenix.OdinInspector;
using UnityEngine;#if UNITY_EDITOR // Editor namespaces can only be used in the editor.
using Sirenix.OdinInspector.Editor.Examples;
#endifpublic class DisableInInlineEditorExampleComponent : MonoBehaviour
{
#if UNITY_EDITOR // DisabledInInlineEditorScriptableObject is an example type and only exists in the editor[InfoBox("Click the pen icon to open a new inspector window for the InlineObject too see the difference this attribute makes.")][InlineEditor(Expanded = true)]public DisabledInInlineEditorScriptableObject InlineObject;
#endif#if UNITY_EDITOR // Editor-related code must be excluded from builds[OnInspectorInit]private void CreateData() {InlineObject = ExampleHelper.GetScriptableObject<DisabledInInlineEditorScriptableObject>("Inline Object");}[OnInspectorDispose]private void CleanupData() {if (InlineObject != null) Object.DestroyImmediate(InlineObject);}
#endif
}

2.5 DisableInPlayMode / HideInPlayMode

在处于播放模式时禁用 / 隐藏对象。只希望在编辑模式下可编辑 / 显示时,可使用此选项。

image-20240715235402700
// DisableInPlayModeExamplesComponent.csusing Sirenix.OdinInspector;
using UnityEngine;public class DisableInPlayModeExamplesComponent : MonoBehaviour
{[Title("Disabled in play mode")][DisableInPlayMode]public int A;[DisableInPlayMode]public Material B;
}

2.6 ShowIf / HideIf

如果解析的字符串计算结果为指定值,则在 Inspector 窗口中显示 / 隐藏该对象。

  • string condition

    检查值条件的解析字符串,如成员名称、表达式等。

  • object optionalValue

    要检查的值。

  • bool animate = true

    状态改变时是否启用滑入和滑出动画显示。

image-20240715235942366
// ShowAndHideIfExamplesComponent.cs
using Sirenix.OdinInspector;
using UnityEngine;public class ShowAndHideIfExamplesComponent : MonoBehaviour
{// Note that you can also reference methods and properties or use @expressions. You are not limited to fields.public UnityEngine.Object SomeObject;[EnumToggleButtons]public InfoMessageType SomeEnum;public bool IsToggled;[ShowIf("SomeEnum", InfoMessageType.Info)]public Vector3 Info;[ShowIf("SomeEnum", InfoMessageType.Warning)]public Vector2 Warning;[ShowIf("SomeEnum", InfoMessageType.Error)]public Vector3 Error;[ShowIf("IsToggled")]public Vector2 VisibleWhenToggled;[HideIf("IsToggled")]public Vector3 HiddenWhenToggled;[HideIf("SomeObject")]public Vector3 ShowWhenNull;[ShowIf("SomeObject")]public Vector3 HideWhenNull;[EnableIf("@this.IsToggled && this.SomeObject != null || this.SomeEnum == InfoMessageType.Error")]public int ShowWithExpression;
}

2.7 ShowIfGroup / HideIfGroup

满足某个条件,则显示 / 隐藏指定组。

  • string path

    指定组的路径。

  • object value

    与路径末尾的标签重名的属性等于该值时,则满足条件。

  • bool animate = true

    状态改变时是否启用滑入和滑出动画显示。

image-20240716000503730
// HideIfGroupExampleComponent.csusing Sirenix.OdinInspector;
using UnityEngine;public class HideIfGroupExampleComponent : MonoBehaviour
{public bool Toggle = true;[HideIfGroup("Toggle")][BoxGroup("Toggle/Shown Box")]public int A, B;[BoxGroup("Box")]public InfoMessageType EnumField = InfoMessageType.Info;[BoxGroup("Box")][HideIfGroup("Box/Toggle")]public Vector3 X, Y;// Like the regular If-attributes, HideIfGroup also supports specifying values.// You can also chain multiple HideIfGroup attributes together for more complex behaviour.[HideIfGroup("Box/Toggle/EnumField", Value = InfoMessageType.Info)][BoxGroup("Box/Toggle/EnumField/Border", ShowLabel = false)]public string Name;[BoxGroup("Box/Toggle/EnumField/Border")]public Vector3 Vector;// HideIfGroup will by default use the name of the group,// but you can also use the MemberName property to override this.[HideIfGroup("RectGroup", Condition = "Toggle")]public Rect Rect;
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/bicheng/47392.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

目标检测入门:4.目标检测中的一阶段模型和两阶段模型

在前面几章里&#xff0c;都只做了目标检测中的目标定位任务&#xff0c;并未做目标分类任务。目标检测作为计算机视觉领域的核心人物之一&#xff0c;旨在从图像中识别出所有感兴趣的目标&#xff0c;并确定它们的类别和位置。现在目标检测以一阶段模型和两阶段模型为代表的。…

SpringBoot集成MQTT实现交互服务通信

引言 本文是springboot集成mqtt的一个实战案例。 gitee代码库地址&#xff1a;源码地址 一、什么是MQTT MQTT&#xff08;Message Queuing Telemetry Transport&#xff0c;消息队列遥测传输协议&#xff09;&#xff0c;是一种基于发布/订阅&#xff08;publish/subscribe&…

IDEA自带的Maven 3.9.x无法刷新http nexus私服

问题&#xff1a; 自建的私服&#xff0c;配置了域名&#xff0c;使用http协议&#xff0c;在IDEA中或本地Maven 3.9.x会出现报错&#xff0c;提示http被blocked&#xff0c;原因是Maven 3.8.1开始&#xff0c;Maven默认禁止使用HTTP仓库地址&#xff0c;只允许使用HTTPS仓库地…

【单片机毕业设计选题24069】-物联网节水灌溉系统设计

系统功能: 完成基于物联网的节水灌溉系统的电路图以及软件代码编写。要求系统可以通过传感器监测土壤的湿度和环境温湿度&#xff0c;如果土壤湿度低于限值和环境温湿度超过限值&#xff0c;则需开启继电器&#xff0c;打开电机水泵进行供水灌溉&#xff1b;当土壤湿度高于限值…

高数知识补充----矩阵、行列式、数学符号

矩阵计算 参考链接&#xff1a;矩阵如何运算&#xff1f;——线性代数_矩阵计算-CSDN博客 行列式计算 参考链接&#xff1a;实用的行列式计算方法 —— 线性代数&#xff08;det&#xff09;_det线性代数-CSDN博客 参考链接&#xff1a;行列式的计算方法(含四种&#xff0c;…

使用ETLCloud实现MySQL数据库与StarRocks数据库同步

在现代数据架构中&#xff0c;数据同步是保证数据一致性和分析准确性的关键步骤之一。本文将介绍如何利用ETLCloud技术实现MySQL数据库与StarRocks数仓数据库的高效数据同步&#xff0c;以及其在数据管理和分析中的重要性。 数据同步的重要性 在数据驱动的时代&#xff0c;企…

uniapp 解决scroll-view组件 refresher-triggered刷新无效

直接上代码 看代码注释 const isRefresh ref(false); //下拉刷新状态// 下拉刷新async function refresherpulling() {renderArr.value [];isRefresh.value true; // 先赋为true 调用完接口再设为falseawait reqData();isRefresh.value false; // 重置状态}下面是组件视图 …

OpenAI训练数据从哪里来、与苹果合作进展如何?“ChatGPT之母”最新回应

7月9日&#xff0c;美国约翰霍普金斯大学公布了对“ChatGPT之母”、OpenAI首席技术官米拉穆拉蒂&#xff08;Mira Murati&#xff09;的采访视频。这场采访时间是6月10日&#xff0c;访谈中&#xff0c;穆拉蒂不仅与主持人讨论了OpenAI与Apple的合作伙伴关系&#xff0c;还深入…

Apache Omid TSO 组件源码实现原理

Apache Omid TSO 组件实现原理 作用 独立进程&#xff0c;处理全局事务之间的并发冲突。 流程 TSOChannelHandler#channelRead -> AbstractRequestProcessor -> PersistenceProcessorHandler 总体流程 thread1TSOChannelHandler#channelReadAbstractRequestProcess…

智能边缘计算网关:实现工业自动化与数据处理的融合-天拓四方

随着物联网&#xff08;IoT&#xff09;技术的迅速发展和普及&#xff0c;越来越多的设备被连接到互联网上&#xff0c;产生了海量的数据。如何有效地处理和分析这些数据&#xff0c;同时确保数据的安全性和实时性&#xff0c;成为了摆在企业面前的一大挑战。智能边缘计算网关作…

广联达Linkworks ArchiveWebService XML实体注入漏洞复现

0x01 产品简介 广联达 LinkWorks(也称为 GlinkLink 或 GTP-LinkWorks)是广联达公司(Glodon)开发的一种BIM(建筑信息模型)协同平台。广联达是中国领先的数字建造技术提供商之一,专注于为建筑、工程和建筑设计行业提供数字化解决方案。 0x02 漏洞概述 广联达 LinkWorks…

在VScode中编译C程序

一&#xff0c;安装 VS Code 下载并安装VS code&#xff0c;安装简体中文和C/C插件。略。 二&#xff0c;配置gcc环境 下载并安装MinGW。添加环境变量。略。 在cmd中输入 gcc -v 能打印版本即可。 三&#xff0c;打开文件夹&#xff0c;创建工作区 1&#xff0c;打开文件夹…

数据库系统概论:数据库系统模式

数据库系统在我们的数字世界中扮演着至关重要的角色&#xff0c;无论是个人设备还是企业级应用&#xff0c;数据的有效管理和访问都是必不可少的。而数据库系统的模式结构是确保数据一致性和可访问性的关键组成部分。 数据库系统模式 基本概念 型和值 数据模型中有 型(type…

游戏中的敏感词算法初探

在游戏中起名和聊天需要服务器判断是否含有敏感词&#xff0c;从而拒绝或屏蔽敏感词显示&#xff0c;这里枚举一些常用的算法和实际效果。 1.字符串匹配算法 常用的有KMP&#xff0c;核心就是预处理出next数组&#xff0c;也就是失配信息&#xff0c;时间复杂度在O(mn) 。还有个…

微软研究人员为电子表格应用开发了专用人工智能LLM

微软的 Copilot 生成式人工智能助手现已成为该公司许多软件应用程序的一部分。其中包括 Excel 电子表格应用程序&#xff0c;用户可以在其中输入文本提示来帮助处理某些选项。微软的一组研究人员一直在研究一种新的人工智能大型语言模型&#xff0c;这种模型是专门为 Excel、Go…

Transformer系列专题(四)——Swintransformer

文章目录 九、SwinTransformer9.1 整体网络架构9.2 Transformer Blocks9.3 Patch Embedding&#xff08;将图像切割成小块&#xff08;Patch&#xff09;&#xff09;9.4 window_partition9.5 W-MSA&#xff08;Window Multi-head Self Attention&#xff09;9.6 window_revers…

Redis-应用

目录 应用 缓存雪崩、击穿、穿透和解决办法? 布隆过滤器是怎么工作的? 缓存的数据一致性怎么保证 Redis和Mysql消息一致性 业务一致性要求高怎么办? 数据库与缓存的一致性问题 数据库和缓存的一致性如何保证 如何保证本地缓存和分布式缓存的一致&#xff1f; 如果在…

【Pytorch】一文向您详细介绍 `tensor.max(1, keepdims=True)`

【&#x1f525;Pytorch】一文向您详细介绍 tensor.max(1, keepdimsTrue) 下滑即可查看博客内容 &#x1f308; 欢迎莅临我的个人主页 &#x1f448;这里是我静心耕耘深度学习领域、真诚分享知识与智慧的小天地&#xff01;&#x1f387; &#x1f393; 博主简介&#xff…

(一)原生js案例之图片轮播

原生js实现的两种播放效果 效果一 循环播放&#xff0c;单一的效果 代码实现 <!DOCTYPE html> <html lang"en"> <head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-sc…

昇思学习打卡-20-生成式/GAN图像生成

文章目录 网络介绍生成器和判别器的博弈过程数据集可视化模型细节训练过程网络优缺点优点缺点 网络介绍 GAN通过设计生成模型和判别模型这两个模块&#xff0c;使其互相博弈学习产生了相当好的输出。 GAN模型的核心在于提出了通过对抗过程来估计生成模型这一全新框架。在这个…