Add **Nested Animations** for compositing animation clips

This commit is contained in:
Wojtek Figat
2022-07-31 15:53:09 +02:00
parent 3a39dad30f
commit 3b52914416
15 changed files with 583 additions and 186 deletions

View File

@@ -1,6 +1,8 @@
// Copyright (c) 2012-2022 Wojciech Figat. All rights reserved.
using System;
using FlaxEditor.Content;
using FlaxEditor.GUI.Drag;
using FlaxEditor.GUI.Timeline.Tracks;
using FlaxEditor.Viewport.Previews;
using FlaxEngine;
@@ -24,6 +26,7 @@ namespace FlaxEditor.GUI.Timeline
}
private AnimationPreview _preview;
internal Guid _id;
/// <summary>
/// Gets or sets the animated preview used for the animation playback.
@@ -62,6 +65,7 @@ namespace FlaxEditor.GUI.Timeline
TrackArchetypes.Add(AnimationChannelTrack.GetArchetype());
TrackArchetypes.Add(AnimationChannelDataTrack.GetArchetype());
TrackArchetypes.Add(AnimationEventTrack.GetArchetype());
TrackArchetypes.Add(NestedAnimationTrack.GetArchetype());
}
/// <summary>
@@ -169,5 +173,48 @@ namespace FlaxEditor.GUI.Timeline
base.OnSeek(frame);
}
/// <inheritdoc />
protected override void SetupDragDrop()
{
base.SetupDragDrop();
DragHandlers.Add(new DragHandler(new DragAssets(IsValidAsset), OnDragAsset));
}
private static bool IsValidAsset(AssetItem assetItem)
{
if (assetItem is BinaryAssetItem binaryAssetItem)
{
if (typeof(Animation).IsAssignableFrom(binaryAssetItem.Type))
{
var sceneAnimation = FlaxEngine.Content.LoadAsync<Animation>(binaryAssetItem.ID);
if (sceneAnimation)
return true;
}
}
return false;
}
private static void OnDragAsset(Timeline timeline, DragHelper drag)
{
foreach (var assetItem in ((DragAssets)drag).Objects)
{
if (assetItem is BinaryAssetItem binaryAssetItem)
{
if (typeof(Animation).IsAssignableFrom(binaryAssetItem.Type))
{
var animation = FlaxEngine.Content.LoadAsync<Animation>(binaryAssetItem.ID);
if (!animation || animation.WaitForLoaded())
continue;
var track = (NestedAnimationTrack)timeline.NewTrack(NestedAnimationTrack.GetArchetype());
track.Asset = animation;
track.TrackMedia.DurationFrames = (int)(animation.Length * timeline.FramesPerSecond);
track.Rename(assetItem.ShortName);
timeline.AddTrack(track);
}
}
}
}
}
}