コガネブログ

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

【Unity】RectTransform の「Some values driven by XXXX」の状態を取得する方法

概要

using System.Reflection;
using UnityEditor;
using UnityEngine;

public static class Example
{
    [MenuItem( "Tools/Hoge" )]
    private static void Hoge()
    {
        var rectTransform    = ( RectTransform ) Selection.activeTransform;
        var type             = typeof( RectTransform );
        var propertyInfo     = type.GetProperty( "drivenProperties", BindingFlags.Instance | BindingFlags.NonPublic );
        var drivenProperties = propertyInfo.GetValue( rectTransform );

        Debug.Log( drivenProperties );
    }
}

リフレクションを使用して drivenProperties プロパティを参照する

f:id:baba_s:20201005170214p:plain

例えば ContentSizeFitter の Horizontal Fit が設定されている RectTransform の場合

f:id:baba_s:20201005170244p:plain

SizeDeltaX が「Some values driven by XXXX」の対象になっていることが確認できる

参考サイト様