public virtual void ReadState(PlayerState outState) { if (!string.IsNullOrEmpty(errorDetails)) { outState.ErrorDetails = errorDetails; Debug.LogError(errorDetails); return; } FinchUpdateError err = FinchUpdateError.NotInitialized; if (FinchSettings.HeadUpdateType == FinchHeadUpdateType.RotationUpdate) { err = FinchCore.Update(FinchVR.MainCamera != null ? FinchVR.MainCamera.rotation.ToFinch() : Camera.main.transform.rotation.ToFinch()); } else if (FinchSettings.HeadUpdateType == FinchHeadUpdateType.RotationAndPositionUpdate) { err = FinchCore.Update(FinchVR.MainCamera.rotation.ToFinch(), FinchVR.MainCamera.position.ToFinch()); } else { err = FinchCore.Update(); } if (err != FinchUpdateError.None) { outState.ErrorDetails = "Error update Dash controller data: " + err; Debug.LogError(outState.ErrorDetails); } for (int i = 0; i < (int)FinchChirality.Last; ++i) { outState.ElementsBeginEvents[i] = FinchCore.GetEvents((FinchChirality)i, FinchEventType.Begin); outState.ElementsState[i] = FinchCore.GetEvents((FinchChirality)i, FinchEventType.Process); outState.ElementsEndEvents[i] = FinchCore.GetEvents((FinchChirality)i, FinchEventType.End); outState.IsTouching[i] = FinchCore.GetEvent((FinchChirality)i, FinchControllerElement.Touchpad, FinchEventType.Process); outState.TouchAxes[i] = FinchCore.GetTouchpadAxes((FinchChirality)i); outState.IndexTrigger[i] = FinchCore.GetIndexTrigger((FinchChirality)i); } for (int i = 0; i < (int)FinchNodeType.Last; ++i) { outState.Gyro[i] = FinchCore.GetBoneLocalAngularVelocity(PlayerState.Bones[(FinchNodeType)i]); outState.Accel[i] = FinchCore.GetBoneLocalAcceleration(PlayerState.Bones[(FinchNodeType)i]); } outState.NodesState = FinchCore.NodesState; if (FinchCore.ControllerType == FinchControllerType.Hand) { UpdateLongPressDetection(FinchControllerElement.Touchpad, true, outState); UpdateCalibrationDelay(outState); } else { UpdateLongPressDetection(FinchControllerElement.ButtonZero, false, outState); } }
protected static void UpdateLongPressDetection(FinchControllerElement element, bool handsDevice, PlayerState outState) { for (FinchChirality i = 0; i < FinchChirality.Last; ++i) { if (handsDevice) { calibrationButtonState[(int)i] = false; } else { outState.CalibrationButtonPressed[(int)i] = false; } if (FinchCore.GetEvent(i, element, FinchEventType.Begin)) { calibrationLongPressStopWatch[(int)i].Start(); } if (FinchCore.GetEvent(i, element, FinchEventType.End)) { calibrationLongPressStopWatch[(int)i].Reset(); } if (calibrationLongPressStopWatch[(int)i].ElapsedMilliseconds >= LongPressTimeMs) { if (handsDevice) { calibrationButtonState[(int)i] = true; } else { outState.CalibrationButtonPressed[(int)i] = true; calibrationLongPressStopWatch[(int)i].Reset(); } } } }
/// <summary> /// Returns element pressing state. /// </summary> /// <param name="node">Certain node</param> /// <param name="element">Controller element</param> /// <returns>Is the controller element pressed</returns> public static bool GetPress(FinchNodeType node, FinchControllerElement element) { return(FinchCore.GetEvent(node, element)); }