mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-01-23 13:50:13 -05:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
35 lines
879 B
C#
35 lines
879 B
C#
using System.Threading;
|
|
|
|
namespace Sandbox.Resources;
|
|
|
|
/// <summary>
|
|
/// Provides a texture generator entry that returns the texture owned by a RenderTexture asset.
|
|
/// </summary>
|
|
[Title( "Render Texture Asset" )]
|
|
[Icon( "switch_video" )]
|
|
[ClassName( "rendertexture" )]
|
|
public sealed class RenderTextureAssetGenerator : TextureGenerator
|
|
{
|
|
/// <summary>
|
|
/// The render texture asset to reference.
|
|
/// </summary>
|
|
[Property]
|
|
public RenderTextureAsset Asset { get; set; }
|
|
|
|
protected override async ValueTask<Texture> CreateTexture( Options options, CancellationToken ct )
|
|
{
|
|
if ( Asset is null )
|
|
return default;
|
|
|
|
if ( options.Compiler is not null && !string.IsNullOrEmpty( Asset.ResourcePath ) )
|
|
{
|
|
options.Compiler.Context.AddCompileReference( Asset.ResourcePath );
|
|
}
|
|
|
|
await MainThread.Wait();
|
|
ct.ThrowIfCancellationRequested();
|
|
|
|
return Asset.Texture;
|
|
}
|
|
}
|