【Unity】指定した型の公開しているVFXGraphのプロパティを取得する

はじめに

指定した型の公開しているVFXGraphのプロパティを一括で取得する方法を紹介します。

環境は Unity 2021.3.25f1です

スクリプト作成

visualEffectAssetクラスのGetExposedPropertiesですべてのプロパティを取得できます。

docs.unity3d.com

using System.Collections.Generic;
using UnityEngine;
using UnityEngine.VFX;
using System.Linq;
public class TestVfx : MonoBehaviour
{
    public VisualEffect effect;

    public List<VFXExposedProperty> GetProperties(System.Type type)
    {
        List<VFXExposedProperty> list = new List<VFXExposedProperty>();
        effect.visualEffectAsset.GetExposedProperties(list);
        return list.Where(_ => _.type == type).ToList();
    }

    public void Test()
    {
        //公開しているBoolを取得
        var list = GetProperties(typeof(bool));
        for(int i = 0; i < list.Count; i++)
        {
            Debug.Log("Propertie " + list[i].name);
        }
    }
}