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

54 lines
1.1 KiB
C#

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