コガネブログ

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

【Unity】Preset の Excluded Properties を昇順に並べ替えるエディタ拡張

概要

Preset を右クリックして「Exclude all properties」を押すと
プロパティが除外設定に登録されるが順番に規則性がないため
除外設定を解除したいプロパティを探すのが大変だった

using System.Linq;
using UnityEditor;
using UnityEditor.Presets;

public static class PresetMenuItem
{
    [MenuItem( "CONTEXT/Preset/Excluded Properties を昇順に並べ替え" )]
    private static void SortExcludedProperties( MenuCommand menuCommand )
    {
        var preset = ( Preset ) menuCommand.context;

        Undo.RecordObject( preset, "Excluded Properties を昇順に並べ替え" );

        preset.excludedProperties = preset.excludedProperties
                .OrderBy( x => x )
                .ToArray()
            ;

        // Array.Sort では反映されない
        //Array.Sort( preset.excludedProperties );
    }
}

上記のエディタ拡張を使用すると

除外設定に登録されたプロパティが名前順にソートされるので
除外設定を解除したいプロパティを探しやすくなる