/// <summary>
        /// Play a timeline (after dealing with the player character if they're in
        /// the scene).
        /// </summary>
        /// <param name="graphEngine">THe graphing engine that's handling this node.</param>
        private IEnumerator Play(GraphEngine graphEngine)
        {
            // Close the dialog box if desired.
            if (CloseDialogBefore)
            {
                DialogManager.CloseDialogBox();
            }

            yield return(new WaitForSeconds(WaitBefore));

            UpdateOutro();

            // Play timeline and wait until finished.
            Director.RebuildGraph();
            Director.Play();
            bool playing = true;

            Action <PlayableDirector> onStop = (PlayableDirector director) => { playing = false; };

            Director.stopped += onStop;

            while (playing && Director.playableGraph.IsPlaying())
            {
                yield return(null);
            }

            Director.stopped -= onStop;

            // Wait additional time if desired.
            yield return(new WaitForSeconds(WaitAfter));


            // Reopen the default dialog box if desired.
            if (CloseDialogBefore && OpenDialogAfter)
            {
                DialogManager.OpenDialogBox();
            }
        }
Esempio n. 2
0
    //-----------------------------------------------------------------

    public void Apply(bool playAfterApplied = true)
    {
        // Cinemachine's clip name will be change after RebuildGraph().
        if (IsModified)
        {
            playableDirector.RebuildGraph();
            ApplyModifiedClipsName();
        }

        if (playAfterApplied)
        {
            playableDirector.Play();
        }
    }
Esempio n. 3
0
    public void PlayIngame()
    {
        AudioTrack audioTrack;

        //Timeline playable graph asset needs to be rebuilt to change contributing tracks
        timelineAsset = (TimelineAsset)ingameTimeline.playableAsset;

        Reset();

        //pick ingame atmos track index:
        int atmosIndex = pickRandomItem(ingameAtmosTrackIndices);
        //pick ingame lead track index:
        int leadIndex = pickRandomItem(ingameLeadTrackIndices);
        //pick ingame rhythm track index:
        int rhythmIndex = pickRandomItem(ingameRhythmTrackIndices);

        //iterate over tracks and set output to playing or muted
        int count = 0;

        foreach (var track in timelineAsset.GetOutputTracks())
        {
            audioTrack = track as AudioTrack;

            if (audioTrack == null)
            {
                //Debug.Log("Null track at count:" + count.ToString());
                continue;
            }
            else
            {
                //Debug.Log("Audio track " + count.ToString() + " clip:" + audioTrack.name);
            }

            if (count == atmosIndex || count == leadIndex || count == rhythmIndex)
            {
                ingameTimeline.SetGenericBinding(audioTrack, playingOutput);
            }
            else
            {
                ingameTimeline.SetGenericBinding(audioTrack, mutedOutput);
            }

            count++;
        }
        ingameTimeline.time = 0.0f;
        ingameTimeline.RebuildGraph();
        ingameTimeline.Play();
    }
Esempio n. 4
0
        public void MuteTrack(int trackIndex, bool mute)
        {
            if (asset == null)
            {
                return;
            }
            // Get track from TimelineAsset
            TrackAsset track = asset.GetOutputTrack(trackIndex);

            // Change TimelineAsset's muted property value
            track.muted = mute;

            double t = director.time; // Store elapsed time

            director.RebuildGraph();  // Rebuild graph
            director.time = t;        // Restore elapsed time
        }
Esempio n. 5
0
        public void MuteTracks(int numAssigmentsCompleted)
        {
            PlayableDirector director    = GetComponent <PlayableDirector>();
            TimelineAsset    timeline    = director.playableAsset as TimelineAsset;
            double           currentTime = director.time;
            int           i = 1;
            List <string> trackNamesToMute = new List <string>(numAssigmentsCompleted == 4 ? trackNamesToMuteGood : trackNamesToMuteBad);

            foreach (string trackName in trackNamesToMuteFlags)
            {
                if (numAssigmentsCompleted < i)
                {
                    trackNamesToMute.Add(trackName);
                }
                i++;
            }
            i = 0;
            foreach (TrackAsset track in timeline.GetOutputTracks())
            {
                bool mute = trackNamesToMute.IndexOf(track.name) >= 0;
                if (track.muted != mute)
                {
                    track.muted = mute;
                    Debug.Log($"{this} {(mute ? "muting" : "unmuting")} track {track}", this);
                    if (track is ActivationTrack)
                    {
                        GameObject binding = director.GetGenericBinding(track) as GameObject;
                        if (binding)
                        {
                            if (mute && binding.activeSelf) // by muting this track we also want to deactivate the thing this track was activating
                            {
                                Debug.Log($"{this} muting track {track}: deactivating {binding}", this);
                                binding.SetActive(false);
                            }
                        }
                    }
                }

                i++;
            }
            director.RebuildGraph();
            director.time = currentTime;
        }
        public override void OnBehaviourPlay(Playable playable, FrameData info)
        {
            _pd.Pause();
            if (_newTime > _pd.time)
            {
                FastForward(_newTime);
            }
            else
            {
                Rewind(_newTime);
            }

            Debug.Log("setFabTime: " + _pd.time + " and: " + _pd.state);

            if (_pd.state != PlayState.Playing)
            {
                _pd.RebuildGraph();
                _pd.Play();
            }
        }
Esempio n. 7
0
        public void Inject()
        {
            if (!Director || !Director.playableGraph.IsValid())
            {
                return;
            }
            var mixersChanged = DetectMixersChanged();

            if (mixersChanged)
            {
                var time = Director.time;
                Director.RebuildGraph();
                Director.time = time;
                UpdateIdIfChanged();
            }
            else if (!DetectGraphChanged())
            {
                return;
            }

            InternalInjectNow();
        }
Esempio n. 8
0
        public IEnumerator TestTimelineTrack()
        {
            director.Play();
            exporter.MaxCaptureFrame = 30;
            yield return(RecordAlembic());

            deleteFileList.Add(exporter.Recorder.Settings.OutputPath);
            var go       = TestAbcImported(exporter.Recorder.Settings.OutputPath);
            var root     = PrefabUtility.InstantiatePrefab(go) as GameObject;
            var player   = root.GetComponent <AlembicStreamPlayer>();
            var timeline = director.playableAsset as TimelineAsset;
            var abcTrack = timeline.CreateTrack <AlembicTrack>(null, "");
            var clip     = abcTrack.CreateClip <AlembicShotAsset>();
            var abcAsset = clip.asset as AlembicShotAsset;
            var refAbc   = new ExposedReference <AlembicStreamPlayer> {
                exposedName = Guid.NewGuid().ToString()
            };

            abcAsset.StreamPlayer = refAbc;
            director.SetReferenceValue(refAbc.exposedName, player);
            director.RebuildGraph();
            var cubeGO = root.GetComponentInChildren <MeshRenderer>().gameObject;

            director.time = 0;
            director.Evaluate();
            yield return(null);

            var t0 = cubeGO.transform.position;

            director.time = player.Duration;
            director.Evaluate();
            yield return(null);

            var t1 = cubeGO.transform.position;

            Assert.AreNotEqual(t0, t1);
        }
Esempio n. 9
0
    private void Update()
    {
        if (!_initialized)
        {
            return;
        }
        bool timelineUpdated = false;

        var newLookAhead = Math.Round((_playableDirector.time + LOOK_AHEAD) / LOOK_AHEAD_GRANULARITY) * LOOK_AHEAD_GRANULARITY;

        if (newLookAhead > _currentLookAhead)
        {
            foreach (var characterBehaviour in _characterBehaviours)
            {
                if (characterBehaviour.Value.IdleClip.end < newLookAhead)
                {
                    characterBehaviour.Value.IdleClip.duration = newLookAhead - characterBehaviour.Value.IdleClip.start;
                }
            }
            _currentLookAhead = newLookAhead;
        }
        while (_battleActive && _battleLockEnd < _currentLookAhead)
        {
            var turnData = new TurnDisplayData();
            turnData.Turn = _battleController.GenerateTurn();
            if (turnData.Turn == null)
            {
                _battleActive = false;
                break;
            }
            turnData.TimelineAssetData  = GetTimelineAssetData(turnData.Turn);
            turnData.CharacterBehaviour = _characterBehaviours[turnData.Turn.Character];
            turnData.TargetBehaviours   = new List <BattleCharacterBehaviour>();
            for (int i = 0; i < turnData.Turn.Targets.Count; i++)
            {
                Character target = turnData.Turn.Targets[i];
                turnData.TargetBehaviours.Add(_characterBehaviours[target]);
            }

            var turnStart   = CalculateLocks(turnData);
            var controlClip = turnData.CharacterBehaviour.BattleDirectorTrack.CreateClip <BattleDirectorAsset>();
            controlClip.start    = turnStart;
            controlClip.duration = turnData.TimelineAssetData.Asset.duration;
            var controlClipAsset = (BattleDirectorAsset)controlClip.asset;
            controlClipAsset.TurnDisplayData           = turnData;
            controlClipAsset.TurnDisplayData.StartTime = turnStart;
            controlClipAsset.TurnDisplayData.EndTime   = turnStart + turnData.TimelineAssetData.Asset.duration;

            if (controlClip.start < turnData.CharacterBehaviour.IdleClip.end)
            {
                var newDuration = controlClip.start - turnData.CharacterBehaviour.IdleClip.start;
                if (newDuration > 0)
                {
                    turnData.CharacterBehaviour.IdleClip.duration = newDuration;
                }
                else
                {
                    turnData.CharacterBehaviour.BattleDirectorTrack.timelineAsset.DeleteClip(turnData.CharacterBehaviour.IdleClip);
                }
                CreateIdleClip(turnData.CharacterBehaviour, controlClip.end);
            }

            for (int targetIndex = 0; targetIndex < turnData.TimelineAssetData.TargetLocks.Count; targetIndex++)
            {
                var targetLock      = turnData.TimelineAssetData.TargetLocks[targetIndex];
                var targetLockStart = targetLock.Start + turnStart;
                var targetLockEnd   = targetLock.End + turnStart;
                var targetBehaviour = turnData.TargetBehaviours[targetIndex];
                if (targetLockStart <= targetBehaviour.IdleClip.end && targetBehaviour.IdleClip.start <= targetLockEnd)
                {
                    var newDuration = targetLockStart - targetBehaviour.IdleClip.start;
                    if (newDuration > 0)
                    {
                        targetBehaviour.IdleClip.duration = newDuration;
                    }
                    else
                    {
                        targetBehaviour.BattleDirectorTrack.timelineAsset.DeleteClip(targetBehaviour.IdleClip);
                    }
                    CreateIdleClip(targetBehaviour, targetLockEnd);
                }
            }

            timelineUpdated = true;
        }
        if (timelineUpdated)
        {
            _playableDirector.initialTime = _playableDirector.time;
            _playableDirector.RebuildGraph();
        }
    }
        public static void MatchNext(TimelineClip currentClip, Transform matchPoint, PlayableDirector director)
        {
            const double      timeEpsilon = 0.00001;
            MatchTargetFields matchFields = GetMatchFields(currentClip);

            if (matchFields == MatchTargetFieldConstants.None || matchPoint == null)
            {
                return;
            }

            double cachedTime = director.time;

            // finds next clip
            TimelineClip nextClip = GetNextClip(currentClip);

            if (nextClip == null || currentClip == nextClip)
            {
                return;
            }

            // make sure the transform is properly updated before modifying the graph
            director.Evaluate();

            var parentTrack = currentClip.parentTrack as AnimationTrack;

            var blendOut = currentClip.blendOutDuration;
            var blendIn  = nextClip.blendInDuration;

            currentClip.blendOutDuration = 0;
            nextClip.blendInDuration     = 0;

            //evaluate previous without current
            parentTrack.RemoveClip(currentClip);
            director.RebuildGraph();
            director.time = nextClip.start + timeEpsilon;
            director.Evaluate(); // add port to evaluate only track

            var targetPosition = matchPoint.position;
            var targetRotation = matchPoint.rotation;

            // evaluate current without next
            parentTrack.AddClip(currentClip);
            parentTrack.RemoveClip(nextClip);
            director.RebuildGraph();
            director.time = Math.Min(nextClip.start, currentClip.end - timeEpsilon);
            director.Evaluate();

            //////////////////////////////////////////////////////////////////////
            //compute offsets

            var animationPlayable = currentClip.asset as AnimationPlayableAsset;
            var match             = UpdateClipOffsets(animationPlayable, parentTrack, matchPoint, targetPosition, targetRotation);

            WriteMatchFields(animationPlayable, match, matchFields);

            //////////////////////////////////////////////////////////////////////

            currentClip.blendOutDuration = blendOut;
            nextClip.blendInDuration     = blendIn;

            parentTrack.AddClip(nextClip);
            director.RebuildGraph();
            director.time = cachedTime;
            director.Evaluate();
        }
Esempio n. 11
0
 void PlayAtSpeed(PlayableDirector playableDirector, float speed)
 {
     playableDirector.RebuildGraph();         // the graph must be created before getting the playable graph
     playableDirector.playableGraph.GetRootPlayable(0).SetSpeed(speed);
     playableDirector.Play();
 }