コガネブログ

平日更新を目標に Unity や C#、Visual Studio、ReSharper などのゲーム開発アレコレを書いていきます

【Unity】【Odin - Inspector and Serializer】条件を満たしているかどうかで項目を表示するかどうかを変更できる「ShowIf」「HideIf」属性

目次

「ShowIf」「HideIf」属性

「ShowIf」属性を使用すると
条件を満たしている場合に変数やプロパティが表示されるようになります

「HideIf」属性を使用すると
条件を満たしている場合に変数やプロパティが非表示になります

f:id:baba_s:20170720153040p:plain

using Sirenix.OdinInspector;
using UnityEngine;

public class Example : MonoBehaviour
{
    public bool isEnable;

    [ShowIf( "isEnable" )] public int a1;
    [HideIf( "isEnable" )] public int a2;

    private bool IsEnable()
    {
        return isEnable;
    }

    [ShowIf( "isEnable" )] public int b1;
    [HideIf( "IsEnable" )] public int b2;
}

使い方

下記の様に記述するだけで使用できます
引数には bool 型の変数の名前を指定します

public bool isEnable;

[ShowIf( "isEnable" )] public int a1;
[HideIf( "isEnable" )] public int a2;

引数には bool 値を返す関数の名前を指定することもできます

private bool IsEnable()
{
    return isEnable;
}

[ShowIf( "isEnable" )] public int b1;
[HideIf( "IsEnable" )] public int b2;

参考サイト様

Odin Inspector and Serializer | Improve your workflow in Unity
Odin Inspector and Serializer | Improve your workflow in Unity