void Update() { if (calibrating) { if (currentState != POSE_ACTION_STATE.STANDING_IN_T_POSE || System.DateTime.Now.CompareTo(calibrationStartTime) < 0) { // Don't start adjustment yet, MUST stand i T-pose first return; } if (System.DateTime.Now.CompareTo(calibrationEndTime) > 0) { // Adjustment time has ended handleAdjustmentInfo(); calibrating = false; currentState = POSE_ACTION_STATE.NONE; } else { Debug.Log("Adjusting..."); readAdjustmentInfo(); return; // Adjustment handled } } }
private void onStandingInTPose(START_END state, BodyPositionState pose) { if (state == START_END.STARTING) { currentState = POSE_ACTION_STATE.STANDING_IN_T_POSE; } else { currentState = POSE_ACTION_STATE.NONE; } }
private void onCrouching(START_END state, BodyPositionState pose) { if (state == START_END.STARTING) { currentState = POSE_ACTION_STATE.CROUCHING; } else { currentState = POSE_ACTION_STATE.NONE; } }
private void onJumping(START_END state, BodyPositionState pose) { if (state == START_END.STARTING) { currentState = POSE_ACTION_STATE.JUMPING; } else { currentState = POSE_ACTION_STATE.NONE; } }
/** * Processing if we are moving in to a new state. * If so we also notify about this to any event listeners. */ private void processCalcState(BodyPositionState pose) { if (calibrating) { // Check for T-pose bool standingInTPose = isStandingInTPose(pose); if (standingInTPose) { // if this has been the same for more than x ms -> go to T-pose if (currentState != POSE_ACTION_STATE.STANDING_IN_T_POSE) { calibrationEndTime = System.DateTime.Now; calibrationStartTime = System.DateTime.Now; calibrationStartTime = calibrationStartTime.AddSeconds(calibrationDelay); calibrationEndTime = calibrationEndTime.AddSeconds(secsForCalibration + calibrationDelay); currentState = POSE_ACTION_STATE.STANDING_IN_T_POSE; if (onStandingInTPose != null) { onStandingInTPose(START_END.STARTING, pose); } if (onPoseCalibrationStarted != null) { onPoseCalibrationStarted(pose); } } } return; // We are calibrating -> no more handling } if (referencePose == null) { return; // ref pose not set -> we cannot process the states } if (currentState == POSE_ACTION_STATE.NONE) { if ((pose.root.y - referencePose.root.y) < crouchingAdjustment) { // We are crouching currentState = POSE_ACTION_STATE.CROUCHING; if (onCrouching != null) { onCrouching(START_END.STARTING, pose); } } else if ((pose.root.y - referencePose.root.y) > jumpingAdjustment) { // We are jumping currentState = POSE_ACTION_STATE.JUMPING; if (onJumping != null) { onJumping(START_END.STARTING, pose); } } else if (isStandingInTPose(pose)) { currentState = POSE_ACTION_STATE.STANDING_IN_T_POSE; if (onStandingInTPose != null) { onStandingInTPose(START_END.STARTING, pose); } } } else if (currentState == POSE_ACTION_STATE.CROUCHING) { if ((pose.root.y - referencePose.root.y) > crouchingAdjustment / 2) { // We are NOT crouching anymore currentState = POSE_ACTION_STATE.NONE; if (onCrouching != null) { onCrouching(START_END.ENDING, pose); } } } else if (currentState == POSE_ACTION_STATE.JUMPING) { if ((pose.root.y - referencePose.root.y) < jumpingAdjustment / 3) { // We are NOT jumping anymore currentState = POSE_ACTION_STATE.NONE; if (onJumping != null) { onJumping(START_END.ENDING, pose); } } } else if (currentState == POSE_ACTION_STATE.STANDING_IN_T_POSE) { if (!isStandingInTPose(pose)) { // We are NOT standing in T-pose anymore currentState = POSE_ACTION_STATE.NONE; if (onStandingInTPose != null) { onStandingInTPose(START_END.ENDING, pose); } } } }