コガネブログ

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

【Unity】【Odin - Inspector and Serializer】パラメータをタブでグループ分けする「TabGroup」属性

目次

「TabGroup」属性

「TabGroup」属性を使用すると
変数をタブ付きのグループに分けることができます

f:id:baba_s:20170719121419p:plain

using Sirenix.OdinInspector;
using UnityEngine;

public class Example : MonoBehaviour
{
    [TabGroup( "タブ A" )] public int a1;
    [TabGroup( "タブ A" )] public int a2;
    [TabGroup( "タブ A" )] public int a3;
    
    [TabGroup( "タブ B" )] public int b1;
    [TabGroup( "タブ B" )] public int b2;
    
    [TabGroup( "タブ C" )] public int c1;
    
    [TabGroup( group:"グループ", tab:"タブ A" )] public int d1;
    [TabGroup( group:"グループ", tab:"タブ A" )] public int d2;
    [TabGroup( group:"グループ", tab:"タブ A" )] public int d3;
    
    [TabGroup( group:"グループ", tab:"タブ B" )] public int e1;
    [TabGroup( group:"グループ", tab:"タブ B" )] public int e2;
    
    [TabGroup( group:"グループ", tab:"タブ C" )] public int f1;
}

使い方

下記の様に記述するだけで使用できます

[TabGroup( "タブ A" )] public int a1;
[TabGroup( "タブ A" )] public int a2;
[TabGroup( "タブ A" )] public int a3;

[TabGroup( "タブ B" )] public int b1;
[TabGroup( "タブ B" )] public int b2;

[TabGroup( "タブ C" )] public int c1;

1 つのクラス内で複数の TabGroup を使用したい場合は
下記の様に group を指定します

[TabGroup( group:"グループ", tab:"タブ A" )] public int d1;
[TabGroup( group:"グループ", tab:"タブ A" )] public int d2;
[TabGroup( group:"グループ", tab:"タブ A" )] public int d3;

[TabGroup( group:"グループ", tab:"タブ B" )] public int e1;
[TabGroup( group:"グループ", tab:"タブ B" )] public int e2;

[TabGroup( group:"グループ", tab:"タブ C" )] public int f1;

参考サイト様

Odin Inspector and Serializer | Improve your workflow in Unity