Commit 373f4897 authored by Pablo Cancoin Desktop's avatar Pablo Cancoin Desktop
Browse files
parents fdcef543 68054c9b
......@@ -5,7 +5,7 @@ using System.Collections.Generic;
using UnityEngine;
/// <summary>
/// Stop the currently played voiceline and hide subtitles.
/// Stops the currently played voiceline and hides subtitles.
/// </summary>
public class ClearVoicelineEffector : AUnityEffector
{
......@@ -17,7 +17,7 @@ public class ClearVoicelineEffector : AUnityEffector
public override void SafeEffectorUpdate()
{
VOManager manager = GameObject.FindGameObjectWithTag("VOManager").GetComponent<VOManager>();
if (manager == null)
if (manager == null) // If the VOManager object can't be found
{
Debug.LogError("Could not play voiceline because a VOManager wasn't found in the scene. Check that a VOManager object is present and has the correct tag.");
}
......
......@@ -7,7 +7,7 @@ using SEVEN.Utilities;
using UnityEngine;
/// <summary>
/// Play the given voiceline.
/// Plays the given voiceline.
/// </summary>
public class PlayVoicelineEffector : AUnityEffector
{
......@@ -27,7 +27,7 @@ public class PlayVoicelineEffector : AUnityEffector
private VOManager manager;
private AudioSource audioSource;
protected bool finished = true;
protected bool finished = true; // Indicates to #SEVEN if it can move on to the next transition
private Vector2 topSubtitlePosition = new Vector2(-1.0f, 358.3f);
......@@ -51,34 +51,33 @@ public class PlayVoicelineEffector : AUnityEffector
{
manager = GameObject.FindGameObjectWithTag("VOManager").GetComponent<VOManager>();
audioSource = GameObject.FindGameObjectWithTag("VOManager").GetComponent<AudioSource>();
if (manager == null)
if (manager == null) // If the VOManager object can't be found
{
Debug.LogError("Could not play voiceline because a VOManager wasn't found in the scene. Check that a VOManager object is present and has the correct tag.");
} else
{
if (audio == null) audio = manager.defaultAudioClip;
if(displayAtTop) manager.changeSubtitlePosition(topSubtitlePosition);
else manager.resetSubtitlePosition();
else manager.resetSubtitlePosition(); // The position of subtitles is reset automatically between voicelines
manager.play(line, audio, length, stay);
if (waitForEnd)
if (waitForEnd) // If this is true then we can't progress in the scenario until the voiceline has finised playing
{
finished = false;
finished = false; // Prevents SEVEN from leaving this transition
UnityThreadExecute.Instance.StartCoroutine(CheckVoicelineEnded());
}
}
}
/// <summary>
/// Check every frame if the voiceline has ended
/// Checks every frame if the voiceline has ended
/// </summary>
/// <returns></returns>
protected virtual IEnumerator CheckVoicelineEnded()
{
while (manager.isPlaying())
{
yield return null;
}
finished = true;
finished = true; // Allows SEVEN to leave the transition
}
}
......@@ -17,14 +17,14 @@ public class NoVoicelineSensor : AUnitySensor
public override Result SafeSensorCheck()
{
VOManager manager = GameObject.FindGameObjectWithTag("VOManager").GetComponent<VOManager>();
if (manager == null)
if (manager == null) // If the VOManager object can't be found
{
Debug.LogError("Could not play voiceline because a VOManager wasn't found in the scene. Check that a VOManager object is present and has the correct tag.");
return new Result(true, null);
}
else
{
return new Result(!manager.isPlaying(), null);
return new Result(!manager.isPlaying(), null); // The sensor check is validated if the VOManager is not playing any voiceline currently
}
}
}
......@@ -4,6 +4,10 @@ using UnityEngine;
using UnityEngine.UI;
using TMPro;
/// <summary>
/// Manages the voicelines being played.
/// </summary>
public class VOManager : MonoBehaviour
{
private Voiceline currentVoiceline = null;
......@@ -30,7 +34,7 @@ public class VOManager : MonoBehaviour
}
// Play a voiceline and display the subtitle
// Plays a voiceline and display the subtitle
public void play(string line, AudioClip audio, float length, bool stay)
{
StartCoroutine(playCoroutine(line, audio, length, stay));
......@@ -47,24 +51,24 @@ public class VOManager : MonoBehaviour
Voiceline v = new Voiceline(line, audio);
subtitle.text = v.text;
currentVoiceline = v;
v.length = 0.0f;
if (length > 0) v.length = length; // Duration of the voiceline is set manually
else if (v.audio != null) // Duration of the voiceline is calculated automatically from the length of the audio clip
if (v.audio != null) // Duration of the voiceline is calculated automatically from the length of the audio clip if there is one
{
source.clip = v.audio;
v.length = v.audio.length * 1.2; // Subtitles are displayed for a little longer than the duration of the audio clip
if(v.length == 0.0f) v.length = v.audio.length * 1.2; // Subtitles are displayed for a little longer to give more time to read
source.Play();
}
else v.length = 0.0f;
yield return new WaitForSeconds((float)currentVoiceline.length); // Wait until the voiceline has ended (necessitates a coroutine)
yield return new WaitForSeconds((float)currentVoiceline.length); // Wait until the voiceline has ended
if(!v.interrupted) // If this voiceline was interrupted, it should not hide subtitles since another voiceline is being displayed
{
currentVoiceline = null; // Reset everything to default values
source.clip = null;
source.Stop();
if (!stay) // If stay is false, then reset and hide the subtitle
if (!stay) // If the voiceline isn't supposed to stay on screen, then reset and hide the subtitle
{
subtitle.text = "";
} // Else the text stays on screen to keep the information displayed to the user
......@@ -85,11 +89,13 @@ public class VOManager : MonoBehaviour
subtitle.text = "";
}
public void changeSubtitlePosition(Vector2 newPosition) // Change the position of the subtitles (valid only for the next subtitle)
// Change the position of the subtitles (valid only for the next subtitle)
public void changeSubtitlePosition(Vector2 newPosition)
{
textObject.GetComponent<RectTransform>().anchoredPosition = newPosition;
}
// Place the subtitle at its default position at the bottom of the screen
public void resetSubtitlePosition()
{
textObject.GetComponent<RectTransform>().anchoredPosition = defaultSubtitlePosition;
......
......@@ -8,7 +8,7 @@ public class Voiceline
public string text;
public AudioClip audio = null;
public double length;
public bool interrupted;
public bool interrupted; // Indicates if the voiceline was interrupted early while it was playing
public Voiceline(string line, AudioClip audio)
{
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment