//----------------------------------------------------------------------------------------------------------------------

        //Calculate the used image index for the passed localTime
        internal int LocalTimeToImageIndex(TimelineClip clip, double localTime)
        {
            TimelineClipSISData timelineSISData = GetBoundTimelineClipSISData();

            if (null != timelineSISData)
            {
                double scaledTimePerFrame = TimelineUtility.CalculateTimePerFrame(clip) * clip.timeScale;

                //Try to check if this frame is "dropped", so that we should use the image in the prev frame
                int playableFrameIndex         = Mathf.RoundToInt((float)localTime / (float)scaledTimePerFrame);
                SISPlayableFrame playableFrame = timelineSISData.GetPlayableFrame(playableFrameIndex);
                while (playableFrameIndex > 0 && !playableFrame.IsUsed())
                {
                    --playableFrameIndex;
                    playableFrame = timelineSISData.GetPlayableFrame(playableFrameIndex);
                    localTime     = playableFrameIndex * scaledTimePerFrame;
                }
            }


            double imageSequenceTime = LocalTimeToCurveTime(clip, localTime);
            int    count             = m_imageFiles.Count;

            //Can't round up, because if the time for the next frame hasn't been reached, then we should stick
            int index = Mathf.FloorToInt(count * (float)imageSequenceTime);

            index = Mathf.Clamp(index, 0, count - 1);
            return(index);
        }
        internal static void SetUsed(this SISPlayableFrame playableFrame, bool used)
        {
#if UNITY_EDITOR
            bool prevUsed = playableFrame.IsUsed();
#endif

            playableFrame.SetBoolProperty(PlayableFramePropertyID.USED, used);

#if UNITY_EDITOR
            //Refresh
            if (used != prevUsed)
            {
                TimelineEditor.Refresh(RefreshReason.ContentsModified);
            }
#endif
        }
Esempio n. 3
0
//----------------------------------------------------------------------------------------------------------------------

        //Calculate the used image index for the passed localTime
        internal int LocalTimeToImageIndex(TimelineClip clip, double localTime)
        {
            SISClipData clipData = GetBoundClipData();

            if (null == clipData)
            {
                return(0);
            }


            {
                //drop disabled frames
                double scaledTimePerFrame = TimelineUtility.CalculateTimePerFrame(clip) * clip.timeScale;

                //Try to check if this frame is "dropped", so that we should use the image in the prev frame
                int playableFrameIndex = Mathf.RoundToInt((float)(localTime - clip.clipIn) / (float)scaledTimePerFrame);
                if (playableFrameIndex < 0)
                {
                    return(0);
                }

                SISPlayableFrame playableFrame = clipData.GetPlayableFrame(playableFrameIndex);
                while (playableFrameIndex > 0 && !playableFrame.IsUsed())
                {
                    --playableFrameIndex;
                    playableFrame = clipData.GetPlayableFrame(playableFrameIndex);
                    localTime     = playableFrameIndex * scaledTimePerFrame;
                }
            }

            AnimationCurve curve             = clipData.GetAnimationCurve();
            double         imageSequenceTime = curve.Evaluate((float)localTime);

            int count = m_imageFiles.Count;

            //Can't round up, because if the time for the next frame hasn't been reached, then we should stick
            int index = Mathf.FloorToInt(count * (float)imageSequenceTime);

            index = Mathf.Clamp(index, 0, count - 1);
            return(index);
        }