private async void sendOutgoingPacket(messagePackage sendData) { try { if (sendData.bytes.Length > 1000000) { Debug.Log("Packet of length " + sendData.bytes.Length + " waiting to go out... But can't.. Because it is probably too huge..."); return; } lock (outputStream) { writer.UnicodeEncoding = Windows.Storage.Streams.UnicodeEncoding.Utf8; writer.ByteOrder = Windows.Storage.Streams.ByteOrder.LittleEndian; writer.WriteBytes(sendData.bytes); flush(); Debug.Log("Sent " + sendData.bytes.Length + " bytes."); } } catch (Exception e) { textOut("344" + e.ToString()); Debug.Log(e.ToString()); return; } }
void FixedUpdate() { if (!socketStarted && targetIPReady) { socketStarted = true; doSocketSetup(); } if (outputText != null) { outputText.text = currentOutput; } if (!outgoingQueue.IsEmpty) { messagePackage mp = null; outgoingQueue.TryDequeue(out mp); if (mp != null) { sendOutgoingPacket(mp); textOut("Packet Sent."); } } if (!incomingLineRenderers.IsEmpty) { lrStruct l = new lrStruct(); if (incomingLineRenderers.TryDequeue(out l)) { GameObject go = new GameObject(); go.transform.parent = this.gameObject.transform; LineRenderer lr = go.gameObject.AddComponent <LineRenderer>(); lr.material = new Material(LineRendererDefaultMaterial);//copy lr.material.color = new Color(l.r, l.g, l.b, l.a); lr.startWidth = l.sw; lr.endWidth = l.ew; lr.endColor = lr.startColor = new Color(l.r, l.g, l.b, l.a); /* some helpful notes * LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>(); * lineRenderer.material = new Material(Shader.Find("Sprites/Default")); * lineRenderer.widthMultiplier = 0.2f; * lineRenderer.positionCount = lengthOfLineRenderer; * * // A simple 2 color gradient with a fixed alpha of 1.0f. * float alpha = 1.0f; * Gradient gradient = new Gradient(); * gradient.SetKeys( * new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) }, * new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) } * ); * lineRenderer.colorGradient = gradient; */ } } //SendHeadsetLocation(); }
void FixedUpdate() { // Task t = HandleSocket(); // while(!t.IsCompleted) //{ // // } if (!socketStarted && targetIPReady) { socketStarted = true; setupSocket(); } if (!outgoingQueue.IsEmpty) { messagePackage mp = null; outgoingQueue.TryDequeue(out mp); if (mp != null) { sendOutgoingPacket(mp); } } if (!incomingLineRenderers.IsEmpty) { lrStruct l = new lrStruct(); if (incomingLineRenderers.TryDequeue(out l)) { LineRenderer lr = this.gameObject.AddComponent <LineRenderer>(); lr.material = new Material(LineRendererDefaultMaterial);//copy lr.material.color = new Color(l.r, l.g, l.b, l.a); lr.startWidth = l.sw; lr.endWidth = l.ew; lr.endColor = lr.startColor = new Color(l.r, l.g, l.b, l.a); } } //SendHeadsetLocation(); }
void FixedUpdate() { if (Camera.main != null) { headsetLocation = Camera.main.transform.position; headsetRotation = Camera.main.transform.rotation; if (lastCamPosSendTime + 0.5f < Time.realtimeSinceStartup) { SendHeadsetLocation(); lastCamPosSendTime = Time.realtimeSinceStartup; } } if (!socketStarted && targetIPReady) { socketStarted = true; doSocketSetup(); } if (doReconnect) { doReconnect = false; socketStarted = false; connected = false; doSocketSetup(); } if (!outgoingQueue.IsEmpty) { messagePackage mp = null; outgoingQueue.TryDequeue(out mp); if (mp != null) { sendOutgoingPacket(mp); } } if (undoLineRenderer) { undoLineRenderer = false; try { LineRenderer lr = lineRenderers.Pop(); lr.enabled = false; Destroy(lr.gameObject); } catch (Exception e) { } } if (!incomingLineRenderers.IsEmpty) { lrStruct l = new lrStruct(); if (incomingLineRenderers.TryDequeue(out l)) { if (l == null) { return; } GameObject go = new GameObject(); go.transform.parent = this.gameObject.transform; LineRenderer lr = go.AddComponent <LineRenderer>(); lr.material = new Material(LineRendererDefaultMaterial);//copy lr.material.color = new Color(l.r, l.g, l.b, l.a); lr.startWidth = l.sw; lr.endWidth = l.ew; lr.widthMultiplier = 1.0f; lr.endColor = lr.startColor = new Color(l.r, l.g, l.b, l.a); lr.SetVertexCount(l.verts.Length); //lr.positionCount = l.verts.Length; for (int i = 0; i < l.verts.Length; i++) { lr.SetPosition(i, l.verts[i]); } go.active = true; Gradient gradient = new Gradient(); gradient.SetKeys( new GradientColorKey[] { new GradientColorKey(lr.material.color, 0.0f), new GradientColorKey(lr.material.color, 1.0f) }, new GradientAlphaKey[] { new GradientAlphaKey(1.0f, 0.0f), new GradientAlphaKey(1.0f, 1.0f) } ); lr.colorGradient = gradient; lineRenderers.Push(lr); /* some helpful notes * LineRenderer lineRenderer = gameObject.AddComponent<LineRenderer>(); * lineRenderer.material = new Material(Shader.Find("Sprites/Default")); * lineRenderer.widthMultiplier = 0.2f; * lineRenderer.positionCount = lengthOfLineRenderer; * * // A simple 2 color gradient with a fixed alpha of 1.0f. * float alpha = 1.0f; * Gradient gradient = new Gradient(); * gradient.SetKeys( * new GradientColorKey[] { new GradientColorKey(c1, 0.0f), new GradientColorKey(c2, 1.0f) }, * new GradientAlphaKey[] { new GradientAlphaKey(alpha, 0.0f), new GradientAlphaKey(alpha, 1.0f) } * ); * lineRenderer.colorGradient = gradient; */ } } //SendHeadsetLocation(); }