Add UniTask dependency, and wait 1 frame before showing subtitle to ensure UI positioned correctly (avoids "flipping" effect when initially shown)
This commit is contained in:
parent
a90a9adc28
commit
0071110c51
|
@ -4,7 +4,8 @@
|
||||||
"references": [
|
"references": [
|
||||||
"Unity.TextMeshPro",
|
"Unity.TextMeshPro",
|
||||||
"TriInspector",
|
"TriInspector",
|
||||||
"com.leantween"
|
"com.leantween",
|
||||||
|
"UniTask"
|
||||||
],
|
],
|
||||||
"includePlatforms": [],
|
"includePlatforms": [],
|
||||||
"excludePlatforms": [],
|
"excludePlatforms": [],
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
|
using Cysharp.Threading.Tasks;
|
||||||
using TMPro;
|
using TMPro;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
using UnityEngine.Events;
|
using UnityEngine.Events;
|
||||||
|
@ -192,6 +193,9 @@ namespace R0bbie.VRSubtitles
|
||||||
// Update speaking character name and avatar displayed
|
// Update speaking character name and avatar displayed
|
||||||
UpdateCharacterDisplay(_characterDataRef);
|
UpdateCharacterDisplay(_characterDataRef);
|
||||||
|
|
||||||
|
// Start subtitle position and rotation where we want it, before showing
|
||||||
|
SnapToFollowTarget();
|
||||||
|
|
||||||
// Set new active line to show
|
// Set new active line to show
|
||||||
activeLine = _text;
|
activeLine = _text;
|
||||||
|
|
||||||
|
@ -202,8 +206,6 @@ namespace R0bbie.VRSubtitles
|
||||||
// If we want to have this line not follow the character position
|
// If we want to have this line not follow the character position
|
||||||
dontFollowCharacter = _dontAttachSubToCharacter;
|
dontFollowCharacter = _dontAttachSubToCharacter;
|
||||||
|
|
||||||
SnapToFollowTarget();
|
|
||||||
|
|
||||||
// Allow continue after audio finished playing
|
// Allow continue after audio finished playing
|
||||||
Invoke(nameof(LineAudioFinished), _audioDuration);
|
Invoke(nameof(LineAudioFinished), _audioDuration);
|
||||||
}
|
}
|
||||||
|
@ -386,9 +388,6 @@ namespace R0bbie.VRSubtitles
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public void SnapToFollowTarget()
|
public void SnapToFollowTarget()
|
||||||
{
|
{
|
||||||
if (!panelActive)
|
|
||||||
return;
|
|
||||||
|
|
||||||
CalculateTargetPositions();
|
CalculateTargetPositions();
|
||||||
|
|
||||||
// Immediately update both parent and child objects pos to target
|
// Immediately update both parent and child objects pos to target
|
||||||
|
@ -465,6 +464,9 @@ namespace R0bbie.VRSubtitles
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Once conditions have been met to end this subtitle line
|
||||||
|
/// </summary>
|
||||||
void LineContinued()
|
void LineContinued()
|
||||||
{
|
{
|
||||||
// Play continued sound if set
|
// Play continued sound if set
|
||||||
|
@ -482,11 +484,14 @@ namespace R0bbie.VRSubtitles
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Activate and show panel
|
/// Activate and show panel
|
||||||
/// </summary>
|
/// </summary>
|
||||||
void ShowPanel()
|
async UniTaskVoid ShowPanel()
|
||||||
{
|
{
|
||||||
// If panel is being shown, and wasn't already showing
|
// 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)))
|
if (!panelActive && (Time.timeSinceLevelLoad > (timeLastHidden + 0.5f)))
|
||||||
{
|
{
|
||||||
// Play popup sound event
|
// Play popup sound event
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
{
|
{
|
||||||
"name": "com.r0bbie.vrsubtitles",
|
"name": "com.r0bbie.vrsubtitles",
|
||||||
"displayName": "VR Subtitles",
|
"displayName": "VR Subtitles",
|
||||||
"version": "1.0.0",
|
"version": "1.0.1",
|
||||||
"unity": "2021.3",
|
"unity": "2021.3",
|
||||||
"author": {
|
"author": {
|
||||||
"name" : "Robbie Cargill",
|
"name" : "Robbie Cargill",
|
||||||
|
@ -15,6 +15,7 @@
|
||||||
],
|
],
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.codewriter.triinspector": "1.13.2",
|
"com.codewriter.triinspector": "1.13.2",
|
||||||
|
"com.cysharp.unitask": "2.5.0",
|
||||||
"com.oss.leantween": "2.50.4",
|
"com.oss.leantween": "2.50.4",
|
||||||
"com.unity.textmeshpro": "3.0.6"
|
"com.unity.textmeshpro": "3.0.6"
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue