rj-action-library/Runtime/Shading/Properties/Vector2PropertyName.cs

53 lines
1.1 KiB
C#
Raw Normal View History

2024-09-14 06:41:52 +00:00
using Godot;
using System.Reflection;
using System.Collections.Generic;
namespace Rokojori
{
[Tool]
[GlobalClass]
public partial class Vector2PropertyName : Resource
{
[Export]
public string propertyName;
public void Set( Material material, Vector2 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 Vector2 Get( Material material )
{
if ( material is ShaderMaterial )
{
var m = ( ShaderMaterial ) material;
return (Vector2) m.GetShaderParameter( propertyName );
}
var propertyInfo = material.GetType().GetProperty( propertyName );
if ( propertyInfo == null )
{
return default( Vector2 );
}
return (Vector2) propertyInfo.GetValue( material );
}
}
}