rokojori_action_library/Runtime/Rendering/AssignedShaderProperty.cs

68 lines
1.2 KiB
C#

using System.Diagnostics;
using System.Collections;
using System.Collections.Generic;
using System;
using Godot;
using Rokojori.Extensions;
namespace Rokojori
{
public class AssignedShaderProperty
{
public ShaderProperty property;
public Variant value;
public static AssignedShaderProperty From( ShaderProperty sp )
{
var asp = new AssignedShaderProperty();
asp.property = sp;
return asp;
}
public bool Update( bool showChangeMessage = false )
{
if ( ! NeedsUpdate() )
{
return false;
}
if ( showChangeMessage )
{
RJLog.Log( "Update from", value, "to", property.GetValue() );
}
property.ApplyGlobal();
value = property.GetValue();
return true;
}
bool NeedsUpdate()
{
if ( value.AsGodotObject() is Texture2D tex )
{
var pTexture = property.GetValue().AsGodotObject() as Texture2D;
var same = tex == pTexture;
if ( ! same )
{
RJLog.Log( "textures changed:", tex, ">>", pTexture );
}
return ! same;
}
if ( value.Equals( property.GetValue() ) )
{
return false;
}
return true;
}
}
}