Hide If Attribute 用于任何屬性伤溉,并且可以在檢查器中隱藏該屬性匙监。使用此選項(xiàng)可根據(jù)對象的當(dāng)前狀態(tài)隱藏不相關(guān)的屬性晦溪。
傳一個(gè)屬性的名稱规阀,此屬性的值如果為true或者部位null,則隱藏此屬性
[HideIf("IsToggled")]
public Vector3 HiddenWhenToggled;
[HideIf("SomeObject")]
public Vector3 ShowWhenNull;
傳入一個(gè)選項(xiàng)值(第二個(gè)參數(shù))紊选,作為與第一個(gè)參數(shù)指定的屬性拼配啼止,如果一致,則隱藏屬性
[HideIf("SomeEnum", InfoMessageType.Info)]
public Vector3 Info;
使用@轉(zhuǎn)義符傳入表達(dá)式
[HideIf("@this.IsToggled && this.SomeObject != null")]
public int HideWithExpression;
完整示例代碼
using Sirenix.OdinInspector;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class HideIfAttributeExample : MonoBehaviour
{
public UnityEngine.Object SomeObject;
[EnumToggleButtons]
public InfoMessageType SomeEnum;
public bool IsToggled;
[HideIf("SomeEnum", InfoMessageType.Info)]
public Vector3 Info;
[HideIf("IsToggled")]
public Vector3 HiddenWhenToggled;
[HideIf("SomeObject")]
public Vector3 ShowWhenNull;
[HideIf("@this.IsToggled && this.SomeObject != null")]
public int HideWithExpression;
}