/**************************************************************************** * Copyright 2019 Nreal Techonology Limited. All rights reserved. * * This file is part of NRSDK. * * https://www.nreal.ai/ * *****************************************************************************/ using UnityEngine; namespace NRKernal.NRExamples { /// A target model display control. public class TargetModelDisplayCtrl : MonoBehaviour { /// The model target. public Transform modelTarget; /// The model renderer. public MeshRenderer modelRenderer; /// The default color. public Color defaultColor = Color.white; /// The minimum scale. public float minScale = 1f; /// The maximum scale. public float maxScale = 3f; /// The around local axis. private Vector3 m_AroundLocalAxis = Vector3.down; /// The touch scroll speed. private float m_TouchScrollSpeed = 10000f; /// The previous position. private Vector2 m_PreviousPos; /// Starts this object. void Start() { ResetModel(); } /// Updates this object. private void Update() { if (NRInput.GetButtonDown(ControllerButton.TRIGGER)) { m_PreviousPos = NRInput.GetTouch(); } else if (NRInput.GetButton(ControllerButton.TRIGGER)) { UpdateScroll(); } else if (NRInput.GetButtonUp(ControllerButton.TRIGGER)) { m_PreviousPos = Vector2.zero; } } /// Updates the scroll. private void UpdateScroll() { if (m_PreviousPos == Vector2.zero) return; Vector2 deltaMove = NRInput.GetTouch() - m_PreviousPos; m_PreviousPos = NRInput.GetTouch(); modelTarget.Rotate(m_AroundLocalAxis, deltaMove.x * m_TouchScrollSpeed * Time.deltaTime, Space.Self); } /// Change model color. /// The color. public void ChangeModelColor(Color color) { modelRenderer.material.color = color; } /// Change model scale. /// The value. public void ChangeModelScale(float val) // 0 ~ 1 { modelTarget.localScale = Vector3.one * Mathf.SmoothStep(minScale, maxScale, val); } /// Resets the model. public void ResetModel() { modelTarget.localRotation = Quaternion.identity; ChangeModelScale(0f); ChangeModelColor(defaultColor); } } }