diff --git a/Scripts/R0bbie.VRSubtitles.asmdef b/Scripts/R0bbie.VRSubtitles.asmdef
index 8a8a027..bf0ebf0 100644
--- a/Scripts/R0bbie.VRSubtitles.asmdef
+++ b/Scripts/R0bbie.VRSubtitles.asmdef
@@ -4,7 +4,8 @@
"references": [
"Unity.TextMeshPro",
"TriInspector",
- "com.leantween"
+ "com.leantween",
+ "UniTask"
],
"includePlatforms": [],
"excludePlatforms": [],
diff --git a/Scripts/SubtitlePanel.cs b/Scripts/SubtitlePanel.cs
index 9443492..e2367a6 100644
--- a/Scripts/SubtitlePanel.cs
+++ b/Scripts/SubtitlePanel.cs
@@ -1,4 +1,5 @@
using System;
+using Cysharp.Threading.Tasks;
using TMPro;
using UnityEngine;
using UnityEngine.Events;
@@ -192,6 +193,9 @@ namespace R0bbie.VRSubtitles
// Update speaking character name and avatar displayed
UpdateCharacterDisplay(_characterDataRef);
+ // Start subtitle position and rotation where we want it, before showing
+ SnapToFollowTarget();
+
// Set new active line to show
activeLine = _text;
@@ -201,8 +205,6 @@ namespace R0bbie.VRSubtitles
// If we want to have this line not follow the character position
dontFollowCharacter = _dontAttachSubToCharacter;
-
- SnapToFollowTarget();
// Allow continue after audio finished playing
Invoke(nameof(LineAudioFinished), _audioDuration);
@@ -386,9 +388,6 @@ namespace R0bbie.VRSubtitles
///
public void SnapToFollowTarget()
{
- if (!panelActive)
- return;
-
CalculateTargetPositions();
// Immediately update both parent and child objects pos to target
@@ -465,6 +464,9 @@ namespace R0bbie.VRSubtitles
}
+ ///
+ /// Once conditions have been met to end this subtitle line
+ ///
void LineContinued()
{
// Play continued sound if set
@@ -482,11 +484,14 @@ namespace R0bbie.VRSubtitles
///
/// Activate and show panel
///
- void ShowPanel()
+ async UniTaskVoid ShowPanel()
{
// If panel is being shown, and wasn't already showing
- // Add a slight delay for playing sound in case toggled quickly off and on again
+ // Wait a frame to ensure subtitle UI correctly positioned before showing
+ await UniTask.DelayFrame(2);
+
+ // Add a slight delay for playing sound again, in case toggled quickly off and on again
if (!panelActive && (Time.timeSinceLevelLoad > (timeLastHidden + 0.5f)))
{
// Play popup sound event
diff --git a/package.json b/package.json
index b4d8ea4..e9c75b1 100644
--- a/package.json
+++ b/package.json
@@ -1,7 +1,7 @@
{
"name": "com.r0bbie.vrsubtitles",
"displayName": "VR Subtitles",
- "version": "1.0.0",
+ "version": "1.0.1",
"unity": "2021.3",
"author": {
"name" : "Robbie Cargill",
@@ -15,6 +15,7 @@
],
"dependencies": {
"com.codewriter.triinspector": "1.13.2",
+ "com.cysharp.unitask": "2.5.0",
"com.oss.leantween": "2.50.4",
"com.unity.textmeshpro": "3.0.6"
}