ソースコード
using System;
using UnityEditor;
using UnityEditor.UI;
using UnityEngine;
using UnityEngine.UI;
[CustomEditor( typeof( ContentSizeFitter ) )]
public sealed class ContentSizeFitterInspector : Editor
{
private static readonly Type BASE_EDITOR_TYPE = typeof( ContentSizeFitterEditor );
public override void OnInspectorGUI()
{
var contentSizeFitter = ( ContentSizeFitter ) target;
var editor = CreateEditor( contentSizeFitter, BASE_EDITOR_TYPE );
editor.OnInspectorGUI();
void SetFitMode( ContentSizeFitter.FitMode fitMode )
{
if ( contentSizeFitter.horizontalFit == fitMode &&
contentSizeFitter.verticalFit == fitMode )
{
return;
}
contentSizeFitter.horizontalFit = fitMode;
contentSizeFitter.verticalFit = fitMode;
EditorUtility.SetDirty( contentSizeFitter );
}
using ( new EditorGUILayout.HorizontalScope() )
{
if ( GUILayout.Button( "Unconstrained" ) )
{
SetFitMode( ContentSizeFitter.FitMode.Unconstrained );
}
if ( GUILayout.Button( "Min Size" ) )
{
SetFitMode( ContentSizeFitter.FitMode.MinSize );
}
if ( GUILayout.Button( "Preferred Size" ) )
{
SetFitMode( ContentSizeFitter.FitMode.PreferredSize );
}
}
}
}
使用例