// Use this for initialization void Start() { soc = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); vtData = new ViveTrackerData(); vtPosition = new Vector3(); vtRotation = new Quaternion(); vtVelocity = new Vector3(); vtAccel = new Vector3(); Thread pthread = new Thread(new ThreadStart(SocRecv)); recv = true; isDataFresh = false; lastUpdateTime = Time.time; pthread.Start(); }
void SocRecv() { UdpClient udpc = new UdpClient(10000); byte[] buf; while (recv) { IPEndPoint RemoteIpEndPoint = new IPEndPoint(IPAddress.Any, 0); buf = udpc.Receive(ref RemoteIpEndPoint); lock (lockObject) { string jsonString = Encoding.ASCII.GetString(buf); vtData = JsonUtility.FromJson <ViveTrackerData>(jsonString); isDataFresh = true; } } udpc.Close(); }