Hello,
I’m new to FMOD and I’m working on a game with Unity.
I created Single Event and then an Action Sheet, then I dragged and dropped an audio track there.
Screenshot:
This audio track is in this case a piece of a dialogue, e.g. a sentence of many.
Every audio has a text and I need to delete the current text in my UI when the current audio track is finished, and then go next…
This is the class handling some of this logic:
tnamespace Assets.Scripts.UI.Dialogues
{
public class DialogPanelView : IDialogueView
{
// From constructor
private GameObject dialogPanelPrefab;
private Transform canvasTransform;
private DialogSegmentData dialogSegmentData;
// Others
private GameObject instantiatedDialogPanel;
public DialogPanelView(GameObject dialogPanelPrefab, Transform canvasTransform, DialogSegmentData dialogSegmentData)
{
this.dialogPanelPrefab = dialogPanelPrefab ?? throw new ArgumentNullException(nameof(dialogPanelPrefab));
this.canvasTransform = canvasTransform ?? throw new ArgumentNullException(nameof(canvasTransform));
this.dialogSegmentData = dialogSegmentData ?? throw new ArgumentNullException(nameof (dialogSegmentData));
}
public void Create()
{
GameObject dialogPanel = GameObject.Instantiate(dialogPanelPrefab);
TMP_Text panelText = ComponentUtils.RequireFirstComponentInChildren<TMP_Text>(dialogPanel);
panelText.text = dialogSegmentData.text;
dialogPanel.transform.SetParent(canvasTransform, false);
instantiatedDialogPanel = dialogPanel;
RuntimeManager.PlayOneShot(dialogSegmentData.soundEvent);
}
public float GetWaitingTimeSeconds()
{
// TODO
}
public void Destroy()
{
GameObject.Destroy(instantiatedDialogPanel);
}
}
}
I want to implement the method float GetWaitingTimeSeconds() but it seems to return zero all the times.
I tried this:
EventDescription eventDescription = RuntimeManager.GetEventDescription(dialogSegmentData.soundEvent);
int totalTime;
eventDescription.getLength(out totalTime);
Debug.Log(totalTime);
return totalTime;
And then this:
EventInstance instance = RuntimeManager.CreateInstance(dialogSegmentData.soundEvent);
instance.getDescription(out EventDescription eventDescription);
instance.start();
int currentTime;
FMOD.RESULT res = instance.getTimelinePosition(out currentTime);
if (res != FMOD.RESULT.OK)
{
Debug.LogError("getTimelinePosition reported error: " + res);
}
Debug.Log($"currentTime = {currentTime}");
int totalTime;
FMOD.RESULT res2 = eventDescription.getLength(out totalTime);
if (res2 != FMOD.RESULT.OK)
{
Debug.LogError("getLength reported error: " + res2);
}
Debug.Log($"totalTime = {totalTime}");
return totalTime;
But no luck. Clearly I’m making a mistake. I know that this could be due to the fact that “there’s nothing in the timeline”, I’ve read in other threads. And while I understand the idea behind it, I don’t get how to properly implement this.
If you couldhelp me with the implementation of the method and give a brief explaination, I would be grateful.