mirror of
https://github.com/Facepunch/sbox-public.git
synced 2026-04-19 05:48:07 -04:00
This commit imports the C# engine code and game files, excluding C++ source code. [Source-Commit: ceb3d758046e50faa6258bc3b658a30c97743268]
58 lines
1.2 KiB
C#
58 lines
1.2 KiB
C#
namespace Editor.Assets;
|
|
|
|
[AssetPreview( "jpg" )]
|
|
[AssetPreview( "vtex" )]
|
|
class PreviewImage : AssetPreview
|
|
{
|
|
internal Texture texture;
|
|
|
|
public override bool IsAnimatedPreview => false;
|
|
|
|
public PreviewImage( Asset asset ) : base( asset )
|
|
{
|
|
if ( asset.AssetType == AssetType.ImageFile )
|
|
{
|
|
texture = Texture.Load( Asset.GetSourceFile() );
|
|
}
|
|
else
|
|
{
|
|
texture = Texture.Load( Asset.Path );
|
|
}
|
|
}
|
|
|
|
public override Task InitializeAsset()
|
|
{
|
|
using ( Scene.Push() )
|
|
{
|
|
PrimaryObject = new GameObject();
|
|
PrimaryObject.WorldTransform = Transform.Zero;
|
|
|
|
var sprite = PrimaryObject.AddComponent<SpriteRenderer>();
|
|
sprite.Sprite = new Sprite()
|
|
{
|
|
Animations = [new()
|
|
{
|
|
Name = "Default",
|
|
Frames = [ new Sprite.Frame { Texture = 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 );
|
|
}
|
|
}
|