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:11:53 +01:00
|
|
|
MarcsWebLogger.Log($"{randomNumber}-WallArt_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,
|
2023-12-15 11:10:23 +01:00
|
|
|
useMipMap = false, // true testen
|
2023-12-14 19:37:24 +01:00
|
|
|
depthStencilFormat = UnityEngine.Experimental.Rendering.GraphicsFormat.D24_UNorm_S8_UInt,
|
|
|
|
};
|
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:11:53 +01:00
|
|
|
|
2023-12-14 19:58:00 +01:00
|
|
|
|
2023-12-14 19:37:24 +01:00
|
|
|
outsideCameraInstance = camera.GetComponent<Camera>();
|
2023-12-14 19:58:00 +01:00
|
|
|
|
2023-12-15 09:11:53 +01:00
|
|
|
// Attempt to set the target texture
|
|
|
|
outsideCameraInstance.targetTexture = renderTexture;
|
2023-12-14 19:58:00 +01:00
|
|
|
|
|
|
|
|
2023-12-14 19:37:24 +01:00
|
|
|
material = new Material(Shader.Find("Standard"));
|
|
|
|
material.mainTexture = renderTexture;
|
2023-12-15 09:11:53 +01:00
|
|
|
|
2023-12-14 19:37:24 +01:00
|
|
|
meshRenderer.material = material;
|
2023-12-14 19:58:00 +01:00
|
|
|
ovrCameraRig = FindObjectOfType<OVRCameraRig>();
|
2023-12-15 09:11:53 +01:00
|
|
|
|
|
|
|
MarcsWebLogger.Log($"{randomNumber}-WallArt_end");
|
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
|
|
|
}
|