VR/Assets/Prefabs/OVR Scene Manager Overrides/Picture/WallArt.cs

81 lines
2.6 KiB
C#
Raw Normal View History

2023-12-14 19:37:24 +01:00
using System.Collections;
using UnityEngine;
using UnityEngine.Networking;
public class WallArt : MonoBehaviour
{
public GameObject outsideCameraPrefab;
2023-12-14 22:58:23 +01:00
public Transform window;
2023-12-14 19:37:24 +01:00
private Camera outsideCameraInstance;
public MeshRenderer meshRenderer;
2023-12-14 19:58:00 +01:00
private OVRCameraRig ovrCameraRig;
2023-12-14 19:37:24 +01:00
private RenderTexture renderTexture;
private Material material;
// Start is called before the first frame update
void Start()
{
var randomNumber = Random.Range(10000, 99999);
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-start");
2023-12-14 19:37:24 +01:00
renderTexture = new RenderTexture(256, 256, 0)
{
dimension = UnityEngine.Rendering.TextureDimension.Tex2D,
wrapMode = TextureWrapMode.Clamp,
filterMode = FilterMode.Bilinear,
enableRandomWrite = false,
useDynamicScale = false,
useMipMap = false,
depthStencilFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.D24_UNorm_S8_UInt,
};
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-1");
2023-12-14 19:58:00 +01:00
2023-12-14 19:37:24 +01:00
GameObject camera = Instantiate(outsideCameraPrefab, transform.position, Quaternion.identity);
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-1.1");
2023-12-14 19:58:00 +01:00
2023-12-14 19:37:24 +01:00
outsideCameraInstance = camera.GetComponent<Camera>();
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-2");
2023-12-14 19:58:00 +01:00
2023-12-14 19:37:24 +01:00
try
{
// Attempt to set the target texture
outsideCameraInstance.targetTexture = renderTexture;
}
catch (System.Exception e)
{
// Handle any exceptions that may occur
Debug.LogError("An error occurred: " + e.Message);
}
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-3");
2023-12-14 19:58:00 +01:00
// Set the initial rotation of the camera
2023-12-14 19:37:24 +01:00
outsideCameraInstance.transform.rotation = Quaternion.Euler(
2023-12-14 19:58:00 +01:00
Random.Range(0f, 360f),
Random.Range(0f, 360f),
Random.Range(0f, 360f)
2023-12-14 19:37:24 +01:00
);
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-4");
2023-12-14 19:58:00 +01:00
2023-12-14 19:37:24 +01:00
material = new Material(Shader.Find("Standard"));
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-5");
2023-12-14 19:58:00 +01:00
2023-12-14 19:37:24 +01:00
material.mainTexture = renderTexture;
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-6");
2023-12-14 19:37:24 +01:00
meshRenderer.material = material;
2023-12-15 09:07:07 +01:00
MarcsWebLogger.Log($"{randomNumber}-7");
2023-12-14 19:58:00 +01:00
ovrCameraRig = FindObjectOfType<OVRCameraRig>();
2023-12-14 19:37:24 +01:00
}
// Update is called once per frame
void Update()
{
2023-12-14 19:58:00 +01:00
// Check if the cameraRig is assigned
if (ovrCameraRig == null) return;
2023-12-14 19:37:24 +01:00
2023-12-15 08:40:48 +01:00
outsideCameraInstance.transform.position = ovrCameraRig.centerEyeAnchor.position;
outsideCameraInstance.transform.LookAt(window);
2023-12-14 19:58:00 +01:00
}
2023-12-14 19:37:24 +01:00
}