// Copyright (c) 2012-2023 Wojciech Figat. All rights reserved. using System; using System.Collections.Generic; using System.IO; using FlaxEditor.Utilities; using FlaxEngine; namespace FlaxEditor.GUI.Timeline.Tracks { /// /// The timeline media that represents a particle miter playback media event. /// /// public class ParticleEmitterMedia : Media { private sealed class Proxy : ProxyBase { /// /// Gets or sets the particle emitter to simulate. /// [EditorDisplay("General"), EditorOrder(10), Tooltip("The particle emitter to simulate.")] public ParticleEmitter ParticleEmitter { get => Track.Asset; set => Track.Asset = value; } /// public Proxy(ParticleEmitterTrack track, ParticleEmitterMedia media) : base(track, media) { } } /// public override void OnTimelineChanged(Track track) { base.OnTimelineChanged(track); PropertiesEditObject = track != null ? new Proxy((ParticleEmitterTrack)track, this) : null; } } /// /// The timeline track that represents a particle emitter playback. /// /// public class ParticleEmitterTrack : SingleMediaAssetTrack { /// /// Gets the archetype. /// /// The archetype. public static TrackArchetype GetArchetype() { return new TrackArchetype { TypeId = 0, Name = "Particle Emitter", Create = options => new ParticleEmitterTrack(ref options), Load = LoadTrack, Save = SaveTrack, }; } private static void LoadTrack(int version, Track track, BinaryReader stream) { var e = (ParticleEmitterTrack)track; Guid id = stream.ReadGuid(); e.Asset = FlaxEngine.Content.LoadAsync(id); stream.ReadInt32(); // Skip emitterIndex var m = e.TrackMedia; m.StartFrame = stream.ReadInt32(); m.DurationFrames = stream.ReadInt32(); } private static void SaveTrack(Track track, BinaryWriter stream) { var e = (ParticleEmitterTrack)track; stream.WriteGuid(ref e.AssetID); stream.Write(((ParticleSystemTimeline)track.Timeline).Emitters.IndexOf(e)); 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); } } /// /// The overriden values for the emitters parameters. Key is parameter ID, value is the custom value. /// public Dictionary ParametersOverrides = new Dictionary(); /// /// Initializes a new instance of the class. /// /// The options. public ParticleEmitterTrack(ref TrackCreateOptions options) : base(ref options) { MinMediaCount = 1; MaxMediaCount = 1; } /// public override void OnDestroy() { ParametersOverrides.Clear(); ParametersOverrides = null; base.OnDestroy(); } } }