You're breathtaking!
This commit is contained in:
91
Source/Editor/Content/Proxy/SpriteAtlasProxy.cs
Normal file
91
Source/Editor/Content/Proxy/SpriteAtlasProxy.cs
Normal file
@@ -0,0 +1,91 @@
|
||||
// Copyright (c) 2012-2020 Wojciech Figat. All rights reserved.
|
||||
|
||||
using System;
|
||||
using FlaxEditor.Content.Thumbnails;
|
||||
using FlaxEditor.Viewport.Previews;
|
||||
using FlaxEditor.Windows;
|
||||
using FlaxEditor.Windows.Assets;
|
||||
using FlaxEngine;
|
||||
using FlaxEngine.GUI;
|
||||
|
||||
namespace FlaxEditor.Content
|
||||
{
|
||||
/// <summary>
|
||||
/// A <see cref="SpriteAtlas"/> asset proxy object.
|
||||
/// </summary>
|
||||
/// <seealso cref="FlaxEditor.Content.BinaryAssetProxy" />
|
||||
public sealed class SpriteAtlasProxy : BinaryAssetProxy
|
||||
{
|
||||
private SimpleSpriteAtlasPreview _preview;
|
||||
|
||||
/// <inheritdoc />
|
||||
public override string Name => "Sprite Atlas";
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanReimport(ContentItem item)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override EditorWindow Open(Editor editor, ContentItem item)
|
||||
{
|
||||
return new SpriteAtlasWindow(editor, (AssetItem)item);
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Color AccentColor => Color.FromRGB(0x5C7F69);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override Type AssetType => typeof(SpriteAtlas);
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnThumbnailDrawPrepare(ThumbnailRequest request)
|
||||
{
|
||||
if (_preview == null)
|
||||
{
|
||||
_preview = new SimpleSpriteAtlasPreview
|
||||
{
|
||||
AnchorPreset = AnchorPresets.StretchAll,
|
||||
Offsets = Margin.Zero,
|
||||
};
|
||||
}
|
||||
|
||||
// TODO: disable streaming for asset during thumbnail rendering (and restore it after)
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override bool CanDrawThumbnail(ThumbnailRequest request)
|
||||
{
|
||||
// Check if asset is streamed enough
|
||||
var asset = (SpriteAtlas)request.Asset;
|
||||
return asset.ResidentMipLevels >= Mathf.Max(1, (int)(asset.MipLevels * ThumbnailsModule.MinimumRequiredResourcesQuality));
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnThumbnailDrawBegin(ThumbnailRequest request, ContainerControl guiRoot, GPUContext context)
|
||||
{
|
||||
_preview.Asset = (SpriteAtlas)request.Asset;
|
||||
_preview.Parent = guiRoot;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void OnThumbnailDrawEnd(ThumbnailRequest request, ContainerControl guiRoot)
|
||||
{
|
||||
_preview.Asset = null;
|
||||
_preview.Parent = null;
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Dispose()
|
||||
{
|
||||
if (_preview != null)
|
||||
{
|
||||
_preview.Dispose();
|
||||
_preview = null;
|
||||
}
|
||||
|
||||
base.Dispose();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user