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