/// <summary>
        /// return the currently active animation frames
        /// </summary>
        /// <returns></returns>
        public List <IFrameRecord> GetFrameDebugInfo()
        {
            List <IFrameRecord> snapshots = new List <IFrameRecord>();

#if UNITY_EDITOR
            if (poseGenerator.CurrentPushIndex >= 0)
            {
                AnimationSampleTimeIndex animSampleTime = Binary.GetAnimationSampleTimeIndex(Time.timeIndex);

                if (animSampleTime.IsValid)
                {
                    AnimationFrameDebugInfo lastFrame = new AnimationFrameDebugInfo()
                    {
                        sequenceIdentifier = poseGenerator.CurrentPushIndex,
                        animName           = animSampleTime.clipName,
                        animFrame          = animSampleTime.animFrameIndex,
                        weight             = poseGenerator.ApproximateTransitionProgression,
                        blendOutDuration   = BlendDuration,
                    };
                    snapshots.Add(lastFrame);
                }
            }
#endif

            return(snapshots);
        }
Exemple #2
0
        public void AddRecords(List <IFrameRecord> records, float frameStartTime, float frameEndTime)
        {
            List <AnimationFrameDebugInfo> frameSnapshots = records.Select(r => (AnimationFrameDebugInfo)r).ToList();

            List <int> newSnapshots = new List <int>(); // snaphots from sequences that weren't already present in the records

            // Update blending-out sequences
            float deltaTime = frameEndTime - frameStartTime;

            for (int i = m_AnimationRecords.Count - m_NumActiveAnims; i < m_AnimationRecords.Count; ++i)
            {
                AnimationRecord animRecord = m_AnimationRecords[i];
                if (frameSnapshots.Any(s => s.sequenceIdentifier == animRecord.sequenceIdentifier))
                {
                    continue; // sequence will updated anyway with a new frame
                }

                if (animRecord.blendOutTime > 0.0f)
                {
                    // sequence is obsolete (no update this frame) but still require blending out
                    animRecord.blendOutTime -= deltaTime;

                    AnimationFrameInfo lastFrame = animRecord.animFrames[animRecord.animFrames.Count - 1];
                    float deltaWeight            = deltaTime / animRecord.blendOutDuration;

                    frameSnapshots.Add(new AnimationFrameDebugInfo()
                    {
                        sequenceIdentifier = animRecord.sequenceIdentifier,
                        animName           = animRecord.animName,
                        animFrame          = lastFrame.animFrame,
                        weight             = math.max(lastFrame.weight - deltaWeight, 0.0f),
                        blendOutDuration   = 0.0f
                    });
                }
            }

            int updatedSnapshots = 0;

            for (int snapshotIndex = 0; snapshotIndex < frameSnapshots.Count; ++snapshotIndex)
            {
                AnimationFrameDebugInfo frameDebugInfo = frameSnapshots[snapshotIndex];

                bool bAddNewRecord = true;

                for (int i = m_AnimationRecords.Count - m_NumActiveAnims; i < m_AnimationRecords.Count - updatedSnapshots; ++i)
                {
                    AnimationRecord animRecord = m_AnimationRecords[i];
                    if (animRecord.sequenceIdentifier == frameDebugInfo.sequenceIdentifier)
                    {
                        // snapshot from already existing sequence, just add a new animation frame
                        animRecord.endTime = frameEndTime;
                        animRecord.AddAnimationFrame(frameEndTime, frameDebugInfo.weight, frameDebugInfo.animFrame, frameDebugInfo.blendOutDuration);

                        m_LinesEndTimes[animRecord.rank] = frameEndTime;
                        m_AnimationRecords.SwapElements(i, m_AnimationRecords.Count - updatedSnapshots - 1);
                        ++updatedSnapshots;

                        bAddNewRecord = false;
                        break;
                    }
                }

                if (bAddNewRecord)
                {
                    newSnapshots.Add(snapshotIndex);
                }
            }

            foreach (int snapshotIndex in newSnapshots)
            {
                // snapshot from new sequence, add a new record
                AnimationFrameDebugInfo frameDebugInfo = frameSnapshots[snapshotIndex];

                CircularList <AnimationFrameInfo> animFrames = new CircularList <AnimationFrameInfo>();
                animFrames.PushBack(new AnimationFrameInfo {
                    endTime = frameEndTime, weight = frameDebugInfo.weight, animFrame = frameDebugInfo.animFrame
                });

                m_AnimationRecords.PushBack(new AnimationRecord
                {
                    sequenceIdentifier = frameDebugInfo.sequenceIdentifier,
                    animName           = frameDebugInfo.animName,
                    startTime          = frameStartTime,
                    endTime            = frameEndTime,
                    blendOutDuration   = frameDebugInfo.blendOutDuration,
                    blendOutTime       = frameDebugInfo.blendOutDuration,
                    rank       = GetNewAnimRank(frameStartTime, frameEndTime),
                    animFrames = animFrames
                });
            }

            m_NumActiveAnims = frameSnapshots.Count;
        }