This commit is contained in:
Mister_Nebula 2021-09-27 16:54:15 +01:00
parent d9e9e2b5cf
commit 7732a63b5a
4 changed files with 33 additions and 10 deletions

View File

@ -0,0 +1,30 @@
using UnityEngine;
public class CameraFacingBillboard : MonoBehaviour
{
private OWCamera _activeCam;
private void Awake()
=> GlobalMessenger<OWCamera>.AddListener("SwitchActiveCamera", OnSwitchActiveCamera);
private void Start()
{
_activeCam = Locator.GetActiveCamera();
UpdateRotation();
}
private void OnDestroy()
=> GlobalMessenger<OWCamera>.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);
}

View File

@ -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<FaceActiveCamera>();
lookAt.SetValue("_useLookAt", false);
lookAt.SetValue("_localFacingVector", Vector3.back);
lookAt.SetValue("_localRotationAxis", Vector3.up);
newBox.AddComponent<CameraFacingBillboard>();
newBox.GetComponent<Text>().text = text;
newBox.AddComponent<ZOverride>();
newBox.SetActive(true);

View File

@ -134,6 +134,7 @@
<Compile Include="CampfireSync\WorldObjects\QSBCampfire.cs" />
<Compile Include="ClientServerStateSync\ClientStateManager.cs" />
<Compile Include="ClientServerStateSync\Events\ClientStateEvent.cs" />
<Compile Include="ConversationSync\CameraFacingBillboard.cs" />
<Compile Include="ConversationSync\Events\DialogueConditionEvent.cs" />
<Compile Include="ConversationSync\Events\DialogueConditionMessage.cs" />
<Compile Include="ConversationSync\Events\ConversationEvent.cs" />

View File

@ -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<FaceActiveCamera>();
lookAt.SetValue("_useLookAt", true);
lookAt.SetValue("_localFacingVector", Vector3.back);
lookAt.SetValue("_localRotationAxis", Vector3.up);
newBox.AddComponent<CameraFacingBillboard>();
newBox.GetComponent<Text>().text = text;
newBox.AddComponent<ZOverride>();
newBox.SetActive(true);