private IEnumerator IterateAllSceneCacheFrames(PlayableDirector director, TimelineClip clip, SceneCachePlayer scPlayer,
                                                       Action <int> afterUpdateFunc)
        {
            ISceneCacheInfo scInfo = scPlayer.ExtractSceneCacheInfo(forceOpen: true);

            Assert.IsNotNull(scInfo);

            double timePerFrame = 1.0f / scInfo.GetSampleRate();

            //Use (numFrames-1) because when it becomes invisible when Timeline reaches the last frame
            for (int i = 0; i < scInfo.GetNumFrames() - 1; ++i)
            {
                double elapsedTime = i * timePerFrame;
                if (elapsedTime >= clip.duration)
                {
                    yield break;
                }

                double directorTime = clip.start + i * timePerFrame;
                SetDirectorTime(director, directorTime); //this will trigger change in the time of the SceneCachePlayable
                yield return(null);

                afterUpdateFunc(i);
            }
        }
        public IEnumerator EnsureMatchingAndLimitedFramesAreLoadedToScene()
        {
            InitTest(true, out PlayableDirector director, out SceneCachePlayer sceneCachePlayer, out TimelineClip clip0);
            yield return(null);


            ISceneCacheInfo scInfo = sceneCachePlayer.ExtractSceneCacheInfo(forceOpen: true);

            Assert.IsNotNull(scInfo);
            int    numFrames    = scInfo.GetNumFrames();
            double timePerFrame = 1.0f / scInfo.GetSampleRate();

            //Setup clip0 duration
            int halfFrames = Mathf.FloorToInt(numFrames * 0.5f);

            clip0.duration = halfFrames * timePerFrame;

            //Setup clip1
            TimelineClip clip1 = clip0.GetParentTrack().CreateClip <SceneCachePlayableAsset>();

            clip1.start    = clip0.start + clip0.duration;
            clip1.clipIn   = clip0.duration;
            clip1.duration = clip0.duration;
            SceneCachePlayableAsset playableAsset1 = clip1.asset as SceneCachePlayableAsset;

            Assert.IsNotNull(playableAsset1);
            director.SetReferenceValue(playableAsset1.GetSceneCachePlayerRef().exposedName, sceneCachePlayer);

            TimelineEditorUtility.RefreshTimelineEditor(RefreshReason.ContentsAddedOrRemoved | RefreshReason.WindowNeedsRedraw | RefreshReason.ContentsModified);
            yield return(null);

            //Setup Limited Animation
            const int NUM_FRAMES_TO_HOLD = 3;
            const int OFFSET             = 1;

            LimitedAnimationController limitedAnimationController1 = playableAsset1.GetOverrideLimitedAnimationController();

            limitedAnimationController1.Enable(NUM_FRAMES_TO_HOLD, OFFSET);

            yield return(IterateAllSceneCacheFrames(director, clip0, sceneCachePlayer, (int timelineFrame) => {
                EditorApplication.isPaused = true;
                Assert.AreEqual(timelineFrame, sceneCachePlayer.GetFrame());
            }));

            yield return(IterateAllSceneCacheFrames(director, clip1, sceneCachePlayer, (int timelineFrame) => {
                int shownFrame = sceneCachePlayer.GetFrame();
                if (shownFrame == (scInfo.GetNumFrames() - 1)) //clamped to the end frame
                {
                    return;
                }

                Assert.Zero(shownFrame % NUM_FRAMES_TO_HOLD - OFFSET);
            }));
        }
Esempio n. 3
0
//----------------------------------------------------------------------------------------------------------------------        

    private static double CalculateTimeForLimitedAnimation(SceneCachePlayer scPlayer, 
        LimitedAnimationController overrideLimitedAnimationController, double time)  
    {
        LimitedAnimationController origLimitedAnimationController = scPlayer.GetLimitedAnimationController();
        if (origLimitedAnimationController.IsEnabled()) //do nothing if LA is set on the target SceneCache
            return time;
        
        if (!overrideLimitedAnimationController.IsEnabled())
            return time;

        ISceneCacheInfo scInfo = scPlayer.ExtractSceneCacheInfo(forceOpen: true);
        if (null == scInfo)
            return time;
            
        int frame = scPlayer.CalculateFrame((float)time,overrideLimitedAnimationController);
        return frame / scInfo.GetSampleRate();
    }
Esempio n. 4
0
        private static void DrawCacheInfo(SceneCachePlayer t)
        {
            ISceneCacheInfo scInfo = t.ExtractSceneCacheInfo(forceOpen: false);

            if (null == scInfo)
            {
                return;
            }

            t.ShowInfoInInspector(EditorGUILayout.Foldout(t.IsInfoInInspectorShown(), "Info", true, GetDefaultFoldoutStyle()));
            if (!t.IsInfoInInspectorShown())
            {
                return;
            }

            ++EditorGUI.indentLevel;

            const int leftWidth  = 160;
            int       numFrames  = scInfo.GetNumFrames();
            float     sampleRate = scInfo.GetSampleRate();
            TimeRange timeRange  = scInfo.GetTimeRange();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label($"Num Frames: {numFrames}", GUILayout.MaxWidth(leftWidth));
            GUILayout.Label($"Start Time: {timeRange.start,15:N4}");
            EditorGUILayout.EndHorizontal();

            EditorGUILayout.BeginHorizontal();
            GUILayout.Label($"Frame Rate: {sampleRate}", GUILayout.MaxWidth(leftWidth));
            GUILayout.Label($"End Time  : {timeRange.end,15:N4}");
            EditorGUILayout.EndHorizontal();

            --EditorGUI.indentLevel;

            EditorGUILayout.Space();
            EditorGUILayout.Space();
        }