Files
sbox-public/engine/Sandbox.Engine/Scene/Components/Component.Dirty.cs
s&box team 71f266059a Open source release
This commit imports the C# engine code and game files, excluding C++ source code.

[Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
2025-11-24 09:05:18 +00:00

54 lines
958 B
C#

namespace Sandbox;
public abstract partial class Component
{
bool _dirty;
/// <summary>
/// Called when a property is set, which will run a callback
/// </summary>
protected void OnPropertyDirty<T>( in WrappedPropertySet<T> p )
{
p.Setter( p.Value );
OnPropertyDirty();
}
protected void OnPropertyDirty()
{
if ( _dirty ) return;
if ( !IsValid ) return;
_dirty = true;
using ( CallbackBatch.Batch() )
{
CallbackBatch.Add( CommonCallback.Dirty, OnDirtyInternal, this, "OnDirty" );
}
}
void OnDirtyInternal()
{
if ( !_dirty ) return;
ExceptionWrap( "OnDirty", OnDirty );
_dirty = false;
}
/// <summary>
/// Called when the component has become dirty
/// </summary>
protected virtual void OnDirty()
{
}
}
[AttributeUsage( AttributeTargets.Property )]
[CodeGenerator( CodeGeneratorFlags.WrapPropertySet | CodeGeneratorFlags.Instance, "OnPropertyDirty" )]
public class MakeDirtyAttribute : Attribute
{
}