// Copyright (c) 2012-2021 Wojciech Figat. All rights reserved. using System; using System.IO; using FlaxEngine; namespace FlaxEditor.GUI.Timeline.Tracks { /// /// The timeline media that represents a nested scene animation media event. /// /// public class NestedSceneAnimationMedia : SingleMediaAssetMedia { private sealed class Proxy : ProxyBase { /// /// Gets or sets the nested scene animation to play. /// [EditorDisplay("General"), EditorOrder(10), Tooltip("The nested scene animation to play.")] public SceneAnimation NestedSceneAnimation { get => Track.Asset; set => Track.Asset = value; } /// /// Gets or sets the nested animation looping mode. /// [EditorDisplay("General"), EditorOrder(20), Tooltip("If checked, the nested animation will loop when playback exceeds its duration. Otherwise it will stop play.")] public bool Loop { get => Track.Loop; set => Track.Loop = value; } /// public Proxy(NestedSceneAnimationTrack track, NestedSceneAnimationMedia media) : base(track, media) { } } /// public override void OnTimelineChanged(Track track) { base.OnTimelineChanged(track); PropertiesEditObject = new Proxy(Track as NestedSceneAnimationTrack, this); } } /// /// The timeline track that represents a nested scene animation playback. /// /// public class NestedSceneAnimationTrack : SingleMediaAssetTrack { /// /// Gets the archetype. /// /// The archetype. public static TrackArchetype GetArchetype() { return new TrackArchetype { TypeId = 3, Name = "Nested Timeline", Create = options => new NestedSceneAnimationTrack(ref options), Load = LoadTrack, Save = SaveTrack, }; } private static void LoadTrack(int version, Track track, BinaryReader stream) { var e = (NestedSceneAnimationTrack)track; Guid id = new Guid(stream.ReadBytes(16)); e.Asset = FlaxEngine.Content.LoadAsync(id); var m = e.TrackMedia; m.StartFrame = stream.ReadInt32(); m.DurationFrames = stream.ReadInt32(); } private static void SaveTrack(Track track, BinaryWriter stream) { var e = (NestedSceneAnimationTrack)track; var assetId = e.Asset?.ID ?? Guid.Empty; stream.Write(assetId.ToByteArray()); if (e.Media.Count != 0) { var m = e.TrackMedia; stream.Write(m.StartFrame); stream.Write(m.DurationFrames); } else { stream.Write(0); stream.Write(track.Timeline.DurationFrames); } } /// /// Gets or sets the nested animation looping mode. /// public bool TrackLoop { get => Loop; set { if (Loop == value) return; Loop = value; Timeline?.MarkAsEdited(); } } /// public NestedSceneAnimationTrack(ref TrackCreateOptions options) : base(ref options) { } } }