Add audio clip preview refresh on asset reimport in Editor
This commit is contained in:
@@ -37,6 +37,7 @@ namespace FlaxEditor.Viewport.Previews
|
||||
|
||||
private readonly object _locker = new object();
|
||||
private AudioClip _asset;
|
||||
private int _pcmSequence = 0;
|
||||
private float[] _pcmData;
|
||||
private AudioDataInfo _pcmInfo;
|
||||
|
||||
@@ -118,6 +119,22 @@ namespace FlaxEditor.Viewport.Previews
|
||||
/// </summary>
|
||||
public static readonly float UnitsPerSecond = 100.0f;
|
||||
|
||||
/// <summary>
|
||||
/// Invalidates the cached audio PCM data and fetches it again from the asset.
|
||||
/// </summary>
|
||||
public void RefreshPreview()
|
||||
{
|
||||
lock (_locker)
|
||||
{
|
||||
// Release any cached data
|
||||
_pcmData = null;
|
||||
|
||||
// Invalidate any in-flight data download to reject cached data due to refresh
|
||||
if (_pcmSequence != 0)
|
||||
_pcmSequence++;
|
||||
}
|
||||
}
|
||||
|
||||
/// <inheritdoc />
|
||||
public override void Draw()
|
||||
{
|
||||
@@ -234,7 +251,13 @@ namespace FlaxEditor.Viewport.Previews
|
||||
/// </summary>
|
||||
private void DownloadData()
|
||||
{
|
||||
var asset = _asset;
|
||||
AudioClip asset;
|
||||
int sequence;
|
||||
lock (_locker)
|
||||
{
|
||||
asset = _asset;
|
||||
sequence = _pcmSequence;
|
||||
}
|
||||
if (!asset)
|
||||
return;
|
||||
|
||||
@@ -259,8 +282,9 @@ namespace FlaxEditor.Viewport.Previews
|
||||
lock (_locker)
|
||||
{
|
||||
// If asset has been modified during data fetching, ignore it
|
||||
if (_asset == asset)
|
||||
if (_asset == asset && _pcmSequence == sequence)
|
||||
{
|
||||
_pcmSequence++;
|
||||
_pcmData = data;
|
||||
_pcmInfo = dataInfo;
|
||||
}
|
||||
|
||||
@@ -307,6 +307,7 @@ namespace FlaxEditor.Windows.Assets
|
||||
_propertiesEditor.BuildLayout();
|
||||
if (_previewSource)
|
||||
_previewSource.Stop();
|
||||
_preview.RefreshPreview();
|
||||
|
||||
// Setup
|
||||
ClearEditedFlag();
|
||||
|
||||
Reference in New Issue
Block a user