split into multiple assemblies

This commit is contained in:
2022-11-20 12:52:22 +01:00
parent def03954a0
commit 9fdfafc3eb
373 changed files with 380 additions and 119 deletions

View File

@@ -0,0 +1,44 @@
using UnityEngine;
using UnityEngine.InputSystem.XR;
using UnityEngine.XR.Interaction.Toolkit;
namespace EscapeRoomEngine.Portal.Runtime
{
public class PortalDriverClone : MonoBehaviour
{
/// <summary>
/// The portal where this clone is mirroring the portal driver.
/// </summary>
[HideInInspector] public Portal portal;
public static PortalDriverClone Create(PortalDriver portalDriver)
{
// copy the portal driver object
var clone = Instantiate(portalDriver).gameObject;
// destroy all unnecessary components
Destroy(clone.GetComponent<PortalDriver>());
foreach (var xrGrabInteractable in clone.GetComponentsInChildren<XRGrabInteractable>())
Destroy(xrGrabInteractable);
foreach (var rigidbody in clone.GetComponentsInChildren<Rigidbody>())
Destroy(rigidbody);
foreach (var trackedPoseDriver in clone.GetComponentsInChildren<TrackedPoseDriver>())
Destroy(trackedPoseDriver);
// add a clone component
clone.AddComponent<PortalDriverClone>();
// set up the clone
var portalDriverClone = clone.GetComponent<PortalDriverClone>();
portalDriverClone.gameObject.SetActive(false);
return portalDriverClone;
}
public void UpdatePosition(Transform cloning)
{
var m = portal.transform.localToWorldMatrix * Portal.HalfRotation *
portal.linkedPortal.transform.worldToLocalMatrix * cloning.localToWorldMatrix;
transform.SetPositionAndRotation(m.GetPosition(), m.rotation);
}
}
}