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);
|
|
|
|
Log($"{randomNumber}-start");
|
|
|
|
|
|
|
|
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,
|
|
|
|
};
|
|
|
|
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);
|
|
|
|
Log($"{randomNumber}-1.1");
|
2023-12-14 19:58:00 +01:00
|
|
|
|
2023-12-14 19:37:24 +01:00
|
|
|
outsideCameraInstance = camera.GetComponent<Camera>();
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
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
|
|
|
);
|
|
|
|
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"));
|
|
|
|
Log($"{randomNumber}-5");
|
2023-12-14 19:58:00 +01:00
|
|
|
|
2023-12-14 19:37:24 +01:00
|
|
|
material.mainTexture = renderTexture;
|
|
|
|
Log($"{randomNumber}-6");
|
|
|
|
meshRenderer.material = material;
|
|
|
|
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 22:58:23 +01:00
|
|
|
|
|
|
|
// https://www.youtube.com/watch?v=txF4t1qynyk
|
|
|
|
|
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-14 19:58:00 +01:00
|
|
|
// Get the CenterEyeAnchor position
|
|
|
|
Vector3 centerEyePosition = ovrCameraRig.centerEyeAnchor.position;
|
|
|
|
//Vector3 centerEyePosition = new Vector3();
|
2023-12-14 19:37:24 +01:00
|
|
|
|
2023-12-14 19:58:00 +01:00
|
|
|
// Update the position of the object based on the CenterEyeAnchor position with an added offset to the y-axis
|
2023-12-14 22:58:23 +01:00
|
|
|
///outsideCameraInstance.transform.position = new Vector3(centerEyePosition.x, centerEyePosition.y + 0f, centerEyePosition.z);
|
2023-12-14 19:58:00 +01:00
|
|
|
|
|
|
|
// Remove rotation around the z-axis
|
2023-12-14 22:58:23 +01:00
|
|
|
///Vector3 eulerRotation = ovrCameraRig.centerEyeAnchor.rotation.eulerAngles;
|
2023-12-14 19:58:00 +01:00
|
|
|
//Vector3 eulerRotation = Vector3.right;
|
2023-12-14 22:58:23 +01:00
|
|
|
///outsideCameraInstance.transform.rotation = Quaternion.Euler(eulerRotation.x, eulerRotation.y, 0f);
|
|
|
|
|
|
|
|
Vector3 localPlayer = window.InverseTransformPoint(centerEyePosition);
|
|
|
|
outsideCameraInstance.transform.position = window.TransformPoint(new Vector3(localPlayer.x, localPlayer.y, localPlayer.z));
|
|
|
|
Vector3 lookAtWindow = window.TransformPoint(new Vector3(-localPlayer.x, localPlayer.y, localPlayer.z));
|
|
|
|
outsideCameraInstance.transform.LookAt(lookAtWindow);
|
|
|
|
|
2023-12-14 19:58:00 +01:00
|
|
|
}
|
2023-12-14 19:37:24 +01:00
|
|
|
|
|
|
|
private void Log(string message)
|
|
|
|
{
|
|
|
|
StartCoroutine(MakeGetRequest($"https://log.m-g.tech/?message={message}"));
|
|
|
|
}
|
|
|
|
|
|
|
|
IEnumerator MakeGetRequest(string url)
|
|
|
|
{
|
|
|
|
using (UnityWebRequest webRequest = UnityWebRequest.Get(url))
|
|
|
|
{
|
|
|
|
// Send the request and wait for a response
|
|
|
|
yield return webRequest.SendWebRequest();
|
|
|
|
|
|
|
|
// Check for errors
|
|
|
|
if (webRequest.result == UnityWebRequest.Result.ConnectionError ||
|
|
|
|
webRequest.result == UnityWebRequest.Result.ProtocolError)
|
|
|
|
{
|
|
|
|
Debug.LogError("Error: " + webRequest.error);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Print the results
|
|
|
|
Debug.Log("Received: " + webRequest.downloadHandler.text);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|