Skip to content

Commit

Permalink
Skip added
Browse files Browse the repository at this point in the history
  • Loading branch information
BDeshiDev committed May 2, 2024
1 parent c5ffd6b commit ad7b287
Show file tree
Hide file tree
Showing 5 changed files with 514 additions and 58 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ public class DialogueSystem : MonoBehaviour
[Header("Execution Data")]
[SerializeField] private DialogueNodeBase _curNode;

[Header("Skip")]
[SerializeField] private bool _resetSkipAfterChoice = true;
[SerializeField] private bool _isSkipActive = false;
[SerializeField] private bool _shouldShowLineWhenSkipped = true;
[SerializeField] private float _showLineDurationWhenSkipping = .32f;
public bool IsSkipActive => _isSkipActive;
public bool ShouldShowLineWhenSkipped => _shouldShowLineWhenSkipped;
public float ShowLineDurationWhenSkipping => _showLineDurationWhenSkipping;
public event Action<bool> OnSkipToggled;

public event Action<DialogueGraph> OnDialogueStarted;
public event Action<DialogueGraph> OnDialogueEnded;

Expand Down Expand Up @@ -92,6 +102,8 @@ public async UniTask PlayDialogue(DialogueGraph graph, DialogueNodeBase startNod
_currentGraph = graph;
_curNode = startNode;
_currentGraph.HandleDialogueStarted();
_isSkipActive = false;

OnDialogueStarted?.Invoke(_currentGraph);
while (_curNode != null)
{
Expand All @@ -117,6 +129,10 @@ public void PickChoice(int choiceIndex)
{
if (_curNode != null)
{
if (_resetSkipAfterChoice)
{
ToggleSkip(false);
}
_curNode.HandleChoiceSelected(choiceIndex);
}
}
Expand All @@ -131,6 +147,12 @@ public void HandleDialogueChoiceEnded(DialogueChoicesNode dialogueChoicesNode)
OnDialogueChoiceEnded?.Invoke(dialogueChoicesNode);
}

public void ToggleSkip() => ToggleSkip(!_isSkipActive);
public void ToggleSkip(bool shouldSkipBeActive) {
_isSkipActive = shouldSkipBeActive;
OnSkipToggled?.Invoke(_isSkipActive);
}

private void OnDestroy()
{
if (_currentGraph != null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,24 @@ public override async UniTask Play()
{
_canAdvanceDialogue = false;

Core.DialogueSystem.Instance.DialogueLineStarted?.Invoke(this);
while (!_canAdvanceDialogue)
Debug.Log($"{Core.DialogueSystem.Instance.IsSkipActive} {Core.DialogueSystem.Instance.ShouldShowLineWhenSkipped}");
if (!Core.DialogueSystem.Instance.IsSkipActive ||
Core.DialogueSystem.Instance.ShouldShowLineWhenSkipped)
{
await UniTask.Yield();
Core.DialogueSystem.Instance.DialogueLineStarted?.Invoke(this);
while (!_canAdvanceDialogue)
{
if (Core.DialogueSystem.Instance.IsSkipActive)
{
await UniTask.Delay(TimeSpan.FromSeconds(Core.DialogueSystem.Instance.ShowLineDurationWhenSkipping));
break;
}

await UniTask.Yield();
await UniTask.NextFrame();
}
Core.DialogueSystem.Instance.DialogueLineCompleted?.Invoke(this);
}
Core.DialogueSystem.Instance.DialogueLineCompleted?.Invoke(this);

InvokePostPlayEvents();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DialogueUI:DialogueUIBase
{
public DialogueBoxUI DialogueBox;
public DialogueChoiceUI ChoiceUI;

void Start()
{
RegisterEvents();
Expand All @@ -30,6 +31,7 @@ private void RegisterEvents()
DialogueSystem.Instance.OnDialogueChoiceStarted += HandleDialogueChoiceStarted;
DialogueSystem.Instance.OnDialogueChoiceEnded += HandleDialogueChoiceEnded;
}


public override void ShowDialogueLineImmediate(DialogueLineNodeBase node)
{
Expand Down
Loading

0 comments on commit ad7b287

Please sign in to comment.