From 7732a63b5aba38060ff6db14600d71b577b91161 Mon Sep 17 00:00:00 2001 From: Mister_Nebula <41904486+misternebula@users.noreply.github.com> Date: Mon, 27 Sep 2021 16:54:15 +0100 Subject: [PATCH] Fixes #314 --- QSB/ConversationSync/CameraFacingBillboard.cs | 30 +++++++++++++++++++ QSB/ConversationSync/ConversationManager.cs | 6 +--- QSB/QSB.csproj | 1 + QSB/Utility/DebugBoxManager.cs | 6 +--- 4 files changed, 33 insertions(+), 10 deletions(-) create mode 100644 QSB/ConversationSync/CameraFacingBillboard.cs diff --git a/QSB/ConversationSync/CameraFacingBillboard.cs b/QSB/ConversationSync/CameraFacingBillboard.cs new file mode 100644 index 00000000..74b0630c --- /dev/null +++ b/QSB/ConversationSync/CameraFacingBillboard.cs @@ -0,0 +1,30 @@ +using UnityEngine; + +public class CameraFacingBillboard : MonoBehaviour +{ + private OWCamera _activeCam; + + private void Awake() + => GlobalMessenger.AddListener("SwitchActiveCamera", OnSwitchActiveCamera); + + private void Start() + { + _activeCam = Locator.GetActiveCamera(); + UpdateRotation(); + } + + private void OnDestroy() + => GlobalMessenger.RemoveListener("SwitchActiveCamera", OnSwitchActiveCamera); + + private void OnSwitchActiveCamera(OWCamera activeCamera) + { + _activeCam = activeCamera; + UpdateRotation(); + } + + void LateUpdate() + => UpdateRotation(); + + private void UpdateRotation() + => transform.LookAt(transform.position + (_activeCam.transform.rotation * Vector3.forward), _activeCam.transform.rotation * Vector3.up); +} \ No newline at end of file diff --git a/QSB/ConversationSync/ConversationManager.cs b/QSB/ConversationSync/ConversationManager.cs index 3171b3f8..8baa343f 100644 --- a/QSB/ConversationSync/ConversationManager.cs +++ b/QSB/ConversationSync/ConversationManager.cs @@ -1,5 +1,4 @@ using OWML.Common; -using OWML.Utils; using QSB.Events; using QSB.Player; using QSB.Utility; @@ -120,10 +119,7 @@ namespace QSB.ConversationSync newBox.transform.SetParent(parent); newBox.transform.localPosition = new Vector3(0, vertOffset, 0); newBox.transform.rotation = parent.rotation; - var lookAt = newBox.AddComponent(); - lookAt.SetValue("_useLookAt", false); - lookAt.SetValue("_localFacingVector", Vector3.back); - lookAt.SetValue("_localRotationAxis", Vector3.up); + newBox.AddComponent(); newBox.GetComponent().text = text; newBox.AddComponent(); newBox.SetActive(true); diff --git a/QSB/QSB.csproj b/QSB/QSB.csproj index 9858b117..a9a5f5fa 100644 --- a/QSB/QSB.csproj +++ b/QSB/QSB.csproj @@ -134,6 +134,7 @@ + diff --git a/QSB/Utility/DebugBoxManager.cs b/QSB/Utility/DebugBoxManager.cs index 37921e3c..8d2481c6 100644 --- a/QSB/Utility/DebugBoxManager.cs +++ b/QSB/Utility/DebugBoxManager.cs @@ -1,5 +1,4 @@ using OWML.Common; -using OWML.Utils; using UnityEngine; using UnityEngine.UI; @@ -29,10 +28,7 @@ namespace QSB.Utility newBox.transform.SetParent(parent); newBox.transform.localPosition = new Vector3(0, vertOffset, 0); newBox.transform.rotation = parent.rotation; - var lookAt = newBox.AddComponent(); - lookAt.SetValue("_useLookAt", true); - lookAt.SetValue("_localFacingVector", Vector3.back); - lookAt.SetValue("_localRotationAxis", Vector3.up); + newBox.AddComponent(); newBox.GetComponent().text = text; newBox.AddComponent(); newBox.SetActive(true);