/******************************************************************************
 ͷ˽
  
*******************************************************************************/

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Newtonsoft.Json;

public class ServerInteraction : MonoBehaviour
{
	public static ServerInteraction Instance;

	public bool isShake = false;
	private void Awake()
	{
		Instance = this;
	}

	private void Update()
	{
		if (isShake)
		{
			Shake("100", 5, 2);
			isShake = false;
		}
	}

	/// <summary>
	/// 
	/// </summary>
	/// <param name="gloveID">id</param>
	/// <param name="shakePattern">ģʽ 0=0.5s 1=1s Դ5s</param>
	/// <param name="handType">1=  2=</param>
	public void Shake(string gloveID, int shakePattern, int handType)
	{
		if (shakePattern < 0)
		{
			shakePattern = 0;
		}
		if (shakePattern > 9)
		{
			shakePattern = 9;
		}

		if (handType < 1)
		{
			handType = 1;
		}
		if (handType > 2)
		{
			handType = 2;
		}

		Shake shake = new Shake();
		shake.control = "motorShake";
		shake.deviceId = "100";//ѡ
		shake.shakePattern = shakePattern;
		shake.nodeList = new List<int>() { handType };

		string sendData = JsonConvert.SerializeObject(shake);
		Debug.Log("﷢͵Ϣ:" + sendData);
		bool result = MotionSourceManager.Instance.SendMessage(sendData);

		if (result)
		{
			Debug.Log("-˷Ϣɹ");
		}
		else
		{
			Debug.Log("-˷Ϣʧ");
		}
	}
}



public class Shake
{
	public string control;
	public string deviceId;
	public int shakePattern;
	public List<int> nodeList;
}