mirror of
https://github.com/PashaBibko/The-Mobius-Line.git
synced 2026-04-04 01:49:07 +00:00
Portal rendering 1/2 done
This commit is contained in:
45
Assets/Scripts/Portals/PortalManager.cs
Normal file
45
Assets/Scripts/Portals/PortalManager.cs
Normal file
@@ -0,0 +1,45 @@
|
||||
using System.ComponentModel;
|
||||
using UnityEngine;
|
||||
|
||||
public class PortalManager : MonoBehaviour
|
||||
{
|
||||
[Header("References")]
|
||||
[SerializeField] GameObject m_OtherPortal;
|
||||
|
||||
[Header("Set References")]
|
||||
[SerializeField] GameObject m_CameraPrefab;
|
||||
[SerializeField] MeshRenderer m_PortalRenderer;
|
||||
[SerializeField] Transform m_CapturePoint;
|
||||
|
||||
PortalManager m_OtherManager;
|
||||
PortalCamera m_PortalCamera;
|
||||
|
||||
public PortalManager Linked() => m_OtherManager;
|
||||
|
||||
public Vector3 pos => transform.parent.position;
|
||||
public Quaternion rot => transform.parent.rotation;
|
||||
|
||||
// Start is called before the first frame update
|
||||
void Start()
|
||||
{
|
||||
// Validates that it is a portal
|
||||
m_OtherManager = m_OtherPortal.GetComponentInChildren<PortalManager>();
|
||||
if (m_OtherManager == null)
|
||||
{
|
||||
Debug.LogError("OtherPortal was not valid portal");
|
||||
return;
|
||||
}
|
||||
|
||||
// Creates the camera in top-level heirachry and stores the PortalCamera script
|
||||
GameObject cam = Instantiate(m_CameraPrefab, transform.root.parent);
|
||||
m_PortalCamera = cam.GetComponentInChildren<PortalCamera>();
|
||||
|
||||
// Initialises the camera so it renders to the portal and not the screen
|
||||
m_PortalCamera.InitCamera(m_PortalRenderer, this);
|
||||
}
|
||||
public Vector3 TranslateOffset(Vector3 offset)
|
||||
{
|
||||
m_CapturePoint.localPosition = offset;
|
||||
return m_CapturePoint.position;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user