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 ) { } /// /// Create the model or whatever needs to be viewed /// public override Task InitializeAsset() { using ( EditorUtility.DisableTextureStreaming() ) { var pf = Asset.LoadResource(); 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( true ).IsValid() ) return; if ( scene.Components.GetInDescendantsOrSelf( true ).IsValid() ) return; if ( scene.Components.GetInDescendantsOrSelf( true ).IsValid() ) return; var go = scene.CreateObject(); go.Name = "Directional Light"; go.WorldRotation = Rotation.From( 90, 0, 0 ); var light = go.Components.Create(); light.LightColor = Color.White; scene.SceneWorld.AmbientLightColor = "#557685"; } }