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]
55 lines
1.4 KiB
C#
55 lines
1.4 KiB
C#
namespace Editor.Assets;
|
|
|
|
[AssetPreview( "prefab" )]
|
|
class PreviewPrefab : AssetPreview
|
|
{
|
|
public override float PreviewWidgetCycleSpeed => 0.2f;
|
|
|
|
public override bool UsePixelEvaluatorForThumbs => true;
|
|
|
|
public PreviewPrefab( Asset asset ) : base( asset )
|
|
{
|
|
|
|
}
|
|
|
|
/// <summary>
|
|
/// Create the model or whatever needs to be viewed
|
|
/// </summary>
|
|
public override Task InitializeAsset()
|
|
{
|
|
using ( EditorUtility.DisableTextureStreaming() )
|
|
{
|
|
var pf = Asset.LoadResource<PrefabFile>();
|
|
if ( pf is null ) return Task.CompletedTask;
|
|
|
|
using ( Scene.Push() )
|
|
{
|
|
PrimaryObject = GameObject.Clone( pf );
|
|
PrimaryObject.WorldPosition = 0;
|
|
SceneCenter = PrimaryObject.GetBounds().Center;
|
|
SceneSize = PrimaryObject.GetBounds().Size;
|
|
|
|
TryAddDefaultLighting( Scene );
|
|
}
|
|
}
|
|
|
|
return Task.CompletedTask;
|
|
}
|
|
|
|
static void TryAddDefaultLighting( Scene scene )
|
|
{
|
|
if ( scene.Components.GetInDescendantsOrSelf<DirectionalLight>( true ).IsValid() ) return;
|
|
if ( scene.Components.GetInDescendantsOrSelf<SpotLight>( true ).IsValid() ) return;
|
|
if ( scene.Components.GetInDescendantsOrSelf<PointLight>( true ).IsValid() ) return;
|
|
|
|
var go = scene.CreateObject();
|
|
go.Name = "Directional Light";
|
|
|
|
go.WorldRotation = Rotation.From( 90, 0, 0 );
|
|
var light = go.Components.Create<DirectionalLight>();
|
|
light.LightColor = Color.White;
|
|
|
|
scene.SceneWorld.AmbientLightColor = "#557685";
|
|
}
|
|
}
|