/// <summary>
        /// Initializes a new instance of the <see cref="ParticleSystemTimeline"/> class.
        /// </summary>
        /// <param name="preview">The particle system preview.</param>
        public ParticleSystemTimeline(ParticleSystemPreview preview)
            : base(PlaybackButtons.Play | PlaybackButtons.Stop)
        {
            PlaybackState        = PlaybackStates.Playing;
            PropertiesEditObject = new Proxy(this);

            _preview = preview;

            // Setup track types
            TrackArchetypes.Add(ParticleEmitterTrack.GetArchetype());
            TrackArchetypes.Add(FolderTrack.GetArchetype());
        }
Exemple #2
0
        /// <summary>
        /// Loads the timeline from the specified data.
        /// </summary>
        /// <param name="data">The data.</param>
        public void Load(byte[] data)
        {
            Clear();

            using (var memory = new MemoryStream(data))
                using (var stream = new BinaryReader(memory))
                {
                    // Load properties
                    int version = stream.ReadInt32();
                    if (version != 1)
                    {
                        throw new Exception("Unknown particle timeline version " + version);
                    }
                    FramesPerSecond = stream.ReadSingle();
                    DurationFrames  = stream.ReadInt32();

                    // Load emitters
                    int emittersCount = stream.ReadInt32();

                    // Load tracks
                    int tracksCount = stream.ReadInt32();
                    _tracks.Capacity = Math.Max(_tracks.Capacity, tracksCount);
                    for (int i = 0; i < tracksCount; i++)
                    {
                        var   type = stream.ReadByte();
                        var   flag = stream.ReadByte();
                        Track track;
                        var   mute = (flag & 1) == 1;
                        switch (type)
                        {
                        // Emitter
                        case 0:
                        {
                            track = new ParticleEmitterTrack(TrackArchetypes[1], mute);
                            break;
                        }

                        // Folder
                        case 1:
                        {
                            track = new FolderTrack(TrackArchetypes[0], mute);
                            break;
                        }

                        default: throw new Exception("Unknown Particle System track type " + type);
                        }
                        int parentIndex   = stream.ReadInt32();
                        int childrenCount = stream.ReadInt32();
                        track.Name = Utilities.Utils.ReadStr(stream, -13);
                        track.Tag  = parentIndex;

                        switch (type)
                        {
                        // Emitter
                        case 0:
                        {
                            var  e  = (ParticleEmitterTrack)track;
                            Guid id = new Guid(stream.ReadBytes(16));
                            e.Emitter = FlaxEngine.Content.LoadAsync <ParticleEmitter>(ref id);
                            var emitterIndex = stream.ReadInt32();
                            var m            = e.Media[0];
                            m.StartFrame     = stream.ReadInt32();
                            m.DurationFrames = stream.ReadInt32();
                            break;
                        }

                        // Folder
                        case 1:
                        {
                            var e = (FolderTrack)track;
                            e.IconColor = new Color(stream.ReadByte(), stream.ReadByte(), stream.ReadByte(), stream.ReadByte());
                            break;
                        }
                        }

                        AddLoadedTrack(track);
                    }
                    for (int i = 0; i < tracksCount; i++)
                    {
                        var parentIndex = (int)_tracks[i].Tag;
                        _tracks[i].Tag = null;
                        if (parentIndex != -1)
                        {
                            _tracks[i].ParentTrack = _tracks[parentIndex];
                        }
                    }
                    for (int i = 0; i < tracksCount; i++)
                    {
                        _tracks[i].OnLoaded();
                    }
                }

            ArrangeTracks();
            ClearEditedFlag();
            OnPlay();
        }