ISAP/Assets/Scripts/Net/PersonMain.cs

102 lines
3.0 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Unity.Collections;
using UnityEngine;
public class PersonMain : MonoBehaviour
{
UdpConnect udp;
private void Awake()
{
udp = UdpConnect.Instance;
DontDestroyOnLoad(this.gameObject);
}
private void Start()
{
EventCenter.dispatcher.AddListener(MsgType.OnSetRoom, OnSetRoom);
}
private void OnSetRoom(Message evt)
{
//udp.InitSocket();
}
void Update()
{
//if (Input.GetKeyUp(KeyCode.W))
//{
// UIManager.Instance.ShowHint("生命体征呼吸次数100次每分");
//}
//if (Input.GetKeyUp(KeyCode.Q))
//{
// //int i = 0xff;
// ////char c = '\xff\';
// ////char[] chars = {0xff };
// //char[] data = { (char)0x00, (char)0xFF, (char)0x00, (char)0xFF, (char)0x5A, (char)0x02,
// // (char)0x02, (char)0x10, (char)0xFC, (char)0xFC, (char)0xFC };
// ////char[] data2 = {'' };
// //string str = "hello world";
// //int[] num = { 0, 1, 2, 3, 4, 5, };
// ////UdpConnect.Instance.SocketSend(data);
// //UdpConnect.Instance.SocketSend(str);
// ////UdpConnect.Instance.SocketSend(num);
// //int num = Convert.ToInt32(255);
// string head = Convert.ToString(255, 16) + Convert.ToString(0, 16) + Convert.ToString(255, 16)
// + Convert.ToString(0, 16) + Convert.ToString(255, 16);
// string end = Convert.ToString(252, 16) + Convert.ToString(252, 16) + Convert.ToString(252, 16);
// head = "ff 00 ff 00 ff ";//尾部+空格
// string type = "5a ";
// string length = "02 ";
// string data = "f0 00 ";
// end = "fc fc fc";
// //string str = head + end;
// string str = head + type + length + data + end;
// //char[] chars = str.ToCharArray();
// //char c = (char)0xff;
// var sendData = textWork16(str);
// string log = "";
// for (int i = 0; i < sendData.Length; i++)
// {
// log += sendData[i].ToString();
// }
// Debug.Log("我发送" + log);
// UdpConnect.Instance.SocketSend(str);
// //byte[] bytes = { 255,0,255,0,255 }; // 16进制表示的字符'\uffff'
// //char[] chars = Encoding.Unicode.GetChars(bytes);
// //Debug.Log(chars[0]); // 输出 '\uffff'
//}
}
private byte[] textWork16(string strText)
{
strText = strText.Replace(" ", "");
byte[] bText = new byte[strText.Length / 2];
for (int i = 0; i < strText.Length / 2; i++)
{
bText[i] = Convert.ToByte(Convert.ToInt32(strText.Substring(i * 2, 2), 16));
}
return bText;
}
/// <summary>
/// ff f f char = ff
/// </summary>
private void OnDestroy()
{
EventCenter.dispatcher.RemoveListener(MsgType.OnSetRoom, OnSetRoom);
}
}