Guest User

Untitled

a guest
May 19th, 2020
27
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.62 KB | None | 0 0
  1. using UnityEngine;
  2. using UnityEngine.Playables;
  3. using System.Collections.Generic;
  4. using PixelCrushers.DialogueSystem;
  5. using Skatebirb.Gameplay;
  6. using Skatebirb.Managers;
  7.  
  8. namespace Skatebirb.Timeline
  9. {
  10. public class DialogMixerBehaviour : PlayableBehaviour
  11. {
  12. private List<DialogBehaviour> havePlayedDialogs = new List<DialogBehaviour>();
  13. private bool shouldPauseForDialog = false;
  14.  
  15. private PlayableGraph ourGraph;
  16. private PlayableDirector ourDiretor;
  17.  
  18. public override void OnPlayableCreate(Playable playable)
  19. {
  20. ourGraph = playable.GetGraph();
  21. ourDiretor = ourGraph.GetResolver() as PlayableDirector;
  22. }
  23.  
  24. public override void OnGraphStart(Playable playable)
  25. {
  26. havePlayedDialogs.Clear();
  27. shouldPauseForDialog = false;
  28. }
  29.  
  30. public override void ProcessFrame(Playable playable, FrameData info, object playerData)
  31. {
  32. bool noPlayablesPlaying = true;
  33.  
  34. // 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.
  35. if (!Application.isPlaying) { return; }
  36.  
  37. // Iterate over all the clips on this track
  38. int numInputPlayables = playable.GetInputCount();
  39. for (int playableIndex = 0; playableIndex < numInputPlayables; playableIndex++)
  40. {
  41. // First, extract the weight, since it's what tells us if we're even processing this playable
  42. float inputWeight = playable.GetInputWeight(playableIndex);
  43.  
  44. if (inputWeight > 0.1f)
  45. {
  46. noPlayablesPlaying = false;
  47.  
  48. // Extracting the behavior is... complicated
  49. ScriptPlayable<DialogBehaviour> inputPlayable = (ScriptPlayable<DialogBehaviour>)playable.GetInput(playableIndex);
  50. DialogBehaviour inputDialogBehaviour = inputPlayable.GetBehaviour();
  51. if (inputDialogBehaviour == null || string.IsNullOrEmpty(inputDialogBehaviour.dialogName)) { continue; }
  52.  
  53. // If we're active, and haven't actually played dialog yet - NOW IS THE TIME BOY
  54. if (!havePlayedDialogs.Contains(inputDialogBehaviour))
  55. {
  56. // Now start the conversation!
  57. DialogueManager.StartConversation(inputDialogBehaviour.dialogName);
  58.  
  59. havePlayedDialogs.Add(inputDialogBehaviour);
  60. shouldPauseForDialog = true;
  61. }
  62. }
  63. }
  64.  
  65. if (noPlayablesPlaying)
  66. {
  67. if (shouldPauseForDialog)
  68. {
  69. shouldPauseForDialog = false;
  70.  
  71. // If the conversation is still going, pause the timeline so the user can keep reading
  72. // (this will eventually be resumed over in MissionGiver, which is why we MUST have them as the speaker up above)
  73. if (DialogueManager.IsConversationActive) { ourDiretor.Pause(); }
  74. }
  75. }
  76. }
  77. }
  78. }
Advertisement
Add Comment
Please, Sign In to add comment