91 lines
3.8 KiB
C#
91 lines
3.8 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using UnityEngine;
|
|
|
|
|
|
// HEAVILY INSPIRED by SampleVIrutalFrame.cs from the Unity TheWorldBeyond Project.
|
|
public class WorldScript : MonoBehaviour
|
|
{
|
|
|
|
public OVRSceneManager _sceneManager;
|
|
|
|
public SimpleResizable _doorPrefab;
|
|
|
|
void Awake()
|
|
{
|
|
|
|
#if UNITY_EDITOR_WIN || UNITY_STANDALONE_WIN || UNITY_ANDROID
|
|
OVRManager.eyeFovPremultipliedAlphaModeEnabled = false;
|
|
#endif
|
|
_sceneManager.SceneModelLoadedSuccessfully += InitializeRoom;
|
|
}
|
|
|
|
void InitializeRoom()
|
|
{
|
|
MarcsWebLogger.Log("Wordscript initialize");
|
|
OVRSceneAnchor[] sceneAnchors = FindObjectsOfType<OVRSceneAnchor>();
|
|
MarcsWebLogger.Log($"found {sceneAnchors.Length} sceneAnchors");
|
|
|
|
if (sceneAnchors == null) return;
|
|
List<Transform> windows = new List<Transform>();
|
|
|
|
|
|
for (int i = 0; i < sceneAnchors.Length; i++)
|
|
{
|
|
OVRSceneAnchor instance = sceneAnchors[i];
|
|
OVRSemanticClassification classification = instance.GetComponent<OVRSemanticClassification>();
|
|
if (classification.Contains(OVRSceneManager.Classification.WallArt))
|
|
{
|
|
|
|
MarcsWebLogger.Log($"found a window at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
}
|
|
else if (classification.Contains(OVRSceneManager.Classification.DoorFrame))
|
|
{
|
|
MarcsWebLogger.Log($"1 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
windows.Add(instance.transform);
|
|
|
|
|
|
MarcsWebLogger.Log($"2 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
SimpleResizer resizer = new SimpleResizer();
|
|
|
|
MarcsWebLogger.Log($"3 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
SimpleResizable prefab = classification.Contains(OVRSceneManager.Classification.DoorFrame) ? _doorPrefab : _doorPrefab;
|
|
|
|
MarcsWebLogger.Log($"4 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
Vector3 dimensions = instance.transform.GetChild(0).localScale;
|
|
|
|
|
|
// the Resizer scales the mesh so that the bounds are flush with the window extents
|
|
// in this case, we want the mesh frame to extend "outside" of the extents, so we adjust it
|
|
// as well, the vines on the door also require special treatment
|
|
|
|
MarcsWebLogger.Log($"5 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
if (prefab.GetComponent<ResizablePadding>())
|
|
{
|
|
|
|
MarcsWebLogger.Log($"6 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
dimensions += prefab.GetComponent<ResizablePadding>().dimensionPadding;
|
|
}
|
|
|
|
MarcsWebLogger.Log($"7 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
MarcsWebLogger.Log($"7 DOOR 0: {resizer == null}");
|
|
MarcsWebLogger.Log($"7 DOOR 1: {dimensions == null}");
|
|
MarcsWebLogger.Log($"7 DOOR 2: {sceneAnchors[i].gameObject == null}");
|
|
MarcsWebLogger.Log($"7 DOOR 3: {prefab == null}");
|
|
|
|
try
|
|
{
|
|
resizer.CreateResizedObject(dimensions, sceneAnchors[i].gameObject, prefab);
|
|
}
|
|
catch (Exception e)
|
|
{
|
|
MarcsWebLogger.Log(e.StackTrace.ToString().Substring(0, 200));
|
|
|
|
}
|
|
MarcsWebLogger.Log($"8 DOOR at pos: {instance.transform.position}, rot: {instance.transform.rotation}");
|
|
}
|
|
}
|
|
}
|
|
}
|