using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;


public class Mostech_UIManager : MonoBehaviour
{
	private ConcurrentQueue<string> queue = new ConcurrentQueue<string>();
	public Text text_Log;
	public Button startDataReceiveBtn;
    public Button poseCaliBtn;
	public Button quitBtn;

	public Text leftHandGetPacketRate;
	public Text rightHandGetPacketRate;

	private void Awake()
	{
		
	}

	// Start is called before the first frame update
	void Start()
    {
        startDataReceiveBtn.onClick.AddListener(StartDataReceiveBtnEvent);
        poseCaliBtn.onClick.AddListener(PoseCaliBtnEvent);
		quitBtn.onClick.AddListener(Quit);

	}


    /// <summary>
    /// ɼ
    /// </summary>
    private void StartDataReceiveBtnEvent()
	{
		bool result = Mostech_MotionDriver.Instance.StartDataReceiving();
		if(!result)
		{
			Debug.LogError("豸");
		}
	}


    /// <summary>
    /// У׼
    /// </summary>
    private void PoseCaliBtnEvent()
	{
		bool result= Mostech_MotionDriver.Instance.PoseCalibration();
		if(!result)
		{
			Debug.LogError("豸");
		}
	}


	/// <summary>
	/// 豸
	/// </summary>
	/// <param name="left"></param>
	/// <param name="right"></param>
	public void UpDateDeviceInfo(int left,int right)
	{
		leftHandGetPacketRate.text = "ֵð:" + left;
		rightHandGetPacketRate.text = "ֵð:" + right;
	}

	public void Quit()
	{
		Application.Quit();
	}


	/// <summary>
	/// UIʾ־
	/// </summary>
	/// <param name="log"></param>
	public void ShowLog(string log)
	{
		if (text_Log.gameObject.activeInHierarchy)
		{
			queue.Enqueue(log);
		}
		else
		{
			text_Log.gameObject.SetActive(true);
			text_Log.text = log;
			Invoke("HideLog", 2f);
		}
	}

	//ʾ
	private void HideLog()
	{
		text_Log.gameObject.SetActive(false);
		string log;
		if (queue.TryDequeue(out log))
		{
			ShowLog(log);
		}
	}

}
