mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 13:59:22 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
63 lines
1.3 KiB
C#
63 lines
1.3 KiB
C#
using Sandbox;
|
|
|
|
namespace Editor.Assets;
|
|
|
|
[AssetPreview( "rtex" )]
|
|
class PreviewRenderTexture : AssetPreview
|
|
{
|
|
private RenderTextureAsset renderTexture;
|
|
|
|
public override bool IsAnimatedPreview => false;
|
|
|
|
public PreviewRenderTexture( Asset asset ) : base( asset )
|
|
{
|
|
if ( asset.TryLoadResource<RenderTextureAsset>( out var resource ) )
|
|
{
|
|
renderTexture = resource;
|
|
}
|
|
}
|
|
|
|
public override Task InitializeAsset()
|
|
{
|
|
if ( renderTexture?.Texture is null )
|
|
{
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
using ( Scene.Push() )
|
|
{
|
|
PrimaryObject = new GameObject();
|
|
PrimaryObject.WorldTransform = Transform.Zero;
|
|
|
|
var sprite = PrimaryObject.AddComponent<SpriteRenderer>();
|
|
sprite.Sprite = new Sprite()
|
|
{
|
|
Animations =
|
|
[
|
|
new Sprite.Animation
|
|
{
|
|
Name = "Default",
|
|
Frames = [ new Sprite.Frame { Texture = renderTexture.Texture } ]
|
|
}
|
|
]
|
|
};
|
|
sprite.Size = new Vector2( 16, 16 );
|
|
|
|
Camera.Orthographic = true;
|
|
Camera.OrthographicHeight = 16;
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
public override void UpdateScene( float cycle, float timeStep )
|
|
{
|
|
base.UpdateScene( cycle, timeStep );
|
|
|
|
Camera.Orthographic = true;
|
|
Camera.OrthographicHeight = 16;
|
|
Camera.WorldPosition = Vector3.Forward * -200;
|
|
Camera.WorldRotation = Rotation.LookAt( Vector3.Forward );
|
|
}
|
|
}
|