using Godot; using System.Reflection; using System.Collections.Generic; namespace Rokojori { [Tool] [GlobalClass] public partial class FloatPropertyName : Resource { [Export] public string propertyName; public void Set( Material material, float value ) { if ( material is ShaderMaterial ) { var shaderMaterial = ( ShaderMaterial ) material; shaderMaterial.SetShaderParameter( propertyName, value ); return; } var propertyInfo = material.GetType().GetProperty( propertyName ); if ( propertyInfo == null ) { return; } propertyInfo.SetValue( material, value ); } public float Get( Material material ) { if ( material is ShaderMaterial ) { var m = ( ShaderMaterial ) material; return (float) m.GetShaderParameter( propertyName ); } var propertyInfo = material.GetType().GetProperty( propertyName ); if ( propertyInfo == null ) { return default( float ); } return (float) propertyInfo.GetValue( material ); } } }