void GrabUpdate(CustomHand hand) { if ((rightHand || leftHand) && GetMyGrabPoserTransform(hand)) { hand.SkeletonUpdate(); GetComponentInChildren <MeshRenderer>().material.color = Color.grey; float tempDistance = Mathf.Clamp(StartButtonPosition - (StartButtonPosition - transform.InverseTransformPoint(hand.PivotPoser.position).z) * DistanceMultiply, StartButtonPosition, distanseToPress); if (tempDistance >= distanseToPress) { GetComponentInChildren <MeshRenderer>().material.color = Color.blue; if (!press) { ButtonDown.Invoke(); } press = true; ButtonUpdate.Invoke(); } else { if (press) { ButtonUp.Invoke(); } press = false; } MoveObject.localPosition = new Vector3(0, 0, tempDistance); MoveObject.rotation = Quaternion.LookRotation(GetMyGrabPoserTransform(hand).forward, hand.PivotPoser.up); hand.GrabUpdateCustom(); } }
private async void StartListener() { try { while (_connected) { try { var ret = await _streamReader.ReadLineAsync(); if (ret == null) { Debug.WriteLine("Connection closed gracefully"); return; } Debug.WriteLine($"Got some text: {ret}"); _gotText?.Invoke(ret); if (ret.StartsWith("S:LOAD ") || ret.StartsWith("R:GETLOAD ")) { //LOAD 123 55.0 var(vid, percent) = ret.ParseLoad(); LoadUpdate?.Invoke(vid, percent); } else if (ret.StartsWith("S:TASK ") || ret.StartsWith("R:GETTASK ")) { var(vid, state) = ret.ParseTask(); TaskUpdate?.Invoke(vid, state); } else if (ret.StartsWith("S:BTN ")) { var(vid, mode) = ret.ParseButton(); ButtonUpdate?.Invoke(vid, mode); } else if (ret.StartsWith("S:LED ") || ret.StartsWith("R:GETLED ")) { var led = ret.ParseLed(); LedUpdate?.Invoke(led.Vid, led.State); } else if (ret.StartsWith("R:GETTHERMTEMP ")) { var t = ret.ParseThermTemp(); TemperatureSensorUpdate?.Invoke(t.Vid, t.Sensor, t.Temperature); } } catch { if (!_tcpClient.Connected) { Debug.WriteLine("disconnected"); _connected = false; } } } } finally { _gotText?.Invoke(null); } }