/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal { #if UNITY_EDITOR using UnityEngine; /// Manager for nr emulators. internal class NREmulatorManager : MonoBehaviour { /// Gets or sets the instance. /// The instance. public static NREmulatorManager Instance { get; set; } /// Identifier for the simulation plane. public static int SIMPlaneID = 0; /// True if inited. public static bool Inited = false; /// The center camera. private Camera centerCam = null; /// Starts this object. private void Start() { DontDestroyOnLoad(this); Instance = this; } /// Query if 'worldPos' is in game view. /// The world position. /// True if in game view, false if not. public bool IsInGameView(Vector3 worldPos) { if (centerCam == null) centerCam = GameObject.Find("CenterCamera").GetComponent(); Transform camTransform = centerCam.transform; Vector2 viewPos = centerCam.WorldToViewportPoint(worldPos); Vector3 dir = (worldPos - camTransform.position).normalized; float dot = Vector3.Dot(camTransform.forward, dir); if (dot > 0 && viewPos.x >= 0 && viewPos.x <= 1 && viewPos.y >= 0 && viewPos.y <= 1) { return true; } else { return false; } } } #endif }