IEnumerator RestartBroadcasting() { yield return(null); NetworkTransport.StartBroadcastDiscovery(host, port, 1, 1, 1, new byte[1], 1, 2000, out error); PhoneServer.TestError(error); }
// Update is called once per frame private void Update() { if (server == null) { server = FindObjectOfType<PhoneServer>(); if (server == null) return; } var data = server.phones[number]; child.localRotation = data.gyroAttitude; if (Input.GetKeyDown(KeyCode.Space)) { parent.rotation = Quaternion.Inverse(data.gyroAttitude); offset = data.gyroAttitude; angle = data.compassMagneticHeading; } Vector3 gyro = child.eulerAngles; Vector3 angles = new Vector3(GetAngle(gyro, x), GetAngle(gyro, y), GetAngle(gyro, z)); transform.localEulerAngles = angles; }
// Use this for initialization private void Start() { server = FindObjectOfType <PhoneServer>(); parent = new GameObject("Gyro " + number).transform; child = new GameObject("Local gyro").transform; child.parent = parent; }
// Use this for initialization private void Start() { server = FindObjectOfType<PhoneServer>(); parent = new GameObject("Gyro " + number).transform; child = new GameObject("Local gyro").transform; child.parent = parent; }
// Update is called once per frame private void Update() { int rConn; int rChan; int rSize; Server server; var rec = NetworkTransport.ReceiveFromHost(host, out rConn, out rChan, data, data.Length, out rSize, out error); PhoneServer.TestError(error); ms.Position = 0; switch (rec) { case NetworkEventType.DataEvent: if (rChan == reliable) { server = servers.FirstOrDefault(s => s.connection == rConn); if (server == null) { break; } var key = reader.ReadString(); switch (key) { case "name": server.name = reader.ReadString(); break; case "vibrate": server.vibrate = reader.ReadSingle(); break; } } break; case NetworkEventType.ConnectEvent: server = new Server(rConn); server.send = !isConnected && string.IsNullOrEmpty(filter); servers.Add(server); UpdateConnected(); break; case NetworkEventType.DisconnectEvent: server = servers.FirstOrDefault(s => s.connection == rConn); servers.Remove(server); UpdateConnected(); break; case NetworkEventType.Nothing: break; case NetworkEventType.BroadcastEvent: break; } #if UNITY_ANDROID || UNITY_IOS if (servers.Count > 0 && servers.Max(s => s.send ? s.vibrate : 0) > 0.5f) { Handheld.Vibrate(); } #endif if (Time.time > timer && isConnected) { timer = Time.time + 1f / frequency; ms.Position = 0; writer.Write(number); WriteStatus(); for (int i = 0; i < servers.Count; i++) { if (servers[i].send) { NetworkTransport.Send(host, servers[i].connection, state, data, (int)ms.Position, out error); PhoneServer.TestError(error); } } } if (text != null) { string str = "Gyro: " + Input.gyro.attitude + "\nCompas: "******"F1") + "\nAcc: " + Input.acceleration + "\nSending #" + number + " with " + frequency + "Hz to:"; for (int i = 0; i < servers.Count; i++) { if (servers[i].send) { str += "\n" + servers[i].name; } } text.text = str; } if (Input.GetKeyDown(KeyCode.Escape)) { Application.Quit(); } }