/****************************************************************************
* Copyright 2019 Nreal Techonology Limited. All rights reserved.
*
* This file is part of NRSDK.
*
* https://www.nreal.ai/
*
*****************************************************************************/
using UnityEngine;
using UnityEngine.UI;
namespace NRKernal.NRExamples
{
/// A custom virtual controler user interface.
[HelpURL("https://developer.nreal.ai/develop/unity/customize-phone-controller")]
public class CustomVirtualControlerUI : MonoBehaviour
{
/// The show control.
public Button showBtn;
/// The hide control.
public Button hideBtn;
/// The base controller panel.
public GameObject baseControllerPanel;
/// The color btns.
public Button[] colorBtns;
/// The reset control.
public Button resetBtn;
/// The scale slider.
public Slider scaleSlider;
/// The model control.
private TargetModelDisplayCtrl m_ModelCtrl;
/// Starts this object.
private void Start()
{
Init();
}
/// Initializes this object.
private void Init()
{
m_ModelCtrl = FindObjectOfType();
for (int i = 0; i < colorBtns.Length; i++)
{
int k = i;
colorBtns[i].onClick.AddListener(() => { OnColorButtonClick(k); });
}
showBtn.onClick.AddListener(() => { SetBaseControllerEnabled(true); });
hideBtn.onClick.AddListener(() => { SetBaseControllerEnabled(false); });
resetBtn.onClick.AddListener(OnResetButtonClick);
scaleSlider.onValueChanged.AddListener(OnScaleSliderValueChanged);
}
/// Executes the 'color button click' action.
/// Zero-based index of the.
private void OnColorButtonClick(int index)
{
m_ModelCtrl.ChangeModelColor(colorBtns[index].image.color);
}
/// Executes the 'scale slider value changed' action.
/// The value.
private void OnScaleSliderValueChanged(float val)
{
m_ModelCtrl.ChangeModelScale(val);
}
/// Executes the 'reset button click' action.
private void OnResetButtonClick()
{
m_ModelCtrl.ResetModel();
scaleSlider.value = 0f;
}
/// Sets base controller enabled.
/// True if is enabled, false if not.
private void SetBaseControllerEnabled(bool isEnabled)
{
baseControllerPanel.SetActive(isEnabled);
}
}
}