mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-02 11:28:19 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
54 lines
958 B
C#
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
|
|
{
|
|
|
|
}
|