2022-10-09 22:33:51 +00:00
|
|
|
|
using QSB.Utility;
|
|
|
|
|
using UnityEngine;
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
namespace QSB.ConversationSync;
|
|
|
|
|
|
2022-10-09 22:33:51 +00:00
|
|
|
|
[UsedInUnityProject]
|
2022-03-03 03:46:33 +00:00
|
|
|
|
public class CameraFacingBillboard : MonoBehaviour
|
2021-09-27 15:54:15 +00:00
|
|
|
|
{
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private OWCamera _activeCam;
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void Awake()
|
|
|
|
|
=> GlobalMessenger<OWCamera>.AddListener("SwitchActiveCamera", OnSwitchActiveCamera);
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void Start()
|
|
|
|
|
{
|
|
|
|
|
_activeCam = Locator.GetActiveCamera();
|
|
|
|
|
UpdateRotation();
|
|
|
|
|
}
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void OnDestroy()
|
|
|
|
|
=> GlobalMessenger<OWCamera>.RemoveListener("SwitchActiveCamera", OnSwitchActiveCamera);
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void OnSwitchActiveCamera(OWCamera activeCamera)
|
|
|
|
|
{
|
|
|
|
|
_activeCam = activeCamera;
|
|
|
|
|
UpdateRotation();
|
|
|
|
|
}
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void LateUpdate()
|
|
|
|
|
=> UpdateRotation();
|
2021-09-27 15:54:15 +00:00
|
|
|
|
|
2022-03-03 03:46:33 +00:00
|
|
|
|
private void UpdateRotation()
|
|
|
|
|
=> transform.LookAt(transform.position + (_activeCam.transform.rotation * Vector3.forward), _activeCam.transform.rotation * Vector3.up);
|
2022-02-25 06:04:54 +00:00
|
|
|
|
}
|