rj-action-library/Runtime/Shading/Shaders/UniformMember.cs

65 lines
1.5 KiB
C#
Raw Normal View History

2025-01-03 12:09:23 +00:00
using Godot;
using System.Reflection;
using System.Collections.Generic;
2025-05-27 20:07:15 +00:00
using Microsoft.VisualBasic;
2025-01-03 12:09:23 +00:00
namespace Rokojori
{
public class UniformMember
{
public string name;
public Variant.Type type;
public PropertyHint hint;
public string hintString;
public int usage;
public override string ToString()
{
return type + " " + name + "( '" + hint + "', '" + hintString + "', '" + usage + "')";
}
2025-05-27 20:07:15 +00:00
public static UniformMember Create( string name, Variant.Type type )
{
var um = new UniformMember ();
um.name = name;
um.type = type;
return um;
}
2025-01-03 12:09:23 +00:00
public string GetPropertyNameType()
{
if ( type == Variant.Type.Object )
{
return ( hintString + "" );
}
else
{
return ( type + "" );
}
}
2025-05-27 20:07:15 +00:00
public T Get<[MustBeVariant] T>( Material material )
{
return material is ShaderMaterial sm ? Get<T>( sm ) : Get<T>( (StandardMaterial3D) material );
}
public T Get<[MustBeVariant] T>( ShaderMaterial shaderMaterial )
{
return shaderMaterial.GetShaderParameter( name ).As<T>();
}
public T Get<[MustBeVariant] T>( StandardMaterial3D standardMaterial )
{
var property = new ShaderPropertyName();
property.propertyName = name;
return property._Get<T>( standardMaterial, default( T ) );
}
public void Set( ShaderMaterial shaderMaterial, Variant value )
{
shaderMaterial.SetShaderParameter( name, value );
}
2025-01-03 12:09:23 +00:00
}
}