Hi to all.
AC is friendly, clear and powerfull solution. Thanks, Chris, for your work.
On DocumentUI GO I have the following script to voice over document page:
using UnityEngine;
using AC;
public class DocumentsController : MonoBehaviour
{
private AudioSource _audio;
void OnEnable()
{
if (KickStarter.player != null)
{
_audio = KickStarter.player.speechAudioSource;
Play(KickStarter.runtimeDocuments.ActiveDocument);
};
EventManager.OnMenuElementShift += OnMenuElementShift;
EventManager.OnMenuTurnOff += OnMenuTurnOff;
}
private void OnMenuTurnOff(Menu _menu, bool isInstant)
{
_audio.Stop();
}
private void OnMenuElementShift(MenuElement _element, AC_ShiftInventory shiftType)
{
if (_element is MenuJournal)
Play(KickStarter.runtimeDocuments.ActiveDocument);
}
void Play(Document doc)
{
_audio.Stop();
int last_page = KickStarter.runtimeDocuments.GetLastOpenPage(doc)-1;
int line_id = doc.pages[last_page].lineID;
AudioClip clip = KickStarter.runtimeLanguages.GetSpeechAudioClip(line_id, KickStarter.player);
if (clip != null)
_audio.PlayOneShot(clip);
}
void OnDisable()
{
EventManager.OnMenuElementShift -= OnMenuElementShift;
EventManager.OnMenuTurnOff -= OnMenuTurnOff;
}
}
All works great, but i need some more functionality. When AudioClip for page is finished playing, I need to automatically turn to next page. And if it is last page, automatically close DocumentUI.
I think, that in Play() method I need to add something like:
StartCoroutine(TurnPage(clip.length));
and:
IEnumerator TurnPage(float time)
{
yield return new WaitForSeconds(time);
//Turn page or close document//
}
But I dont know, how to call method, which handles the buttons (NextPage and CloseDocument) click. Or may be there is more simple way to do this?
It looks like you're new here. If you want to get involved, click one of these buttons!
Comments
Welcome to the community, @BlindRainGames.
Yes - so long as the game isn't paused while the Document is open, then a coroutine should be able to do the job.
You don't need to access the NextPage or CloseDocument buttons - you can modify the Menu and Journal directly.
Try this:
Thanks, @ChrisIceBox. I found the following solution. May be, I don't understand something, but it works.
IEnumerator TurnPage(float time)
{
yield return new WaitForSeconds(time);
Menu menu = KickStarter.playerMenus.GetMenuWithCanvas(GetComponent