// Copyright (c) 2012-2024 Wojciech Figat. All rights reserved. using System; using FlaxEditor.Content.Thumbnails; using FlaxEngine; using FlaxEngine.GUI; namespace FlaxEditor.Content { /// /// Base class for all asset proxy objects used to manage . /// /// [HideInEditor] public abstract class AssetProxy : ContentProxy { /// public override bool IsAsset => true; /// /// Gets the full name of the asset type (stored data format). /// public abstract string TypeName { get; } /// /// Gets a value indicating whether this instance is virtual Proxy not linked to any asset. /// protected virtual bool IsVirtual { get; } /// /// Determines whether [is virtual proxy]. /// /// true if [is virtual proxy]; otherwise, false. public bool IsVirtualProxy() { return IsVirtual && CanExport == false; } /// /// Checks if this proxy supports the given asset type id at the given path. /// /// The asset type identifier. /// The asset path. /// True if proxy supports assets of the given type id and path. public virtual bool AcceptsAsset(string typeName, string path) { return typeName == TypeName && path.EndsWith(FileExtension, StringComparison.OrdinalIgnoreCase); } /// /// Constructs the item for the asset. /// /// The asset path. /// The asset type name identifier. /// The asset identifier. /// Created item. public abstract AssetItem ConstructItem(string path, string typeName, ref Guid id); /// /// Called when thumbnail request gets prepared for drawing. /// /// The request. public virtual void OnThumbnailDrawPrepare(ThumbnailRequest request) { } /// /// Determines whether thumbnail can be drawn for the specified item. /// /// The request. /// true if this thumbnail can be drawn for the specified item; otherwise, false. public virtual bool CanDrawThumbnail(ThumbnailRequest request) { return true; } /// /// Called when thumbnail drawing begins. Proxy should setup scene GUI for guiRoot. /// /// The request to render thumbnail. /// The GUI root container control. /// GPU context. public virtual void OnThumbnailDrawBegin(ThumbnailRequest request, ContainerControl guiRoot, GPUContext context) { guiRoot.AddChild(new Label { Text = Name, AnchorPreset = AnchorPresets.StretchAll, Offsets = Margin.Zero, Wrapping = TextWrapping.WrapWords }); } /// /// Called when thumbnail drawing ends. Proxy should clear custom GUI from guiRoot from that should be not destroyed. /// /// The request to render thumbnail. /// The GUI root container control. public virtual void OnThumbnailDrawEnd(ThumbnailRequest request, ContainerControl guiRoot) { } /// /// Called when thumbnail requests cleans data after drawing. /// /// The request. public virtual void OnThumbnailDrawCleanup(ThumbnailRequest request) { } /// /// Initializes rendering settings for asset preview drawing for a thumbnail. /// /// The asset preview. protected void InitAssetPreview(Viewport.Previews.AssetPreview preview) { preview.RenderOnlyWithWindow = false; preview.UseAutomaticTaskManagement = false; preview.AnchorPreset = AnchorPresets.StretchAll; preview.Offsets = Margin.Zero; var task = preview.Task; task.Enabled = false; var view = task.View; view.IsSingleFrame = true; // Disable LOD transitions task.View = view; var eyeAdaptation = preview.PostFxVolume.EyeAdaptation; eyeAdaptation.Mode = EyeAdaptationMode.None; eyeAdaptation.OverrideFlags |= EyeAdaptationSettingsOverride.Mode; preview.PostFxVolume.EyeAdaptation = eyeAdaptation; } } }