/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ namespace NRKernal.Record { using NRKernal; using UnityEngine; using UnityEngine.UI; /// Preview the camera's record or capture image. public class NRPreviewer : MonoBehaviour { /// The root. public GameObject Root; /// The preview screen. public RawImage PreviewScreen; /// The state icon. public Image StateIcon; /// True if is bind to controller, false if not. public bool isBindToController = true; /// Starts this object. private void Start() { Root.SetActive(false); } /// Sets a data. /// The tex. /// True to isplaying. public void SetData(Texture tex, bool isplaying) { PreviewScreen.texture = tex; StateIcon.color = isplaying ? Color.green : Color.red; } /// Updates this object. private void Update() { if (NRInput.GetButtonDown(ControllerButton.APP)) { Root.SetActive(!Root.activeInHierarchy); NRInput.LaserVisualActive = !Root.activeInHierarchy; NRInput.ReticleVisualActive = !Root.activeInHierarchy; } if (isBindToController) { this.BindPreviewTOController(); } } /// Bind preview to controller. private void BindPreviewTOController() { var inputAnchor = NRInput.AnchorsHelper.GetAnchor(ControllerAnchorEnum.RightModelAnchor); transform.position = inputAnchor.TransformPoint(Vector3.forward * 0.3f); transform.forward = inputAnchor.forward; } /// Switch perview. /// True to flag. public void SwitchPerview(bool flag) { Root.SetActive(flag); } } }