// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using FlaxEngine; using Object = FlaxEngine.Object; namespace FlaxEditor.Viewport.Previews { /// /// Preview control for asset. /// /// public class IESProfilePreview : TexturePreviewBase { private IESProfile _asset; private MaterialInstance _previewMaterial; /// /// Gets or sets the asset to preview. /// public IESProfile Asset { get => _asset; set { if (_asset != value) { _asset = value; _previewMaterial.SetParameterValue("Texture", value); UpdateTextureRect(); } } } /// /// Initializes a new instance of the class. /// public IESProfilePreview() { var baseMaterial = FlaxEngine.Content.LoadAsyncInternal(EditorAssets.IesProfilePreviewMaterial); // Wait for base (don't want to async material parameters set due to async loading) if (baseMaterial == null || baseMaterial.WaitForLoaded()) throw new Exception("Cannot load IES Profile preview material."); // Create preview material (virtual) _previewMaterial = baseMaterial.CreateVirtualInstance(); } /// public override void OnDestroy() { Object.Destroy(ref _previewMaterial); base.OnDestroy(); } /// protected override void CalculateTextureRect(out Rectangle rect) { CalculateTextureRect(new Float2(256), Size, out rect); } /// protected override void DrawTexture(ref Rectangle rect) { // Check if has loaded asset if (_asset && _asset.IsLoaded) { Render2D.DrawMaterial(_previewMaterial, rect); } } } }