Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.Playables;
- using System.Collections.Generic;
- using PixelCrushers.DialogueSystem;
- using Skatebirb.Gameplay;
- using Skatebirb.Managers;
- namespace Skatebirb.Timeline
- {
- public class DialogMixerBehaviour : PlayableBehaviour
- {
- private List<DialogBehaviour> havePlayedDialogs = new List<DialogBehaviour>();
- private bool shouldPauseForDialog = false;
- private PlayableGraph ourGraph;
- private PlayableDirector ourDiretor;
- public override void OnPlayableCreate(Playable playable)
- {
- ourGraph = playable.GetGraph();
- ourDiretor = ourGraph.GetResolver() as PlayableDirector;
- }
- public override void OnGraphStart(Playable playable)
- {
- havePlayedDialogs.Clear();
- shouldPauseForDialog = false;
- }
- public override void ProcessFrame(Playable playable, FrameData info, object playerData)
- {
- bool noPlayablesPlaying = true;
- // If this code is being run in the editor because we're editing the timelines or something? Just give up, don't do ANY of this.
- if (!Application.isPlaying) { return; }
- // Iterate over all the clips on this track
- int numInputPlayables = playable.GetInputCount();
- for (int playableIndex = 0; playableIndex < numInputPlayables; playableIndex++)
- {
- // First, extract the weight, since it's what tells us if we're even processing this playable
- float inputWeight = playable.GetInputWeight(playableIndex);
- if (inputWeight > 0.1f)
- {
- noPlayablesPlaying = false;
- // Extracting the behavior is... complicated
- ScriptPlayable<DialogBehaviour> inputPlayable = (ScriptPlayable<DialogBehaviour>)playable.GetInput(playableIndex);
- DialogBehaviour inputDialogBehaviour = inputPlayable.GetBehaviour();
- if (inputDialogBehaviour == null || string.IsNullOrEmpty(inputDialogBehaviour.dialogName)) { continue; }
- // If we're active, and haven't actually played dialog yet - NOW IS THE TIME BOY
- if (!havePlayedDialogs.Contains(inputDialogBehaviour))
- {
- // Now start the conversation!
- DialogueManager.StartConversation(inputDialogBehaviour.dialogName);
- havePlayedDialogs.Add(inputDialogBehaviour);
- shouldPauseForDialog = true;
- }
- }
- }
- if (noPlayablesPlaying)
- {
- if (shouldPauseForDialog)
- {
- shouldPauseForDialog = false;
- // If the conversation is still going, pause the timeline so the user can keep reading
- // (this will eventually be resumed over in MissionGiver, which is why we MUST have them as the speaker up above)
- if (DialogueManager.IsConversationActive) { ourDiretor.Pause(); }
- }
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment