Timelines

We found 10 examples in language CSharp for this search. You will see 58 fragments of code.

        public void LoadDataFromDump(string superCollectionName, string collectionName, string getFileName, string getToursFileName, bool replaceGuids, string contentAdminId)
        {
            SuperCollection superCollection = _storage.SuperCollections.Find(CollectionIdFromText(superCollectionName));
            bool createCollection = true;

            if (superCollection != null)
            {
                _storage.Entry(superCollection).Collection(_ => _.Collections).Load();
                createCollection = superCollection.Collections.All(candidate => candidate.Title != collectionName);
            }

            if (superCollection == null || createCollection)
            {
                Collection collection = LoadCollections(superCollectionName, collectionName, contentAdminId);
                using (Stream getData = File.OpenRead(_jsonDirectory + getFileName))
                using (Stream getToursData = getToursFileName == null ? null : File.OpenRead(_jsonDirectory + getToursFileName))
                {
                    LoadData(getData, getToursData, collection, replaceGuids);
                }

                _storage.SaveChanges();
            }
        }

        #region Private Methods descended from LoadDataFromDump

        private Collection LoadCollections(string superCollectionName, string collectionName, string userId)
        {
            User user = (userId == null
                             ? _storage.Users.FirstOrDefault(candidate => candidate.NameIdentifier == null)
                             : _storage.Users.FirstOrDefault(candidate => candidate.NameIdentifier == userId)) ??
                        new User { Id = Guid.NewGuid(), NameIdentifier = userId, DisplayName = userId ?? _defaultUser };

            // load collection
            var collection = new Collection
            {
                Title = collectionName,
                Id = CollectionIdFromSuperCollection(superCollectionName, collectionName),
                User = user
            };

            // load supercollection
            SuperCollection superCollection = _storage.SuperCollections.FirstOrDefault(candidate => candidate.Title == superCollectionName);

            if (superCollection == null)
            {
                superCollection = new SuperCollection
                {
                    Title = superCollectionName,
                    Id = CollectionIdFromText(superCollectionName),
                    User = user
                };
                _storage.SuperCollections.Add(superCollection);
            }

            if (superCollection.Collections == null)
            {
                superCollection.Collections = new System.Collections.ObjectModel.Collection<Collection>();
            }

            superCollection.Collections.Add(collection);

            return collection;
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1506:AvoidExcessiveClassCoupling")]
        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Maintainability", "CA1502:AvoidExcessiveComplexity", Justification = "Incremental change, will refactor later if the import process is kept")]
        private void LoadData(Stream dataTimelines, Stream dataTours, Collection collection, bool replaceGuids)
        {
            var timelines = new DataContractJsonSerializer(typeof(IList<Timeline>)).ReadObject(dataTimelines) as IList<Timeline>;

            _storage.Collections.Add(collection);

            int importedTimelinesCount = 0;

            // associate each timeline with the root collection
            TraverseTimelines(timelines, timeline =>
            {
                if (++importedTimelinesCount < _maxTimelines)
                {
                    timeline.Collection = collection;

                    foreach (Exhibit exhibit in timeline.Exhibits)
                    {
                        exhibit.Collection  = collection;
                        exhibit.UpdatedTime = DateTime.UtcNow;

                        if (exhibit.ContentItems != null)
                        {
                            foreach (ContentItem contentItem in exhibit.ContentItems)
                            {
                                contentItem.Collection = collection;
                            }
                        }
                    }
                }
                else if (timeline.ChildTimelines != null)
                {
                    timeline.ChildTimelines.Clear();
                }
            });

            if (replaceGuids)
            {
                // replace GUIDs to ensure multiple collections can be imported
                TraverseTimelines(timelines, timeline =>
                {
                    timeline.Id = Guid.NewGuid();

                    if (timeline.Exhibits != null)
                    {
                        foreach (Exhibit exhibit in timeline.Exhibits)
                        {
                            exhibit.Id = Guid.NewGuid();

                            if (exhibit.ContentItems != null)
                            {
                                foreach (ContentItem contentItem in exhibit.ContentItems)
                                {
                                    contentItem.Id = Guid.NewGuid();
                                }
                            }
                        }
                    }
                }
                );
            }

            if (timelines != null)
            {
                foreach (var timeline in timelines)
                {
                    if (replaceGuids) timeline.Id = Guid.NewGuid();
                    timeline.Collection = collection;
                    timeline.Depth = -1; // this denotes no migration has been applied to current timeline
                    timeline.ForkNode = Storage.ForkNode((long)timeline.FromYear, (long)timeline.ToYear);
                }

                foreach (var timeline in timelines) // note: timeline objects in "timelines" are ordered by depth already since they are parsed from a nested-JSON file 
                {
                    if (timeline.Depth == -1)
                    {
                        timeline.Depth = 0;
                        MigrateInPlace(timeline);
                    }
                    _storage.Timelines.Add(timeline);
                }

                // Set default values for fields for map view support.
                MapViewSupportForTimelines(timelines);
            }
            _storage.SaveChanges();

            if (dataTours != null)
            {
                var bjrTours =
                    new DataContractJsonSerializer(typeof(BaseJsonResult<IEnumerable<Tour>>)).ReadObject(dataTours) as
                    BaseJsonResult<IEnumerable<Tour>>;

                if (bjrTours != null)
                    foreach (var tour in bjrTours.d)
                    {
                        if (replaceGuids) tour.Id = Guid.NewGuid();
                        tour.Collection = collection;

                        if (tour.Bookmarks != null && replaceGuids)
                        {
                            foreach (var bookmark in tour.Bookmarks)
                            {
                                bookmark.Id = Guid.NewGuid();
                            }
                        }
                        _storage.Tours.Add(tour);
                    }
                _storage.SaveChanges();
            }
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Lowercase is URL friendly")]
        private static Guid CollectionIdFromSuperCollection(string supercollection, string collection)
        {
            return CollectionIdFromText(string.Format(
                CultureInfo.InvariantCulture,
                "{0}|{1}",
                supercollection.ToLower(CultureInfo.InvariantCulture),
                collection.ToLower(CultureInfo.InvariantCulture)));
        }

        [System.Diagnostics.CodeAnalysis.SuppressMessage("Microsoft.Globalization", "CA1308:NormalizeStringsToUppercase", Justification = "Lowercase is URL friendly")]
        private static Guid CollectionIdFromText(string value)
        {
            value       = value.Replace(' ', '-'); // replace with URL friendly representation
            byte[] data = _md5Hasher.ComputeHash(Encoding.Default.GetBytes(value.ToLowerInvariant()));
            return new Guid(data);
        }

        public static void MigrateInPlace(Timeline timeline)
        {
            int subtreeSize = 1;
            if (timeline.Exhibits != null)
            {
                foreach (var exhibit in timeline.Exhibits)
                {
                    subtreeSize++;
                    exhibit.Depth = timeline.Depth + 1;
                    if (exhibit.ContentItems != null)
                    {
                        foreach (ContentItem contentItem in exhibit.ContentItems)
                        {
                            contentItem.Depth = exhibit.Depth + 1;
                        }
                        subtreeSize += exhibit.ContentItems.Count();
                    }
                }
            }

            if (timeline.ChildTimelines != null)
            {
                foreach (var child in timeline.ChildTimelines)
                {
                    child.Depth = timeline.Depth + 1;
                    MigrateInPlace(child);
                    subtreeSize += child.SubtreeSize;
                }
            }
            timeline.SubtreeSize = subtreeSize;
        }


        /// <inheritDoc/>
        protected override void _OnClear()
        {
            foreach (var pair in boneTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            foreach (var pair in slotTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            foreach (var pair in constraintTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            if (this.actionTimeline != null)
            {
                this.actionTimeline.ReturnToPool();
            }

            if (this.zOrderTimeline != null)
            {
                this.zOrderTimeline.ReturnToPool();
            }

            this.frameIntOffset = 0;
            this.frameFloatOffset = 0;
            this.frameOffset = 0;
            this.frameCount = 0;
            this.playTimes = 0;
            this.duration = 0.0f;
            this.scale = 1.0f;
            this.fadeInTime = 0.0f;
            this.cacheFrameRate = 0.0f;
            this.name = "";
            this.boneTimelines.Clear();
            this.slotTimelines.Clear();
            this.constraintTimelines.Clear();
            this.boneCachedFrameIndices.Clear();
            this.slotCachedFrameIndices.Clear();
            this.cachedFrames.Clear();

            this.actionTimeline = null;
            this.zOrderTimeline = null;
            this.parent = null;
        }

        /// <internal/>
        /// <private/>
        public void CacheFrames(float frameRate)
        {
            if (this.cacheFrameRate > 0.0f)
            {
                // TODO clear cache.
                return;
            }

            this.cacheFrameRate = Math.Max((float)Math.Ceiling(frameRate * scale), 1.0f);
            var cacheFrameCount = (int)Math.Ceiling(this.cacheFrameRate * duration) + 1; // Cache one more frame.

            cachedFrames.ResizeList(0, false);
            cachedFrames.ResizeList(cacheFrameCount, false);

            foreach (var bone in this.parent.sortedBones)
            {
                var indices = new List<int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                this.boneCachedFrameIndices[bone.name] = indices;
            }

            foreach (var slot in this.parent.sortedSlots)
            {
                var indices = new List<int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                this.slotCachedFrameIndices[slot.name] = indices;
            }
        }

        /// <private/>
        public void AddBoneTimeline(BoneData bone, TimelineData tiemline)
        {
            if (bone == null || tiemline == null)
            {
                return;
            }

            if (!this.boneTimelines.ContainsKey(bone.name))
            {
                this.boneTimelines[bone.name] = new List<TimelineData>();
            }

            var timelines = this.boneTimelines[bone.name];
            if (!timelines.Contains(tiemline))
            {
                timelines.Add(tiemline);
            }
        }
        /// <private/>
        public void AddSlotTimeline(SlotData slot, TimelineData timeline)
        {
            if (slot == null || timeline == null)
            {
                return;
            }

            if (!this.slotTimelines.ContainsKey(slot.name))
            {
                this.slotTimelines[slot.name] = new List<TimelineData>();
            }

            var timelines = this.slotTimelines[slot.name];
            if (!timelines.Contains(timeline))
            {
                timelines.Add(timeline);
            }
        }

        /// <private/>
        public void AddConstraintTimeline(ConstraintData constraint, TimelineData timeline)
        {
            if (constraint == null || timeline == null)
            {
                return;
            }

            if (!this.constraintTimelines.ContainsKey(constraint.name))
            {
                this.constraintTimelines[constraint.name] = new List<TimelineData>();
            }

            var timelines = this.constraintTimelines[constraint.name];
            if (!timelines.Contains(timeline))
            {
                timelines.Add(timeline);
            }
        }

        /// <private/>
        public List<TimelineData> GetBoneTimelines(string timelineName)
        {
            return this.boneTimelines.ContainsKey(timelineName) ? this.boneTimelines[timelineName] : null;
        }


        public async Task InitializeAsync()
        {
            var defaultAccount = _accountService.Accounts.Single(w => w.IsMarkAsDefault);
            foreach (var preset in defaultAccount.DefaultTimelines())
                _timelines.Add(preset.CreateTimeline(defaultAccount));

            await SaveAsync();
        }

        public async Task ClearAsync()
        {
            _timelines.Clear();
            await SaveAsync();
        }

        public Task RestoreAsync()
        {
            _timelines.Clear();

            var roamingSettings = ApplicationData.Current.RoamingSettings;
            var jsonSettings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
            if (!roamingSettings.Values.CheckContainsKeyAndType("Orion.Timeline", typeof(string)))
                return Task.CompletedTask;

            var timelines = JsonConvert.DeserializeObject<List<TimelineBase>>(roamingSettings.Values["Orion.Timeline"] as string, jsonSettings);

            foreach (var timeline in timelines)
            {
                var account = _accountService.Accounts.SingleOrDefault(w => w.Id == timeline.AccountId);
                if (account == null)
                {
                    Debug.WriteLine($"Timeline \"{timeline.Name}\" (ID: {timeline.Id}) is removed.");
                    Debug.WriteLine("Reason: Account credentials is invalid or unknown account.");
                    continue;
                }
                timeline.Account = account;
                _timelines.Add(timeline);
            }

            return Task.CompletedTask;
        }

        public Task SaveAsync()
        {
            var roamingSettings = ApplicationData.Current.RoamingSettings;
            var jsonSettings = new JsonSerializerSettings {TypeNameHandling = TypeNameHandling.All};
            roamingSettings.Values["Orion.Timeline"] = JsonConvert.SerializeObject(_timelines.Where(w => !w.IsInstant).ToList(), jsonSettings);

            return Task.CompletedTask;
        }

        public async Task AddAsync(TimelineBase timeline)
        {
            _timelines.Add(timeline);
            await SaveAsync();
        }

        public async Task RemoveAsync(TimelineBase timeline)
        {
            _timelines.Remove(timeline);
            await SaveAsync();
        }


        /// <inheritDoc/>
        protected override void _OnClear()
        {
            foreach (var pair in boneTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            foreach (var pair in slotTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            foreach (var pair in constraintTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            if (this.actionTimeline != null)
            {
                this.actionTimeline.ReturnToPool();
            }

            if (this.zOrderTimeline != null)
            {
                this.zOrderTimeline.ReturnToPool();
            }

            this.frameIntOffset = 0;
            this.frameFloatOffset = 0;
            this.frameOffset = 0;
            this.frameCount = 0;
            this.playTimes = 0;
            this.duration = 0.0f;
            this.scale = 1.0f;
            this.fadeInTime = 0.0f;
            this.cacheFrameRate = 0.0f;
            this.name = "";
            this.boneTimelines.Clear();
            this.slotTimelines.Clear();
            this.constraintTimelines.Clear();
            this.boneCachedFrameIndices.Clear();
            this.slotCachedFrameIndices.Clear();
            this.cachedFrames.Clear();

            this.actionTimeline = null;
            this.zOrderTimeline = null;
            this.parent = null;
        }

        /// <internal/>
        /// <private/>
        public void CacheFrames(float frameRate)
        {
            if (this.cacheFrameRate > 0.0f)
            {
                // TODO clear cache.
                return;
            }

            this.cacheFrameRate = Math.Max((float)Math.Ceiling(frameRate * scale), 1.0f);
            var cacheFrameCount = (int)Math.Ceiling(this.cacheFrameRate * duration) + 1; // Cache one more frame.

            cachedFrames.ResizeList(0, false);
            cachedFrames.ResizeList(cacheFrameCount, false);

            foreach (var bone in this.parent.sortedBones)
            {
                var indices = new List<int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                this.boneCachedFrameIndices[bone.name] = indices;
            }

            foreach (var slot in this.parent.sortedSlots)
            {
                var indices = new List<int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                this.slotCachedFrameIndices[slot.name] = indices;
            }
        }

        /// <private/>
        public void AddBoneTimeline(BoneData bone, TimelineData tiemline)
        {
            if (bone == null || tiemline == null)
            {
                return;
            }

            if (!this.boneTimelines.ContainsKey(bone.name))
            {
                this.boneTimelines[bone.name] = new List<TimelineData>();
            }

            var timelines = this.boneTimelines[bone.name];
            if (!timelines.Contains(tiemline))
            {
                timelines.Add(tiemline);
            }
        }
        /// <private/>
        public void AddSlotTimeline(SlotData slot, TimelineData timeline)
        {
            if (slot == null || timeline == null)
            {
                return;
            }

            if (!this.slotTimelines.ContainsKey(slot.name))
            {
                this.slotTimelines[slot.name] = new List<TimelineData>();
            }

            var timelines = this.slotTimelines[slot.name];
            if (!timelines.Contains(timeline))
            {
                timelines.Add(timeline);
            }
        }

        /// <private/>
        public void AddConstraintTimeline(ConstraintData constraint, TimelineData timeline)
        {
            if (constraint == null || timeline == null)
            {
                return;
            }

            if (!this.constraintTimelines.ContainsKey(constraint.name))
            {
                this.constraintTimelines[constraint.name] = new List<TimelineData>();
            }

            var timelines = this.constraintTimelines[constraint.name];
            if (!timelines.Contains(timeline))
            {
                timelines.Add(timeline);
            }
        }

        /// <private/>
        public List<TimelineData> GetBoneTimelines(string timelineName)
        {
            return this.boneTimelines.ContainsKey(timelineName) ? this.boneTimelines[timelineName] : null;
        }

        /// <private/>
        protected override void _OnClear()
        {
            foreach (var timeline in this._boneTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var timeline in this._slotTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var timeline in this._constraintTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var bonePose in this._bonePoses.Values)
            {
                bonePose.ReturnToPool();
            }

            if (this._actionTimeline != null)
            {
                this._actionTimeline.ReturnToPool();
            }

            if (this._zOrderTimeline != null)
            {
                this._zOrderTimeline.ReturnToPool();
            }

            this.actionEnabled = false;
            this.additiveBlending = false;
            this.displayControl = false;
            this.resetToPose = false;
            this.playTimes = 1;
            this.layer = 0;

            this.timeScale = 1.0f;
            this.weight = 1.0f;
            this.autoFadeOutTime = 0.0f;
            this.fadeTotalTime = 0.0f;
            this.name = string.Empty;
            this.group = string.Empty;

            this._timelineDirty = true;
            this._playheadState = 0;
            this._fadeState = -1;
            this._subFadeState = -1;
            this._position = 0.0f;
            this._duration = 0.0f;
            this._fadeTime = 0.0f;
            this._time = 0.0f;
            this._fadeProgress = 0.0f;
            this._weightResult = 0.0f;
            this._blendState.Clear();
            this._boneMask.Clear();
            this._boneTimelines.Clear();
            this._slotTimelines.Clear();
            this._constraintTimelines.Clear();
            this._bonePoses.Clear();
            this._animationData = null; //
            this._armature = null; //
            this._actionTimeline = null; //
            this._zOrderTimeline = null;
        }

        private void _UpdateTimelines()
        {
            { // Update bone timelines.
                Dictionary<string, List<BoneTimelineState>> boneTimelines = new Dictionary<string, List<BoneTimelineState>>();

                foreach (var timeline in this._boneTimelines)
                {
                    // Create bone timelines map.
                    var timelineName = timeline.bone.name;
                    if (!(boneTimelines.ContainsKey(timelineName)))
                    {
                        boneTimelines[timelineName] = new List<BoneTimelineState>();
                    }

                    boneTimelines[timelineName].Add(timeline);
                }

                foreach (var bone in this._armature.GetBones())
                {
                    var timelineName = bone.name;
                    if (!this.ContainsBoneMask(timelineName))
                    {
                        continue;
                    }

                    var timelineDatas = this._animationData.GetBoneTimelines(timelineName);
                    if (boneTimelines.ContainsKey(timelineName))
                    {
                        // Remove bone timeline from map.
                        boneTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new bone timeline.
                        var bonePose = this._bonePoses.ContainsKey(timelineName) ? this._bonePoses[timelineName] : (this._bonePoses[timelineName] = BaseObject.BorrowObject<BonePose>());
                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.BoneAll:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneTranslate:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneTranslateTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneRotate:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneRotateTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneScale:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneScaleTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }
                        else if (this.resetToPose)
                        { // Pose timeline.
                            var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
                            timeline.bone = bone;
                            timeline.bonePose = bonePose;
                            timeline.Init(this._armature, this, null);
                            this._boneTimelines.Add(timeline);
                            this._poseTimelines.Add(timeline);
                        }
                    }
                }

                foreach (var timelines in boneTimelines.Values)
                {
                    // Remove bone timelines.
                    foreach (var timeline in timelines)
                    {
                        this._boneTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }

            { // Update slot timelines.
                Dictionary<string, List<SlotTimelineState>> slotTimelines = new Dictionary<string, List<SlotTimelineState>>();
                List<int> ffdFlags = new List<int>();

                foreach (var timeline in this._slotTimelines)
                {
                    // Create slot timelines map.
                    var timelineName = timeline.slot.name;
                    if (!(slotTimelines.ContainsKey(timelineName)))
                    {
                        slotTimelines[timelineName] = new List<SlotTimelineState>();
                    }

                    slotTimelines[timelineName].Add(timeline);
                }

                foreach (var slot in this._armature.GetSlots())
                {
                    var boneName = slot.parent.name;
                    if (!this.ContainsBoneMask(boneName))
                    {
                        continue;
                    }

                    var timelineName = slot.name;
                    var timelineDatas = this._animationData.GetSlotTimelines(timelineName);

                    if (slotTimelines.ContainsKey(timelineName))
                    {
                        // Remove slot timeline from map.
                        slotTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new slot timeline.
                        var displayIndexFlag = false;
                        var colorFlag = false;
                        ffdFlags.Clear();

                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.SlotDisplay:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            displayIndexFlag = true;
                                            break;
                                        }
                                    case TimelineType.SlotColor:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            colorFlag = true;
                                            break;
                                        }
                                    case TimelineType.SlotFFD:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotFFDTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            ffdFlags.Add((int)timeline.meshOffset);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }

                        if (this.resetToPose)
                        {
                            // Pose timeline.
                            if (!displayIndexFlag)
                            {
                                var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
                                timeline.slot = slot;
                                timeline.Init(this._armature, this, null);
                                this._slotTimelines.Add(timeline);
                                this._poseTimelines.Add(timeline);
                            }

                            if (!colorFlag)
                            {
                                var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
                                timeline.slot = slot;
                                timeline.Init(this._armature, this, null);
                                this._slotTimelines.Add(timeline);
                                this._poseTimelines.Add(timeline);
                            }

                            if (slot.rawDisplayDatas != null)
                            {
                                foreach (var displayData in slot.rawDisplayDatas)
                                {
                                    if (displayData != null && displayData.type == DisplayType.Mesh)
                                    {
                                        var meshOffset = (displayData as MeshDisplayData).offset;
                                        if (!ffdFlags.Contains(meshOffset))
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotFFDTimelineState>();
                                            timeline.meshOffset = meshOffset; //
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, null);
                                            this._slotTimelines.Add(timeline);
                                            this._poseTimelines.Add(timeline);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (var timelines in slotTimelines.Values)
                {
                    // Remove slot timelines.
                    foreach (var timeline in timelines)
                    {
                        this._slotTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }

            {
                // Update constraint timelines.
                Dictionary<string, List<ConstraintTimelineState>> constraintTimelines = new Dictionary<string, List<ConstraintTimelineState>>();
                foreach (var timeline in this._constraintTimelines)
                { // Create constraint timelines map.
                    var timelineName = timeline.constraint.name;
                    if (!(constraintTimelines.ContainsKey(timelineName)))
                    {
                        constraintTimelines[timelineName] = new List<ConstraintTimelineState>();
                    }

                    constraintTimelines[timelineName].Add(timeline);
                }

                foreach (var constraint in this._armature._constraints)
                {
                    var timelineName = constraint.name;
                    var timelineDatas = this._animationData.GetConstraintTimelines(timelineName);

                    if (constraintTimelines.ContainsKey(timelineName))
                    {
                        // Remove constraint timeline from map.
                        constraintTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new constraint timeline.
                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.IKConstraint:
                                        {
                                            var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
                                            timeline.constraint = constraint;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._constraintTimelines.Add(timeline);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }
                        else if (this.resetToPose)
                        {
                            // Pose timeline.
                            var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
                            timeline.constraint = constraint;
                            timeline.Init(this._armature, this, null);
                            this._constraintTimelines.Add(timeline);
                            this._poseTimelines.Add(timeline);
                        }
                    }
                }

                foreach (var timelines in constraintTimelines.Values)
                { // Remove constraint timelines.
                    foreach (var timeline in timelines)
                    {
                        this._constraintTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }
        }
        private void _AdvanceFadeTime(float passedTime)
        {
            var isFadeOut = this._fadeState > 0;

            if (this._subFadeState < 0)
            {
                // Fade start event.
                this._subFadeState = 0;

                var eventType = isFadeOut ? EventObject.FADE_OUT : EventObject.FADE_IN;
                if (this._armature.eventDispatcher.HasDBEventListener(eventType))
                {
                    var eventObject = BaseObject.BorrowObject<EventObject>();
                    eventObject.type = eventType;
                    eventObject.armature = this._armature;
                    eventObject.animationState = this;
                    this._armature._dragonBones.BufferEvent(eventObject);
                }
            }

            if (passedTime < 0.0f)
            {
                passedTime = -passedTime;
            }

            this._fadeTime += passedTime;

            if (this._fadeTime >= this.fadeTotalTime)
            {
                // Fade complete.
                this._subFadeState = 1;
                this._fadeProgress = isFadeOut ? 0.0f : 1.0f;
            }
            else if (this._fadeTime > 0.0f)
            {
                // Fading.
                this._fadeProgress = isFadeOut ? (1.0f - this._fadeTime / this.fadeTotalTime) : (this._fadeTime / this.fadeTotalTime);
            }
            else
            {
                // Before fade.
                this._fadeProgress = isFadeOut ? 1.0f : 0.0f;
            }

            if (this._subFadeState > 0)
            {
                // Fade complete event.
                if (!isFadeOut)
                {
                    this._playheadState |= 1; // x1
                    this._fadeState = 0;
                }

                var eventType = isFadeOut ? EventObject.FADE_OUT_COMPLETE : EventObject.FADE_IN_COMPLETE;
                if (this._armature.eventDispatcher.HasDBEventListener(eventType))
                {
                    var eventObject = BaseObject.BorrowObject<EventObject>();
                    eventObject.type = eventType;
                    eventObject.armature = this._armature;
                    eventObject.animationState = this;
                    this._armature._dragonBones.BufferEvent(eventObject);
                }
            }
        }

        /// <internal/>
        /// <private/>
        internal void Init(Armature armature, AnimationData animationData, AnimationConfig animationConfig)
        {
            if (this._armature != null)
            {
                return;
            }

            this._armature = armature;

            this._animationData = animationData;
            this.resetToPose = animationConfig.resetToPose;
            this.additiveBlending = animationConfig.additiveBlending;
            this.displayControl = animationConfig.displayControl;
            this.actionEnabled = animationConfig.actionEnabled;
            this.layer = animationConfig.layer;
            this.playTimes = animationConfig.playTimes;
            this.timeScale = animationConfig.timeScale;
            this.fadeTotalTime = animationConfig.fadeInTime;
            this.autoFadeOutTime = animationConfig.autoFadeOutTime;
            this.weight = animationConfig.weight;
            this.name = animationConfig.name.Length > 0 ? animationConfig.name : animationConfig.animation;
            this.group = animationConfig.group;

            if (animationConfig.pauseFadeIn)
            {
                this._playheadState = 2; // 10
            }
            else
            {
                this._playheadState = 3; // 11
            }

            if (animationConfig.duration < 0.0f)
            {
                this._position = 0.0f;
                this._duration = this._animationData.duration;
                if (animationConfig.position != 0.0f)
                {
                    if (this.timeScale >= 0.0f)
                    {
                        this._time = animationConfig.position;
                    }
                    else
                    {
                        this._time = animationConfig.position - this._duration;
                    }
                }
                else
                {
                    this._time = 0.0f;
                }
            }
            else
            {
                this._position = animationConfig.position;
                this._duration = animationConfig.duration;
                this._time = 0.0f;
            }

            if (this.timeScale < 0.0f && this._time == 0.0f)
            {
                this._time = -0.000001f; // Turn to end.
            }

            if (this.fadeTotalTime <= 0.0f)
            {
                this._fadeProgress = 0.999999f; // Make different.
            }

            if (animationConfig.boneMask.Count > 0)
            {
                this._boneMask.ResizeList(animationConfig.boneMask.Count);
                for (int i = 0, l = this._boneMask.Count; i < l; ++i)
                {
                    this._boneMask[i] = animationConfig.boneMask[i];
                }
            }

            this._actionTimeline = BaseObject.BorrowObject<ActionTimelineState>();
            this._actionTimeline.Init(this._armature, this, this._animationData.actionTimeline);
            this._actionTimeline.currentTime = this._time;
            if (this._actionTimeline.currentTime < 0.0f)
            {
                this._actionTimeline.currentTime = this._duration - this._actionTimeline.currentTime;
            }

            if (this._animationData.zOrderTimeline != null)
            {
                this._zOrderTimeline = BaseObject.BorrowObject<ZOrderTimelineState>();
                this._zOrderTimeline.Init(this._armature, this, this._animationData.zOrderTimeline);
            }
        }
        /// <internal/>
        /// <private/>
        internal void AdvanceTime(float passedTime, float cacheFrameRate)
        {
            this._blendState.dirty = true;
            
            // Update fade time.
            if (this._fadeState != 0 || this._subFadeState != 0)
            {
                this._AdvanceFadeTime(passedTime);
            }

            // Update time.
            if (this._playheadState == 3)
            {
                // 11
                if (this.timeScale != 1.0f)
                {
                    passedTime *= this.timeScale;
                }

                this._time += passedTime;
            }

            if (this._timelineDirty)
            {
                this._timelineDirty = false;
                this._UpdateTimelines();
            }

            if (this.weight == 0.0f)
            {
                return;
            }

            var isCacheEnabled = this._fadeState == 0 && cacheFrameRate > 0.0f;
            var isUpdateTimeline = true;
            var isUpdateBoneTimeline = true;
            var time = this._time;
            this._weightResult = this.weight * this._fadeProgress;

            if (this._actionTimeline.playState <= 0)
            {
                // Update main timeline.
                this._actionTimeline.Update(time);
            }

            if (isCacheEnabled)
            {
                // Cache time internval.
                var internval = cacheFrameRate * 2.0f;
                this._actionTimeline.currentTime = (float)Math.Floor(this._actionTimeline.currentTime * internval) / internval;
            }

            if (this._zOrderTimeline != null && this._zOrderTimeline.playState <= 0)
            {
                // Update zOrder timeline.
                this._zOrderTimeline.Update(time);
            }

            if (isCacheEnabled)
            {
                // Update cache.
                var cacheFrameIndex = (int)Math.Floor(this._actionTimeline.currentTime * cacheFrameRate); // uint
                if (this._armature._cacheFrameIndex == cacheFrameIndex)
                {
                    // Same cache.
                    isUpdateTimeline = false;
                    isUpdateBoneTimeline = false;
                }
                else
                {
                    this._armature._cacheFrameIndex = cacheFrameIndex;
                    if (this._animationData.cachedFrames[cacheFrameIndex])
                    {
                        // Cached.
                        isUpdateBoneTimeline = false;
                    }
                    else
                    {
                        // Cache.
                        this._animationData.cachedFrames[cacheFrameIndex] = true;
                    }
                }
            }

            if (isUpdateTimeline)
            {
                if (isUpdateBoneTimeline)
                {
                    for (int i = 0, l = this._boneTimelines.Count; i < l; ++i)
                    {
                        var timeline = this._boneTimelines[i];

                        if(timeline.playState <= 0)
                        {
                            timeline.Update(time);
                        }

                        if (i == l - 1 || timeline.bone != this._boneTimelines[i + 1].bone) {
                            var state = timeline.bone._blendState.Update(this._weightResult, this.layer);
                            if (state != 0)
                            {
                                timeline.Blend(state);
                            }
                        }
                    }
                }

                if (this.displayControl)
                {
                    for (int i = 0, l = this._slotTimelines.Count; i < l; ++i)
                    {
                        var timeline = this._slotTimelines[i];
                        var displayController = timeline.slot.displayController;

                        if (
                            displayController == null ||
                            displayController == this.name ||
                            displayController == this.group
                        )
                        {
                            if (timeline.playState <= 0)
                            {
                                timeline.Update(time);
                            }
                        }
                    }
                }

                for (int i = 0, l = this._constraintTimelines.Count; i < l; ++i)
                {
                    var timeline = this._constraintTimelines[i];
                    if (timeline.playState <= 0)
                    {
                        timeline.Update(time);
                    }
                }
            }

            if (this._fadeState == 0)
            {
                if (this._subFadeState > 0)
                {
                    this._subFadeState = 0;

                    if (this._poseTimelines.Count > 0)
                    {
                        foreach (var timeline in this._poseTimelines)
                        {
                            if (timeline is BoneTimelineState)
                            {
                                this._boneTimelines.Remove(timeline as BoneTimelineState);
                            }
                            else if (timeline is SlotTimelineState)
                            {
                                this._slotTimelines.Remove(timeline as SlotTimelineState);
                            }
                            else if (timeline is ConstraintTimelineState)
                            {
                                this._constraintTimelines.Remove(timeline as ConstraintTimelineState);
                            }

                            timeline.ReturnToPool();
                        }

                        this._poseTimelines.Clear();
                    }
                }

                if (this._actionTimeline.playState > 0)
                {
                    if (this.autoFadeOutTime >= 0.0f)
                    {
                        // Auto fade out.
                        this.FadeOut(this.autoFadeOutTime);
                    }
                }
            }
        }

        /// <summary>
        /// - Continue play.
        /// </summary>
        /// <version>DragonBones 3.0</version>
        /// <language>en_US</language>

        /// <summary>
        /// - 继续播放。
        /// </summary>
        /// <version>DragonBones 3.0</version>
        /// <language>zh_CN</language>
        public void Play()
        {
            this._playheadState = 3; // 11
        }

		public static int Comparer(USTimelineContainer a, USTimelineContainer b)
		{
			return (a.Index.CompareTo(b.Index));
		}

		#endregion
		
		private void Start()
		{
			if(affectedObjectPath == null)
			{
				affectedObjectPath = string.Empty;
			}
			else
			{
				if(AffectedObject == null && affectedObjectPath.Length != 0)
				{
					var affectedGameObject = GameObject.Find(affectedObjectPath);
					AffectedObject = affectedGameObject.transform;
				}
			}

			foreach(var timeline in Timelines)
			{
				var propertyTimeline = timeline as USTimelineProperty;
				if(!propertyTimeline)
				{
					continue;
				}

				propertyTimeline.TryToFixComponentReferences();
			}
		}
		
		public void AddNewTimeline(USTimelineBase timeline)
		{	
			transform.parent = transform;
		}
		
		public void ProcessTimelines(float sequencerTime, float playbackRate)
		{
			if(!gameObject.activeInHierarchy)
				return;

			foreach(var timeline in Timelines)
				timeline.Process(sequencerTime, playbackRate);
		}
		
		public void SkipTimelineTo(float sequencerTime)
		{
			foreach(var timeline in Timelines)
				timeline.SkipTimelineTo(sequencerTime);
		}
		
		public void ManuallySetTime(float sequencerTime)
		{
			foreach(var timeline in Timelines)
				timeline.ManuallySetTime(sequencerTime);
		}

        /// <private/>
        protected override void _OnClear()
        {
            foreach (var timeline in this._boneTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var timeline in this._slotTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var timeline in this._constraintTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var bonePose in this._bonePoses.Values)
            {
                bonePose.ReturnToPool();
            }

            if (this._actionTimeline != null)
            {
                this._actionTimeline.ReturnToPool();
            }

            if (this._zOrderTimeline != null)
            {
                this._zOrderTimeline.ReturnToPool();
            }

            this.actionEnabled = false;
            this.additiveBlending = false;
            this.displayControl = false;
            this.resetToPose = false;
            this.playTimes = 1;
            this.layer = 0;

            this.timeScale = 1.0f;
            this.weight = 1.0f;
            this.autoFadeOutTime = 0.0f;
            this.fadeTotalTime = 0.0f;
            this.name = string.Empty;
            this.group = string.Empty;

            this._timelineDirty = 2;
            this._playheadState = 0;
            this._fadeState = -1;
            this._subFadeState = -1;
            this._position = 0.0f;
            this._duration = 0.0f;
            this._fadeTime = 0.0f;
            this._time = 0.0f;
            this._fadeProgress = 0.0f;
            this._weightResult = 0.0f;
            this._blendState.Clear();
            this._boneMask.Clear();
            this._boneTimelines.Clear();
            this._slotTimelines.Clear();
            this._constraintTimelines.Clear();
            this._bonePoses.Clear();
            this._animationData = null; //
            this._armature = null; //
            this._actionTimeline = null; //
            this._zOrderTimeline = null;
            this._parent = null;
        }

        private void _UpdateTimelines()
        {
            { // Update constraint timelines.
                foreach (var constraint in this._armature._constraints)
                {
                    var timelineDatas = this._animationData.GetConstraintTimelines(constraint.name);

                    if (timelineDatas != null)
                    {
                        foreach (var timelineData in timelineDatas)
                        {
                            switch (timelineData.type)
                            {
                                case TimelineType.IKConstraint:
                                    {
                                        var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
                                        timeline.constraint = constraint;
                                        timeline.Init(this._armature, this, timelineData);
                                        this._constraintTimelines.Add(timeline);
                                        break;
                                    }

                                default:
                                    break;
                            }
                        }
                    }
                    else if (this.resetToPose)
                    { // Pose timeline.
                        var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
                        timeline.constraint = constraint;
                        timeline.Init(this._armature, this, null);
                        this._constraintTimelines.Add(timeline);
                        this._poseTimelines.Add(timeline);
                    }
                }
            }
        }

        private void _UpdateBoneAndSlotTimelines()
        {
            { // Update bone timelines.
                Dictionary<string, List<BoneTimelineState>> boneTimelines = new Dictionary<string, List<BoneTimelineState>>();

                foreach (var timeline in this._boneTimelines)
                {
                    // Create bone timelines map.
                    var timelineName = timeline.bone.name;
                    if (!(boneTimelines.ContainsKey(timelineName)))
                    {
                        boneTimelines[timelineName] = new List<BoneTimelineState>();
                    }

                    boneTimelines[timelineName].Add(timeline);
                }

                foreach (var bone in this._armature.GetBones())
                {
                    var timelineName = bone.name;
                    if (!this.ContainsBoneMask(timelineName))
                    {
                        continue;
                    }

                    var timelineDatas = this._animationData.GetBoneTimelines(timelineName);
                    if (boneTimelines.ContainsKey(timelineName))
                    {
                        // Remove bone timeline from map.
                        boneTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new bone timeline.
                        var bonePose = this._bonePoses.ContainsKey(timelineName) ? this._bonePoses[timelineName] : (this._bonePoses[timelineName] = BaseObject.BorrowObject<BonePose>());
                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.BoneAll:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneTranslate:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneTranslateTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneRotate:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneRotateTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneScale:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneScaleTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }
                        else if (this.resetToPose)
                        { // Pose timeline.
                            var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
                            timeline.bone = bone;
                            timeline.bonePose = bonePose;
                            timeline.Init(this._armature, this, null);
                            this._boneTimelines.Add(timeline);
                            this._poseTimelines.Add(timeline);
                        }
                    }
                }

                foreach (var timelines in boneTimelines.Values)
                {
                    // Remove bone timelines.
                    foreach (var timeline in timelines)
                    {
                        this._boneTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }

            { // Update slot timelines.
                Dictionary<string, List<SlotTimelineState>> slotTimelines = new Dictionary<string, List<SlotTimelineState>>();
                List<int> ffdFlags = new List<int>();

                foreach (var timeline in this._slotTimelines)
                {
                    // Create slot timelines map.
                    var timelineName = timeline.slot.name;
                    if (!(slotTimelines.ContainsKey(timelineName)))
                    {
                        slotTimelines[timelineName] = new List<SlotTimelineState>();
                    }

                    slotTimelines[timelineName].Add(timeline);
                }

                foreach (var slot in this._armature.GetSlots())
                {
                    var boneName = slot.parent.name;
                    if (!this.ContainsBoneMask(boneName))
                    {
                        continue;
                    }

                    var timelineName = slot.name;
                    var timelineDatas = this._animationData.GetSlotTimelines(timelineName);

                    if (slotTimelines.ContainsKey(timelineName))
                    {
                        // Remove slot timeline from map.
                        slotTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new slot timeline.
                        var displayIndexFlag = false;
                        var colorFlag = false;
                        ffdFlags.Clear();

                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.SlotDisplay:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            displayIndexFlag = true;
                                            break;
                                        }
                                    case TimelineType.SlotColor:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            colorFlag = true;
                                            break;
                                        }
                                    case TimelineType.SlotDeform:
                                        {
                                            var timeline = BaseObject.BorrowObject<DeformTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            ffdFlags.Add((int)timeline.vertexOffset);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }

                        if (this.resetToPose)
                        {
                            // Pose timeline.
                            if (!displayIndexFlag)
                            {
                                var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
                                timeline.slot = slot;
                                timeline.Init(this._armature, this, null);
                                this._slotTimelines.Add(timeline);
                                this._poseTimelines.Add(timeline);
                            }

                            if (!colorFlag)
                            {
                                var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
                                timeline.slot = slot;
                                timeline.Init(this._armature, this, null);
                                this._slotTimelines.Add(timeline);
                                this._poseTimelines.Add(timeline);
                            }

                            if (slot.rawDisplayDatas != null)
                            {
                                foreach (var displayData in slot.rawDisplayDatas)
                                {
                                    if (displayData != null && displayData.type == DisplayType.Mesh)
                                    {
                                        var meshOffset = (displayData as MeshDisplayData).vertices.offset;
                                        if (!ffdFlags.Contains(meshOffset))
                                        {
                                            var timeline = BaseObject.BorrowObject<DeformTimelineState>();
                                            timeline.vertexOffset = meshOffset; //
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, null);
                                            this._slotTimelines.Add(timeline);
                                            this._poseTimelines.Add(timeline);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (var timelines in slotTimelines.Values)
                {
                    // Remove slot timelines.
                    foreach (var timeline in timelines)
                    {
                        this._slotTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }

            // {
            //     // Update constraint timelines.
            //     Dictionary<string, List<ConstraintTimelineState>> constraintTimelines = new Dictionary<string, List<ConstraintTimelineState>>();
            //     foreach (var timeline in this._constraintTimelines)
            //     { // Create constraint timelines map.
            //         var timelineName = timeline.constraint.name;
            //         if (!(constraintTimelines.ContainsKey(timelineName)))
            //         {
            //             constraintTimelines[timelineName] = new List<ConstraintTimelineState>();
            //         }

            //         constraintTimelines[timelineName].Add(timeline);
            //     }

            //     foreach (var constraint in this._armature._constraints)
            //     {
            //         var timelineName = constraint.name;
            //         var timelineDatas = this._animationData.GetConstraintTimelines(timelineName);

            //         if (constraintTimelines.ContainsKey(timelineName))
            //         {
            //             // Remove constraint timeline from map.
            //             constraintTimelines.Remove(timelineName);
            //         }
            //         else
            //         {
            //             // Create new constraint timeline.
            //             if (timelineDatas != null)
            //             {
            //                 foreach (var timelineData in timelineDatas)
            //                 {
            //                     switch (timelineData.type)
            //                     {
            //                         case TimelineType.IKConstraint:
            //                             {
            //                                 var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
            //                                 timeline.constraint = constraint;
            //                                 timeline.Init(this._armature, this, timelineData);
            //                                 this._constraintTimelines.Add(timeline);
            //                                 break;
            //                             }

            //                         default:
            //                             break;
            //                     }
            //                 }
            //             }
            //             else if (this.resetToPose)
            //             {
            //                 // Pose timeline.
            //                 var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
            //                 timeline.constraint = constraint;
            //                 timeline.Init(this._armature, this, null);
            //                 this._constraintTimelines.Add(timeline);
            //                 this._poseTimelines.Add(timeline);
            //             }
            //         }
            //     }

            //     foreach (var timelines in constraintTimelines.Values)
            //     { // Remove constraint timelines.
            //         foreach (var timeline in timelines)
            //         {
            //             this._constraintTimelines.Remove(timeline);
            //             timeline.ReturnToPool();
            //         }
            //     }
            // }
        }

        private void _AdvanceFadeTime(float passedTime)
        {
            var isFadeOut = this._fadeState > 0;

            if (this._subFadeState < 0)
            {
                // Fade start event.
                this._subFadeState = 0;

                var eventType = isFadeOut ? EventObject.FADE_OUT : EventObject.FADE_IN;
                if (this._armature.eventDispatcher.HasDBEventListener(eventType))
                {
                    var eventObject = BaseObject.BorrowObject<EventObject>();
                    eventObject.type = eventType;
                    eventObject.armature = this._armature;
                    eventObject.animationState = this;
                    this._armature._dragonBones.BufferEvent(eventObject);
                }
            }

            if (passedTime < 0.0f)
            {
                passedTime = -passedTime;
            }

            this._fadeTime += passedTime;

            if (this._fadeTime >= this.fadeTotalTime)
            {
                // Fade complete.
                this._subFadeState = 1;
                this._fadeProgress = isFadeOut ? 0.0f : 1.0f;
            }
            else if (this._fadeTime > 0.0f)
            {
                // Fading.
                this._fadeProgress = isFadeOut ? (1.0f - this._fadeTime / this.fadeTotalTime) : (this._fadeTime / this.fadeTotalTime);
            }
            else
            {
                // Before fade.
                this._fadeProgress = isFadeOut ? 1.0f : 0.0f;
            }

            if (this._subFadeState > 0)
            {
                // Fade complete event.
                if (!isFadeOut)
                {
                    this._playheadState |= 1; // x1
                    this._fadeState = 0;
                }

                var eventType = isFadeOut ? EventObject.FADE_OUT_COMPLETE : EventObject.FADE_IN_COMPLETE;
                if (this._armature.eventDispatcher.HasDBEventListener(eventType))
                {
                    var eventObject = BaseObject.BorrowObject<EventObject>();
                    eventObject.type = eventType;
                    eventObject.armature = this._armature;
                    eventObject.animationState = this;
                    this._armature._dragonBones.BufferEvent(eventObject);
                }
            }
        }

        /// <internal/>
        /// <private/>
        internal void Init(Armature armature, AnimationData animationData, AnimationConfig animationConfig)
        {
            if (this._armature != null)
            {
                return;
            }

            this._armature = armature;

            this._animationData = animationData;
            this.resetToPose = animationConfig.resetToPose;
            this.additiveBlending = animationConfig.additiveBlending;
            this.displayControl = animationConfig.displayControl;
            this.actionEnabled = animationConfig.actionEnabled;
            this.layer = animationConfig.layer;
            this.playTimes = animationConfig.playTimes;
            this.timeScale = animationConfig.timeScale;
            this.fadeTotalTime = animationConfig.fadeInTime;
            this.autoFadeOutTime = animationConfig.autoFadeOutTime;
            this.weight = animationConfig.weight;
            this.name = animationConfig.name.Length > 0 ? animationConfig.name : animationConfig.animation;
            this.group = animationConfig.group;

            if (animationConfig.pauseFadeIn)
            {
                this._playheadState = 2; // 10
            }
            else
            {
                this._playheadState = 3; // 11
            }

            if (animationConfig.duration < 0.0f)
            {
                this._position = 0.0f;
                this._duration = this._animationData.duration;
                if (animationConfig.position != 0.0f)
                {
                    if (this.timeScale >= 0.0f)
                    {
                        this._time = animationConfig.position;
                    }
                    else
                    {
                        this._time = animationConfig.position - this._duration;
                    }
                }
                else
                {
                    this._time = 0.0f;
                }
            }
            else
            {
                this._position = animationConfig.position;
                this._duration = animationConfig.duration;
                this._time = 0.0f;
            }

            if (this.timeScale < 0.0f && this._time == 0.0f)
            {
                this._time = -0.000001f; // Turn to end.
            }

            if (this.fadeTotalTime <= 0.0f)
            {
                this._fadeProgress = 0.999999f; // Make different.
            }

            if (animationConfig.boneMask.Count > 0)
            {
                this._boneMask.ResizeList(animationConfig.boneMask.Count);
                for (int i = 0, l = this._boneMask.Count; i < l; ++i)
                {
                    this._boneMask[i] = animationConfig.boneMask[i];
                }
            }

            this._actionTimeline = BaseObject.BorrowObject<ActionTimelineState>();
            this._actionTimeline.Init(this._armature, this, this._animationData.actionTimeline);
            this._actionTimeline.currentTime = this._time;
            if (this._actionTimeline.currentTime < 0.0f)
            {
                this._actionTimeline.currentTime = this._duration - this._actionTimeline.currentTime;
            }

            if (this._animationData.zOrderTimeline != null)
            {
                this._zOrderTimeline = BaseObject.BorrowObject<ZOrderTimelineState>();
                this._zOrderTimeline.Init(this._armature, this, this._animationData.zOrderTimeline);
            }
        }
        /// <internal/>
        /// <private/>
        internal void AdvanceTime(float passedTime, float cacheFrameRate)
        {
            this._blendState.dirty = true;

            // Update fade time.
            if (this._fadeState != 0 || this._subFadeState != 0)
            {
                this._AdvanceFadeTime(passedTime);
            }

            // Update time.
            if (this._playheadState == 3)
            {
                // 11
                if (this.timeScale != 1.0f)
                {
                    passedTime *= this.timeScale;
                }

                this._time += passedTime;
            }

            // Update timeline.
            if (this._timelineDirty != 0)
            {
                if (this._timelineDirty == 2)
                {
                    this._UpdateTimelines();
                }

                this._timelineDirty = 0;
                this._UpdateBoneAndSlotTimelines();
            }

            if (this.weight == 0.0f)
            {
                return;
            }

            var isCacheEnabled = this._fadeState == 0 && cacheFrameRate > 0.0f;
            var isUpdateTimeline = true;
            var isUpdateBoneTimeline = true;
            var time = this._time;
            this._weightResult = this.weight * this._fadeProgress;

            if (this._parent != null)
            {
                this._weightResult *= this._parent._weightResult / this._parent._fadeProgress;
            }

            if (this._actionTimeline.playState <= 0)
            {
                // Update main timeline.
                this._actionTimeline.Update(time);
            }

            if (isCacheEnabled)
            {
                // Cache time internval.
                var internval = cacheFrameRate * 2.0f;
                this._actionTimeline.currentTime = (float)Math.Floor(this._actionTimeline.currentTime * internval) / internval;
            }

            if (this._zOrderTimeline != null && this._zOrderTimeline.playState <= 0)
            {
                // Update zOrder timeline.
                this._zOrderTimeline.Update(time);
            }

            if (isCacheEnabled)
            {
                // Update cache.
                var cacheFrameIndex = (int)Math.Floor(this._actionTimeline.currentTime * cacheFrameRate); // uint
                if (this._armature._cacheFrameIndex == cacheFrameIndex)
                {
                    // Same cache.
                    isUpdateTimeline = false;
                    isUpdateBoneTimeline = false;
                }
                else
                {
                    this._armature._cacheFrameIndex = cacheFrameIndex;
                    if (this._animationData.cachedFrames[cacheFrameIndex])
                    {
                        // Cached.
                        isUpdateBoneTimeline = false;
                    }
                    else
                    {
                        // Cache.
                        this._animationData.cachedFrames[cacheFrameIndex] = true;
                    }
                }
            }

            if (isUpdateTimeline)
            {
                if (isUpdateBoneTimeline)
                {
                    for (int i = 0, l = this._boneTimelines.Count; i < l; ++i)
                    {
                        var timeline = this._boneTimelines[i];

                        if (timeline.playState <= 0)
                        {
                            timeline.Update(time);
                        }

                        if (i == l - 1 || timeline.bone != this._boneTimelines[i + 1].bone)
                        {
                            var state = timeline.bone._blendState.Update(this._weightResult, this.layer);
                            if (state != 0)
                            {
                                timeline.Blend(state);
                            }
                        }
                    }
                }

                if (this.displayControl)
                {
                    for (int i = 0, l = this._slotTimelines.Count; i < l; ++i)
                    {
                        var timeline = this._slotTimelines[i];
                        var displayController = timeline.slot.displayController;

                        if (
                            displayController == null ||
                            displayController == this.name ||
                            displayController == this.group
                        )
                        {
                            if (timeline.playState <= 0)
                            {
                                timeline.Update(time);
                            }
                        }
                    }
                }

                for (int i = 0, l = this._constraintTimelines.Count; i < l; ++i)
                {
                    var timeline = this._constraintTimelines[i];
                    if (timeline.playState <= 0)
                    {
                        timeline.Update(time);
                    }
                }
            }

            if (this._fadeState == 0)
            {
                if (this._subFadeState > 0)
                {
                    this._subFadeState = 0;

                    if (this._poseTimelines.Count > 0)
                    {
                        foreach (var timeline in this._poseTimelines)
                        {
                            if (timeline is BoneTimelineState)
                            {
                                this._boneTimelines.Remove(timeline as BoneTimelineState);
                            }
                            else if (timeline is SlotTimelineState)
                            {
                                this._slotTimelines.Remove(timeline as SlotTimelineState);
                            }
                            else if (timeline is ConstraintTimelineState)
                            {
                                this._constraintTimelines.Remove(timeline as ConstraintTimelineState);
                            }

                            timeline.ReturnToPool();
                        }

                        this._poseTimelines.Clear();
                    }
                }

                if (this._actionTimeline.playState > 0)
                {
                    if (this.autoFadeOutTime >= 0.0f)
                    {
                        // Auto fade out.
                        this.FadeOut(this.autoFadeOutTime);
                    }
                }
            }
        }


        public void Apply(Skeleton skeleton, float lastTime, float time, bool loop, ExposedList<Event> events, float alpha, MixPose pose, MixDirection direction)
        {
            if (skeleton == null)
            {
                throw new ArgumentNullException("skeleton", "skeleton cannot be null.");
            }
            if (loop && (this.duration != 0f))
            {
                time = time % this.duration;
                if (lastTime > 0f)
                {
                    lastTime = lastTime % this.duration;
                }
            }
            ExposedList<Timeline> timelines = this.timelines;
            int index = 0;
            int count = timelines.Count;
            while (index < count)
            {
                timelines.Items[index].Apply(skeleton, lastTime, time, events, alpha, pose, direction);
                index++;
            }
        }

        internal static int BinarySearch(float[] values, float target)
        {
            int num = 0;
            int num2 = values.Length - 2;
            if (num2 == 0)
            {
                return 1;
            }
            int num3 = num2 >> 1;
            while (true)
            {
                if (values[num3 + 1] <= target)
                {
                    num = num3 + 1;
                }
                else
                {
                    num2 = num3;
                }
                if (num == num2)
                {
                    return (num + 1);
                }
                num3 = (num + num2) >> 1;
            }
        }

        internal static int BinarySearch(float[] values, float target, int step)
        {
            int num = 0;
            int num2 = (values.Length / step) - 2;
            if (num2 == 0)
            {
                return step;
            }
            int num3 = num2 >> 1;
            while (true)
            {
                if (values[(num3 + 1) * step] <= target)
                {
                    num = num3 + 1;
                }
                else
                {
                    num2 = num3;
                }
                if (num == num2)
                {
                    return ((num + 1) * step);
                }
                num3 = (num + num2) >> 1;
            }
        }

        internal static int LinearSearch(float[] values, float target, int step)
        {
            int index = 0;
            int num2 = values.Length - step;
            while (index <= num2)
            {
                if (values[index] > target)
                {
                    return index;
                }
                index += step;
            }
            return -1;
        }


        /// <inheritDoc/>
        protected override void _OnClear()
        {
            foreach (var pair in boneTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            foreach (var pair in slotTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            foreach (var pair in constraintTimelines)
            {
                for (int i = 0; i < pair.Value.Count; ++i)
                {
                    pair.Value[i].ReturnToPool();
                }
            }

            if (this.actionTimeline != null)
            {
                this.actionTimeline.ReturnToPool();
            }

            if (this.zOrderTimeline != null)
            {
                this.zOrderTimeline.ReturnToPool();
            }

            this.frameIntOffset = 0;
            this.frameFloatOffset = 0;
            this.frameOffset = 0;
            this.frameCount = 0;
            this.playTimes = 0;
            this.duration = 0.0f;
            this.scale = 1.0f;
            this.fadeInTime = 0.0f;
            this.cacheFrameRate = 0.0f;
            this.name = "";
            this.boneTimelines.Clear();
            this.slotTimelines.Clear();
            this.constraintTimelines.Clear();
            this.boneCachedFrameIndices.Clear();
            this.slotCachedFrameIndices.Clear();
            this.cachedFrames.Clear();

            this.actionTimeline = null;
            this.zOrderTimeline = null;
            this.parent = null;
        }

        /// <internal/>
        /// <private/>
        public void CacheFrames(float frameRate)
        {
            if (this.cacheFrameRate > 0.0f)
            {
                // TODO clear cache.
                return;
            }

            this.cacheFrameRate = Math.Max((float)Math.Ceiling(frameRate * scale), 1.0f);
            var cacheFrameCount = (int)Math.Ceiling(this.cacheFrameRate * duration) + 1; // Cache one more frame.

            cachedFrames.ResizeList(0, false);
            cachedFrames.ResizeList(cacheFrameCount, false);

            foreach (var bone in this.parent.sortedBones)
            {
                var indices = new List<int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                this.boneCachedFrameIndices[bone.name] = indices;
            }

            foreach (var slot in this.parent.sortedSlots)
            {
                var indices = new List<int>(cacheFrameCount);
                for (int i = 0, l = indices.Capacity; i < l; ++i)
                {
                    indices.Add(-1);
                }

                this.slotCachedFrameIndices[slot.name] = indices;
            }
        }

        /// <private/>
        public void AddBoneTimeline(BoneData bone, TimelineData tiemline)
        {
            if (bone == null || tiemline == null)
            {
                return;
            }

            if (!this.boneTimelines.ContainsKey(bone.name))
            {
                this.boneTimelines[bone.name] = new List<TimelineData>();
            }

            var timelines = this.boneTimelines[bone.name];
            if (!timelines.Contains(tiemline))
            {
                timelines.Add(tiemline);
            }
        }
        /// <private/>
        public void AddSlotTimeline(SlotData slot, TimelineData timeline)
        {
            if (slot == null || timeline == null)
            {
                return;
            }

            if (!this.slotTimelines.ContainsKey(slot.name))
            {
                this.slotTimelines[slot.name] = new List<TimelineData>();
            }

            var timelines = this.slotTimelines[slot.name];
            if (!timelines.Contains(timeline))
            {
                timelines.Add(timeline);
            }
        }

        /// <private/>
        public void AddConstraintTimeline(ConstraintData constraint, TimelineData timeline)
        {
            if (constraint == null || timeline == null)
            {
                return;
            }

            if (!this.constraintTimelines.ContainsKey(constraint.name))
            {
                this.constraintTimelines[constraint.name] = new List<TimelineData>();
            }

            var timelines = this.constraintTimelines[constraint.name];
            if (!timelines.Contains(timeline))
            {
                timelines.Add(timeline);
            }
        }

        /// <private/>
        public List<TimelineData> GetBoneTimelines(string timelineName)
        {
            return this.boneTimelines.ContainsKey(timelineName) ? this.boneTimelines[timelineName] : null;
        }

        /// <private/>
        protected override void _OnClear()
        {
            foreach (var timeline in this._boneTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var timeline in this._slotTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var timeline in this._constraintTimelines)
            {
                timeline.ReturnToPool();
            }

            foreach (var bonePose in this._bonePoses.Values)
            {
                bonePose.ReturnToPool();
            }

            if (this._actionTimeline != null)
            {
                this._actionTimeline.ReturnToPool();
            }

            if (this._zOrderTimeline != null)
            {
                this._zOrderTimeline.ReturnToPool();
            }

            this.actionEnabled = false;
            this.additiveBlending = false;
            this.displayControl = false;
            this.resetToPose = false;
            this.playTimes = 1;
            this.layer = 0;

            this.timeScale = 1.0f;
            this.weight = 1.0f;
            this.autoFadeOutTime = 0.0f;
            this.fadeTotalTime = 0.0f;
            this.name = string.Empty;
            this.group = string.Empty;

            this._timelineDirty = 2;
            this._playheadState = 0;
            this._fadeState = -1;
            this._subFadeState = -1;
            this._position = 0.0f;
            this._duration = 0.0f;
            this._fadeTime = 0.0f;
            this._time = 0.0f;
            this._fadeProgress = 0.0f;
            this._weightResult = 0.0f;
            this._blendState.Clear();
            this._boneMask.Clear();
            this._boneTimelines.Clear();
            this._slotTimelines.Clear();
            this._constraintTimelines.Clear();
            this._bonePoses.Clear();
            this._animationData = null; //
            this._armature = null; //
            this._actionTimeline = null; //
            this._zOrderTimeline = null;
            this._parent = null;
        }

        private void _UpdateTimelines()
        {
            { // Update constraint timelines.
                foreach (var constraint in this._armature._constraints)
                {
                    var timelineDatas = this._animationData.GetConstraintTimelines(constraint.name);

                    if (timelineDatas != null)
                    {
                        foreach (var timelineData in timelineDatas)
                        {
                            switch (timelineData.type)
                            {
                                case TimelineType.IKConstraint:
                                    {
                                        var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
                                        timeline.constraint = constraint;
                                        timeline.Init(this._armature, this, timelineData);
                                        this._constraintTimelines.Add(timeline);
                                        break;
                                    }

                                default:
                                    break;
                            }
                        }
                    }
                    else if (this.resetToPose)
                    { // Pose timeline.
                        var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
                        timeline.constraint = constraint;
                        timeline.Init(this._armature, this, null);
                        this._constraintTimelines.Add(timeline);
                        this._poseTimelines.Add(timeline);
                    }
                }
            }
        }

        private void _UpdateBoneAndSlotTimelines()
        {
            { // Update bone timelines.
                Dictionary<string, List<BoneTimelineState>> boneTimelines = new Dictionary<string, List<BoneTimelineState>>();

                foreach (var timeline in this._boneTimelines)
                {
                    // Create bone timelines map.
                    var timelineName = timeline.bone.name;
                    if (!(boneTimelines.ContainsKey(timelineName)))
                    {
                        boneTimelines[timelineName] = new List<BoneTimelineState>();
                    }

                    boneTimelines[timelineName].Add(timeline);
                }

                foreach (var bone in this._armature.GetBones())
                {
                    var timelineName = bone.name;
                    if (!this.ContainsBoneMask(timelineName))
                    {
                        continue;
                    }

                    var timelineDatas = this._animationData.GetBoneTimelines(timelineName);
                    if (boneTimelines.ContainsKey(timelineName))
                    {
                        // Remove bone timeline from map.
                        boneTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new bone timeline.
                        var bonePose = this._bonePoses.ContainsKey(timelineName) ? this._bonePoses[timelineName] : (this._bonePoses[timelineName] = BaseObject.BorrowObject<BonePose>());
                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.BoneAll:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneTranslate:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneTranslateTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneRotate:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneRotateTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }
                                    case TimelineType.BoneScale:
                                        {
                                            var timeline = BaseObject.BorrowObject<BoneScaleTimelineState>();
                                            timeline.bone = bone;
                                            timeline.bonePose = bonePose;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._boneTimelines.Add(timeline);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }
                        else if (this.resetToPose)
                        { // Pose timeline.
                            var timeline = BaseObject.BorrowObject<BoneAllTimelineState>();
                            timeline.bone = bone;
                            timeline.bonePose = bonePose;
                            timeline.Init(this._armature, this, null);
                            this._boneTimelines.Add(timeline);
                            this._poseTimelines.Add(timeline);
                        }
                    }
                }

                foreach (var timelines in boneTimelines.Values)
                {
                    // Remove bone timelines.
                    foreach (var timeline in timelines)
                    {
                        this._boneTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }

            { // Update slot timelines.
                Dictionary<string, List<SlotTimelineState>> slotTimelines = new Dictionary<string, List<SlotTimelineState>>();
                List<int> ffdFlags = new List<int>();

                foreach (var timeline in this._slotTimelines)
                {
                    // Create slot timelines map.
                    var timelineName = timeline.slot.name;
                    if (!(slotTimelines.ContainsKey(timelineName)))
                    {
                        slotTimelines[timelineName] = new List<SlotTimelineState>();
                    }

                    slotTimelines[timelineName].Add(timeline);
                }

                foreach (var slot in this._armature.GetSlots())
                {
                    var boneName = slot.parent.name;
                    if (!this.ContainsBoneMask(boneName))
                    {
                        continue;
                    }

                    var timelineName = slot.name;
                    var timelineDatas = this._animationData.GetSlotTimelines(timelineName);

                    if (slotTimelines.ContainsKey(timelineName))
                    {
                        // Remove slot timeline from map.
                        slotTimelines.Remove(timelineName);
                    }
                    else
                    {
                        // Create new slot timeline.
                        var displayIndexFlag = false;
                        var colorFlag = false;
                        ffdFlags.Clear();

                        if (timelineDatas != null)
                        {
                            foreach (var timelineData in timelineDatas)
                            {
                                switch (timelineData.type)
                                {
                                    case TimelineType.SlotDisplay:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            displayIndexFlag = true;
                                            break;
                                        }
                                    case TimelineType.SlotColor:
                                        {
                                            var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            colorFlag = true;
                                            break;
                                        }
                                    case TimelineType.SlotDeform:
                                        {
                                            var timeline = BaseObject.BorrowObject<DeformTimelineState>();
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, timelineData);
                                            this._slotTimelines.Add(timeline);
                                            ffdFlags.Add((int)timeline.vertexOffset);
                                            break;
                                        }

                                    default:
                                        break;
                                }
                            }
                        }

                        if (this.resetToPose)
                        {
                            // Pose timeline.
                            if (!displayIndexFlag)
                            {
                                var timeline = BaseObject.BorrowObject<SlotDislayTimelineState>();
                                timeline.slot = slot;
                                timeline.Init(this._armature, this, null);
                                this._slotTimelines.Add(timeline);
                                this._poseTimelines.Add(timeline);
                            }

                            if (!colorFlag)
                            {
                                var timeline = BaseObject.BorrowObject<SlotColorTimelineState>();
                                timeline.slot = slot;
                                timeline.Init(this._armature, this, null);
                                this._slotTimelines.Add(timeline);
                                this._poseTimelines.Add(timeline);
                            }

                            if (slot.rawDisplayDatas != null)
                            {
                                foreach (var displayData in slot.rawDisplayDatas)
                                {
                                    if (displayData != null && displayData.type == DisplayType.Mesh)
                                    {
                                        var meshOffset = (displayData as MeshDisplayData).vertices.offset;
                                        if (!ffdFlags.Contains(meshOffset))
                                        {
                                            var timeline = BaseObject.BorrowObject<DeformTimelineState>();
                                            timeline.vertexOffset = meshOffset; //
                                            timeline.slot = slot;
                                            timeline.Init(this._armature, this, null);
                                            this._slotTimelines.Add(timeline);
                                            this._poseTimelines.Add(timeline);
                                        }
                                    }
                                }
                            }
                        }
                    }
                }

                foreach (var timelines in slotTimelines.Values)
                {
                    // Remove slot timelines.
                    foreach (var timeline in timelines)
                    {
                        this._slotTimelines.Remove(timeline);
                        timeline.ReturnToPool();
                    }
                }
            }

            // {
            //     // Update constraint timelines.
            //     Dictionary<string, List<ConstraintTimelineState>> constraintTimelines = new Dictionary<string, List<ConstraintTimelineState>>();
            //     foreach (var timeline in this._constraintTimelines)
            //     { // Create constraint timelines map.
            //         var timelineName = timeline.constraint.name;
            //         if (!(constraintTimelines.ContainsKey(timelineName)))
            //         {
            //             constraintTimelines[timelineName] = new List<ConstraintTimelineState>();
            //         }

            //         constraintTimelines[timelineName].Add(timeline);
            //     }

            //     foreach (var constraint in this._armature._constraints)
            //     {
            //         var timelineName = constraint.name;
            //         var timelineDatas = this._animationData.GetConstraintTimelines(timelineName);

            //         if (constraintTimelines.ContainsKey(timelineName))
            //         {
            //             // Remove constraint timeline from map.
            //             constraintTimelines.Remove(timelineName);
            //         }
            //         else
            //         {
            //             // Create new constraint timeline.
            //             if (timelineDatas != null)
            //             {
            //                 foreach (var timelineData in timelineDatas)
            //                 {
            //                     switch (timelineData.type)
            //                     {
            //                         case TimelineType.IKConstraint:
            //                             {
            //                                 var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
            //                                 timeline.constraint = constraint;
            //                                 timeline.Init(this._armature, this, timelineData);
            //                                 this._constraintTimelines.Add(timeline);
            //                                 break;
            //                             }

            //                         default:
            //                             break;
            //                     }
            //                 }
            //             }
            //             else if (this.resetToPose)
            //             {
            //                 // Pose timeline.
            //                 var timeline = BaseObject.BorrowObject<IKConstraintTimelineState>();
            //                 timeline.constraint = constraint;
            //                 timeline.Init(this._armature, this, null);
            //                 this._constraintTimelines.Add(timeline);
            //                 this._poseTimelines.Add(timeline);
            //             }
            //         }
            //     }

            //     foreach (var timelines in constraintTimelines.Values)
            //     { // Remove constraint timelines.
            //         foreach (var timeline in timelines)
            //         {
            //             this._constraintTimelines.Remove(timeline);
            //             timeline.ReturnToPool();
            //         }
            //     }
            // }
        }

        private void _AdvanceFadeTime(float passedTime)
        {
            var isFadeOut = this._fadeState > 0;

            if (this._subFadeState < 0)
            {
                // Fade start event.
                this._subFadeState = 0;

                var eventType = isFadeOut ? EventObject.FADE_OUT : EventObject.FADE_IN;
                if (this._armature.eventDispatcher.HasDBEventListener(eventType))
                {
                    var eventObject = BaseObject.BorrowObject<EventObject>();
                    eventObject.type = eventType;
                    eventObject.armature = this._armature;
                    eventObject.animationState = this;
                    this._armature._dragonBones.BufferEvent(eventObject);
                }
            }

            if (passedTime < 0.0f)
            {
                passedTime = -passedTime;
            }

            this._fadeTime += passedTime;

            if (this._fadeTime >= this.fadeTotalTime)
            {
                // Fade complete.
                this._subFadeState = 1;
                this._fadeProgress = isFadeOut ? 0.0f : 1.0f;
            }
            else if (this._fadeTime > 0.0f)
            {
                // Fading.
                this._fadeProgress = isFadeOut ? (1.0f - this._fadeTime / this.fadeTotalTime) : (this._fadeTime / this.fadeTotalTime);
            }
            else
            {
                // Before fade.
                this._fadeProgress = isFadeOut ? 1.0f : 0.0f;
            }

            if (this._subFadeState > 0)
            {
                // Fade complete event.
                if (!isFadeOut)
                {
                    this._playheadState |= 1; // x1
                    this._fadeState = 0;
                }

                var eventType = isFadeOut ? EventObject.FADE_OUT_COMPLETE : EventObject.FADE_IN_COMPLETE;
                if (this._armature.eventDispatcher.HasDBEventListener(eventType))
                {
                    var eventObject = BaseObject.BorrowObject<EventObject>();
                    eventObject.type = eventType;
                    eventObject.armature = this._armature;
                    eventObject.animationState = this;
                    this._armature._dragonBones.BufferEvent(eventObject);
                }
            }
        }

        /// <internal/>
        /// <private/>
        internal void Init(Armature armature, AnimationData animationData, AnimationConfig animationConfig)
        {
            if (this._armature != null)
            {
                return;
            }

            this._armature = armature;

            this._animationData = animationData;
            this.resetToPose = animationConfig.resetToPose;
            this.additiveBlending = animationConfig.additiveBlending;
            this.displayControl = animationConfig.displayControl;
            this.actionEnabled = animationConfig.actionEnabled;
            this.layer = animationConfig.layer;
            this.playTimes = animationConfig.playTimes;
            this.timeScale = animationConfig.timeScale;
            this.fadeTotalTime = animationConfig.fadeInTime;
            this.autoFadeOutTime = animationConfig.autoFadeOutTime;
            this.weight = animationConfig.weight;
            this.name = animationConfig.name.Length > 0 ? animationConfig.name : animationConfig.animation;
            this.group = animationConfig.group;

            if (animationConfig.pauseFadeIn)
            {
                this._playheadState = 2; // 10
            }
            else
            {
                this._playheadState = 3; // 11
            }

            if (animationConfig.duration < 0.0f)
            {
                this._position = 0.0f;
                this._duration = this._animationData.duration;
                if (animationConfig.position != 0.0f)
                {
                    if (this.timeScale >= 0.0f)
                    {
                        this._time = animationConfig.position;
                    }
                    else
                    {
                        this._time = animationConfig.position - this._duration;
                    }
                }
                else
                {
                    this._time = 0.0f;
                }
            }
            else
            {
                this._position = animationConfig.position;
                this._duration = animationConfig.duration;
                this._time = 0.0f;
            }

            if (this.timeScale < 0.0f && this._time == 0.0f)
            {
                this._time = -0.000001f; // Turn to end.
            }

            if (this.fadeTotalTime <= 0.0f)
            {
                this._fadeProgress = 0.999999f; // Make different.
            }

            if (animationConfig.boneMask.Count > 0)
            {
                this._boneMask.ResizeList(animationConfig.boneMask.Count);
                for (int i = 0, l = this._boneMask.Count; i < l; ++i)
                {
                    this._boneMask[i] = animationConfig.boneMask[i];
                }
            }

            this._actionTimeline = BaseObject.BorrowObject<ActionTimelineState>();
            this._actionTimeline.Init(this._armature, this, this._animationData.actionTimeline);
            this._actionTimeline.currentTime = this._time;
            if (this._actionTimeline.currentTime < 0.0f)
            {
                this._actionTimeline.currentTime = this._duration - this._actionTimeline.currentTime;
            }

            if (this._animationData.zOrderTimeline != null)
            {
                this._zOrderTimeline = BaseObject.BorrowObject<ZOrderTimelineState>();
                this._zOrderTimeline.Init(this._armature, this, this._animationData.zOrderTimeline);
            }
        }
        /// <internal/>
        /// <private/>
        internal void AdvanceTime(float passedTime, float cacheFrameRate)
        {
            this._blendState.dirty = true;

            // Update fade time.
            if (this._fadeState != 0 || this._subFadeState != 0)
            {
                this._AdvanceFadeTime(passedTime);
            }

            // Update time.
            if (this._playheadState == 3)
            {
                // 11
                if (this.timeScale != 1.0f)
                {
                    passedTime *= this.timeScale;
                }

                this._time += passedTime;
            }

            // Update timeline.
            if (this._timelineDirty != 0)
            {
                if (this._timelineDirty == 2)
                {
                    this._UpdateTimelines();
                }

                this._timelineDirty = 0;
                this._UpdateBoneAndSlotTimelines();
            }

            if (this.weight == 0.0f)
            {
                return;
            }

            var isCacheEnabled = this._fadeState == 0 && cacheFrameRate > 0.0f;
            var isUpdateTimeline = true;
            var isUpdateBoneTimeline = true;
            var time = this._time;
            this._weightResult = this.weight * this._fadeProgress;

            if (this._parent != null)
            {
                this._weightResult *= this._parent._weightResult / this._parent._fadeProgress;
            }

            if (this._actionTimeline.playState <= 0)
            {
                // Update main timeline.
                this._actionTimeline.Update(time);
            }

            if (isCacheEnabled)
            {
                // Cache time internval.
                var internval = cacheFrameRate * 2.0f;
                this._actionTimeline.currentTime = (float)Math.Floor(this._actionTimeline.currentTime * internval) / internval;
            }

            if (this._zOrderTimeline != null && this._zOrderTimeline.playState <= 0)
            {
                // Update zOrder timeline.
                this._zOrderTimeline.Update(time);
            }

            if (isCacheEnabled)
            {
                // Update cache.
                var cacheFrameIndex = (int)Math.Floor(this._actionTimeline.currentTime * cacheFrameRate); // uint
                if (this._armature._cacheFrameIndex == cacheFrameIndex)
                {
                    // Same cache.
                    isUpdateTimeline = false;
                    isUpdateBoneTimeline = false;
                }
                else
                {
                    this._armature._cacheFrameIndex = cacheFrameIndex;
                    if (this._animationData.cachedFrames[cacheFrameIndex])
                    {
                        // Cached.
                        isUpdateBoneTimeline = false;
                    }
                    else
                    {
                        // Cache.
                        this._animationData.cachedFrames[cacheFrameIndex] = true;
                    }
                }
            }

            if (isUpdateTimeline)
            {
                if (isUpdateBoneTimeline)
                {
                    for (int i = 0, l = this._boneTimelines.Count; i < l; ++i)
                    {
                        var timeline = this._boneTimelines[i];

                        if (timeline.playState <= 0)
                        {
                            timeline.Update(time);
                        }

                        if (i == l - 1 || timeline.bone != this._boneTimelines[i + 1].bone)
                        {
                            var state = timeline.bone._blendState.Update(this._weightResult, this.layer);
                            if (state != 0)
                            {
                                timeline.Blend(state);
                            }
                        }
                    }
                }

                if (this.displayControl)
                {
                    for (int i = 0, l = this._slotTimelines.Count; i < l; ++i)
                    {
                        var timeline = this._slotTimelines[i];
                        var displayController = timeline.slot.displayController;

                        if (
                            displayController == null ||
                            displayController == this.name ||
                            displayController == this.group
                        )
                        {
                            if (timeline.playState <= 0)
                            {
                                timeline.Update(time);
                            }
                        }
                    }
                }

                for (int i = 0, l = this._constraintTimelines.Count; i < l; ++i)
                {
                    var timeline = this._constraintTimelines[i];
                    if (timeline.playState <= 0)
                    {
                        timeline.Update(time);
                    }
                }
            }

            if (this._fadeState == 0)
            {
                if (this._subFadeState > 0)
                {
                    this._subFadeState = 0;

                    if (this._poseTimelines.Count > 0)
                    {
                        foreach (var timeline in this._poseTimelines)
                        {
                            if (timeline is BoneTimelineState)
                            {
                                this._boneTimelines.Remove(timeline as BoneTimelineState);
                            }
                            else if (timeline is SlotTimelineState)
                            {
                                this._slotTimelines.Remove(timeline as SlotTimelineState);
                            }
                            else if (timeline is ConstraintTimelineState)
                            {
                                this._constraintTimelines.Remove(timeline as ConstraintTimelineState);
                            }

                            timeline.ReturnToPool();
                        }

                        this._poseTimelines.Clear();
                    }
                }

                if (this._actionTimeline.playState > 0)
                {
                    if (this.autoFadeOutTime >= 0.0f)
                    {
                        // Auto fade out.
                        this.FadeOut(this.autoFadeOutTime);
                    }
                }
            }
        }

DocumentFormat.OpenXml.Office2013.Excel.Timelines : IEnumerable

Constructors :

public Timelines()
public Timelines(IEnumerable<OpenXmlElement> childElements = )
public Timelines(OpenXmlElement[] childElements = )
public Timelines(String outerXml = )

Methods :

public OpenXmlElement CloneNode(Boolean deep = )
public Void Load(TimeLinePart openXmlPart = )
public Void Save(TimeLinePart openXmlPart = )
public TimeLinePart get_TimeLinePart()
public Void Save(Stream stream = )
public Void Save()
public Void Reload()
public Void WriteTo(XmlWriter xmlWriter = )
public OpenXmlElement get_FirstChild()
public OpenXmlElement get_LastChild()
public Boolean get_HasChildren()
public String get_InnerText()
public Void set_InnerXml(String value = )
public Boolean AddChild(OpenXmlElement newChild = , Boolean throwOnError = True)
public T AppendChild(T newChild = )
public T InsertAfter(T newChild = , OpenXmlElement referenceChild = )
public T InsertBefore(T newChild = , OpenXmlElement referenceChild = )
public T InsertAt(T newChild = , Int32 index = )
public T PrependChild(T newChild = )
public T RemoveChild(T child = )
public Void RemoveAllChildren()
public T ReplaceChild(OpenXmlElement newChild = , T oldChild = )
public Void RemoveAllChildren()
public Void Remove()
public Boolean IsAfter(OpenXmlElement element = )
public Boolean IsBefore(OpenXmlElement element = )
public Void AddAnnotation(Object annotation = )
public T Annotation()
public Object Annotation(Type type = )
public IEnumerable<T> Annotations()
public IEnumerable<Object> Annotations(Type type = )
public Void RemoveAnnotations()
public Void RemoveAnnotations(Type type = )
public IEnumerator<OpenXmlElement> GetEnumerator()
public Object Clone()
public MarkupCompatibilityAttributes get_MCAttributes()
public Void set_MCAttributes(MarkupCompatibilityAttributes value = )
public String LookupNamespace(String prefix = )
public String LookupPrefix(String namespaceUri = )
public IFeatureCollection get_Features()
public OpenXmlElementContext get_OpenXmlElementContext()
public Boolean get_HasAttributes()
public IEnumerable<OpenXmlAttribute> get_ExtendedAttributes()
public OpenXmlElementList get_ChildElements()
public OpenXmlElement get_Parent()
public String get_NamespaceUri()
public String get_LocalName()
public String get_Prefix()
public IEnumerable<KeyValuePair<StringString>> get_NamespaceDeclarations()
public XmlQualifiedName get_XmlQualifiedName()
public XName get_XName()
public String get_InnerXml()
public String get_OuterXml()
public OpenXmlAttribute GetAttribute(String localName = , String namespaceUri = )
public IList<OpenXmlAttribute> GetAttributes()
public Void SetAttribute(OpenXmlAttribute openXmlAttribute = )
public Void RemoveAttribute(String localName = , String namespaceUri = )
public Void SetAttributes(IEnumerable<OpenXmlAttribute> openXmlAttributes = )
public Void ClearAllAttributes()
public Void AddNamespaceDeclaration(String prefix = , String uri = )
public Void RemoveNamespaceDeclaration(String prefix = )
public T GetFirstChild()
public OpenXmlElement PreviousSibling()
public T PreviousSibling()
public OpenXmlElement NextSibling()
public T NextSibling()
public IEnumerable<OpenXmlElement> Ancestors()
public IEnumerable<T> Ancestors()
public IEnumerable<T> Elements()
public IEnumerable<OpenXmlElement> Elements()
public IEnumerable<T> Descendants()
public IEnumerable<OpenXmlElement> Descendants()
public IEnumerable<OpenXmlElement> ElementsBefore()
public IEnumerable<OpenXmlElement> ElementsAfter()
public Void Append(IEnumerable<OpenXmlElement> newChildren = )
public Void Append(OpenXmlElement[] newChildren = )
public T InsertAfterSelf(T newElement = )
public T InsertBeforeSelf(T newElement = )
public Type GetType()
public String ToString()
public Boolean Equals(Object obj = )
public Int32 GetHashCode()