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]
36 lines
684 B
C#
36 lines
684 B
C#
namespace Sandbox;
|
|
|
|
public partial class Component
|
|
{
|
|
protected virtual Task OnLoad()
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
private void LaunchLoader()
|
|
{
|
|
var loadingTask = OnLoad();
|
|
if ( loadingTask is null || loadingTask.IsCompletedSuccessfully )
|
|
return;
|
|
|
|
GameObject.Flags |= GameObjectFlags.Loading;
|
|
Scene.AddLoadingTask( WaitForLoad( loadingTask ) );
|
|
|
|
}
|
|
|
|
private async Task WaitForLoad( Task task )
|
|
{
|
|
await task;
|
|
|
|
if ( !this.IsValid() ) return;
|
|
if ( !GameObject.IsValid() ) return;
|
|
|
|
GameObject.Flags &= ~GameObjectFlags.Loading;
|
|
}
|
|
|
|
internal void OnLoadInternal()
|
|
{
|
|
CallbackBatch.Add( CommonCallback.Loading, LaunchLoader, this, "LaunchLoader" );
|
|
}
|
|
}
|