portal with camera transformation

This commit is contained in:
2022-10-07 15:56:16 +02:00
parent 014ba8e36e
commit 59abc4b6f7
20 changed files with 4927 additions and 0 deletions

View File

@@ -0,0 +1,36 @@
using System;
using UnityEngine;
namespace Escape_Room_Engine.Portal
{
public class Portal : MonoBehaviour
{
/// <summary>
/// The portal that is connected with this one.
/// </summary>
public Portal other;
/// <summary>
/// The main camera to take the position for the portal camera from.
/// </summary>
[SerializeField] private Transform playerCamera;
/// <summary>
/// The camera that will draw the view for this portal.
/// </summary>
[SerializeField] private Transform portalCamera;
private void Start()
{
// check whether the other portal is set up
if (!other || other.other != this) throw new Exception("Other Portal not set up correctly.");
// check whether the player camera is set up
if (!playerCamera) throw new Exception("No camera initialised.");
}
private void Update()
{
var portalCameraMatrix = transform.localToWorldMatrix * other.transform.worldToLocalMatrix *
playerCamera.localToWorldMatrix;
portalCamera.SetPositionAndRotation(portalCameraMatrix.GetPosition(), portalCameraMatrix.rotation);
}
}
}