public void ResetControls() { navStateForward = NavState.Off; navStateBack = NavState.Off; navStateLeft = NavState.Off; navStateRight = NavState.Off; navValForward = 0; navValBack = 0; navValLeft = 0; navValRight = 0; navStateForwardLeft = NavState.Off; navStateForwardRight = NavState.Off; navStateBackLeft = NavState.Off; navStateBackRight = NavState.Off; navValForwardLeft = 0; navValForwardRight = 0; navValBackLeft = 0; navValBackRight = 0; forwardKey = false; backKey = false; inputVert = 0f; inputHorz = 0f; }
protected virtual void OnEnable() { m_state = serializedObject.targetObject as NavState; m_transitions = serializedObject.FindProperty("Transitions"); m_transitionList = new ReorderableList(serializedObject, m_transitions, true, false, true, true); m_transitionList.drawElementCallback = DrawElement; m_transitionList.drawHeaderCallback = DrawHeader; }
private void WebService_OnDisconnected(string ip) { Debug.Log("Disconnected: " + ip); if (ip == firstConnectedIP) { // Searchシーンに戻る NavigationState = NavState.Ready; actionDoMainThreads.Enqueue(() => { SceneManager.LoadScene("Search"); }); } }
private void ChangeState(NavState state) { switch (state) { case NavState.GREEN: spriteRenderer.sprite = AntennaSprites[0]; break; case NavState.YELLOW: spriteRenderer.sprite = AntennaSprites[1]; break; case NavState.RED: spriteRenderer.sprite = AntennaSprites[2]; break; case NavState.LOSTSIGNAL: spriteRenderer.sprite = AntennaSprites[3]; Value = 5; GameOver(); break; } }
private void OnRotateComplete(dynamic json) { if (subState == NavState.Rotating && ((string)json.V).Equals("1")) { Trace.t(cc.Good, "Rotate completed"); subState = NavState.MoveStart; } }
void OnNavigating() { float distToMove; if (CurrentWayPoint.isAction) distToMove = DistanceToWayPoint - .6F; else distToMove = DistanceToWayPoint; if (distToMove < 0) distToMove = 0; if (subState == NavState.MoveStart) { Trace.t(cc.Norm, "Navigating MoveStart"); lastHdg = hdgToWayPoint; if (CurrentWayPoint.isAction) { if (distToMove > 0) { Trace.t(cc.Norm, string.Format("action moving {0}", distToMove)); Program.Pilot.Send(new { Cmd = "MOV", Pwr = moveSpeed, Hdg = hdgToWayPoint, Dist = distToMove }); } else { Trace.t(cc.Norm, "action moving; BeginApproach"); BeginApproach(); } } else { Trace.t(cc.Norm, string.Format("moving {0}", distToMove)); Program.Pilot.Send(new { Cmd = "MOV", Pwr = moveSpeed, Hdg = hdgToWayPoint, Dist = distToMove }); } lastMoveCmdAt = DateTime.Now; subState = NavState.Moving; } else if (subState == NavState.Moving) { if (DateTime.Now > lastMoveCmdAt + moveCmdInterval) { Trace.t(cc.Norm, "Move (update)"); Program.Pilot.Send(new { Cmd = "MOV", Pwr = moveSpeed, Hdg = hdgToWayPoint, Dist = distToMove }); lastMoveCmdAt = DateTime.Now; } } }
void OnIdle() { Trace.t(cc.Norm, "OnIdle"); if (Program.WayPoints == null || Program.WayPoints.Count == 0) { Program.Pilot.Send(new { Cmd = "MOV", M1 = 0, M2 = 0 }); // make sure we're stopped Trace.t(cc.Norm, "Finished"); Program.State = RobotState.Finished; CurrentWayPoint = null; Program.Pilot.Send(new { Cmd = "ROT", Hdg = 0 }); // todo for convience, rotate to 0 at end } else { Trace.t(cc.Norm, "Pop Waypoint"); CurrentWayPoint = Program.WayPoints.Pop(); if (EscapeInProgress && CurrentWayPoint == EscapeWaypoint) EscapeInProgress = false; Program.State = RobotState.Navigating; if (DistanceToWayPoint > .05) { subState = NavState.Rotating; Timeout = DateTime.Now + rotateTimeout; lastHdg = hdgToWayPoint; Trace.t(cc.Norm, "Rotating"); Program.Pilot.Send(new { Cmd = "ROT", Hdg = lastHdg }); subState = NavState.Rotating; } else { Trace.t(cc.Norm, "Moving"); subState = NavState.MoveStart; } } }
void OnBumperEvent(dynamic json) { //? should not get here during approach, because our spin flag will be set if (((string)json.V).Equals("1") ) { // obstacle!!!!! Trace.t(cc.Bad, "Unexpected Bumper"); Program.Pilot.Send(new { Cmd = "Mov", M1 = 0, M2 = 0 }); subState = NavState.BumperReverse; Program.Pilot.Send(new { Cmd = "Mov", Pwr = -30, Dist = .5F }); Program.Pilot.waitForEvent(); // todo obstacle during escape Program.State = RobotState.eStop; // todo add avoidance return; // save current waypoint // if !escaping: // (re)push current // push new Waypoint for avoid // escaping = true if (!EscapeInProgress) { Program.WayPoints.Push(CurrentWayPoint); EscapeInProgress = true; EscapeWaypoint = CurrentWayPoint; // when we get there we'll know the escape worked } WayPoint bypassWaypoint = new WayPoint { }; // todo finish Program.WayPoints.Push(bypassWaypoint); Program.State = RobotState.Idle; } }
private void UpdateNavChannel(NavState previousNavState, float previousNavVal, bool keyPressed, float incStep, float decStep) { newNavState = previousNavState; newNavVal = previousNavVal; switch (previousNavState) { case NavState.Off: if (keyPressed) { newNavState = NavState.Inc; newNavVal = previousNavVal + incStep; if (newNavVal >= 1f) { newNavState = NavState.Full; newNavVal = 1f; } } else { newNavVal = 0f; } break; case NavState.Inc: if (keyPressed) { newNavVal = previousNavVal + incStep; if (newNavVal >= 1f) { newNavState = NavState.Full; newNavVal = 1f; } } else { newNavState = NavState.Dec; newNavVal = previousNavVal - decStep; if (newNavVal <= 0f) { newNavState = NavState.Off; newNavVal = 0f; } } break; case NavState.Full: if (keyPressed) { newNavVal = 1f; } else { newNavState = NavState.Dec; newNavVal = previousNavVal - decStep; if (newNavVal <= 0f) { newNavState = NavState.Off; newNavVal = 0f; } } break; case NavState.Dec: if (keyPressed) { newNavState = NavState.Inc; newNavVal = previousNavVal + incStep; if (newNavVal >= 1f) { newNavState = NavState.Full; newNavVal = 1f; } } else { newNavVal = previousNavVal - decStep; if (newNavVal <= 0f) { newNavState = NavState.Off; newNavVal = 0f; } } break; } }
//=================================== //=================================== // CONTROL PROCESSING //=================================== //=================================== //-------------------------------------------- // ProcessControls() // // This is the main entry point for input // processing, called at the beginning of // the main Update() function in LevelManager //-------------------------------------------- public void ProcessControls(string gameState) { // initialize key states to 'off' bool keyStateForward = false; bool keyStateBack = false; bool keyStateDiagLeft = false; bool keyStateDiagRight = false; bool keyStateTurnLeft = false; bool keyStateTurnRight = false; // check for pressed mouse within any of the onscreen rects if (Input.GetMouseButton(0)) { float mouseX = Input.mousePosition.x; float mouseY = Screen.height - Input.mousePosition.y; if (mouseX >= rectForward.xMin && mouseX <= rectForward.xMax && mouseY >= rectForward.yMin && mouseY <= rectForward.yMax) { keyStateForward = true; } if (mouseX >= rectBack.x && mouseX <= rectBack.x + rectBack.width && mouseY >= rectBack.y && mouseY <= rectBack.y + rectBack.height) { keyStateBack = true; } if (mouseX >= rectDiagLeft.x && mouseX <= rectDiagLeft.x + rectDiagLeft.width && mouseY >= rectDiagLeft.y && mouseY <= rectDiagLeft.y + rectDiagLeft.height) { keyStateDiagLeft = true; } if (mouseX >= rectDiagRight.x && mouseX <= rectDiagRight.x + rectDiagRight.width && mouseY >= rectDiagRight.y && mouseY <= rectDiagRight.y + rectDiagRight.height) { keyStateDiagRight = true; } if (mouseX >= rectTurnLeft.x && mouseX <= rectTurnLeft.x + rectTurnLeft.width && mouseY >= rectTurnLeft.y && mouseY <= rectTurnLeft.y + rectTurnLeft.height) { keyStateTurnLeft = true; } if (mouseX >= rectTurnRight.x && mouseX <= rectTurnRight.x + rectTurnRight.width && mouseY >= rectTurnRight.y && mouseY <= rectTurnRight.y + rectTurnRight.height) { keyStateTurnRight = true; } } // check for relevant keys pressed on the physical keyboard if (Input.GetKey(KeyCode.I) || Input.GetKey(KeyCode.UpArrow)) { keyStateForward = true; } if (Input.GetKey(KeyCode.K) || Input.GetKey(KeyCode.DownArrow)) { keyStateBack = true; } if (Input.GetKey(KeyCode.U)) { keyStateDiagLeft = true; } if (Input.GetKey(KeyCode.O)) { keyStateDiagRight = true; } if (Input.GetKey(KeyCode.J) || Input.GetKey(KeyCode.LeftArrow)) { keyStateTurnLeft = true; } if (Input.GetKey(KeyCode.L) || Input.GetKey(KeyCode.RightArrow)) { keyStateTurnRight = true; } // set the heading to either straight ahead or diagonal if (keyStateForward == true) { levelManager.pumaHeadingOffset = 0f; } if (keyStateDiagLeft == true) { levelManager.pumaHeadingOffset = -60f; keyStateForward = true; } else if (keyStateDiagRight == true) { levelManager.pumaHeadingOffset = 60f; keyStateForward = true; } // deal with interactions between forward and back keys if (inputVert == 0) { if (forwardKey == false) { forwardKey = keyStateForward; } if (forwardKey == false) { backKey = keyStateBack; } } else if (inputVert > 0) { if (forwardKey == false) { forwardKey = keyStateForward; } else if (keyStateBack == true) { forwardKey = false; } } else { if (backKey == false) { backKey = keyStateBack; } else if (keyStateForward == true) { backKey = false; } } // now do main input processing UpdateNavChannel(navStateForward, navValForward, forwardKey, Time.deltaTime * 3, Time.deltaTime * 3); navStateForward = newNavState; navValForward = newNavVal; UpdateNavChannel(navStateBack, -navValBack * 2, backKey, Time.deltaTime * 3, Time.deltaTime * 3); navStateBack = newNavState; navValBack = -newNavVal / 2; UpdateNavChannel(navStateLeft, -navValLeft, keyStateTurnLeft, Time.deltaTime * ((gameState == "gameStateStalking") ? 3f : 4.4f), Time.deltaTime * 3); navStateLeft = newNavState; navValLeft = -newNavVal; UpdateNavChannel(navStateRight, navValRight, keyStateTurnRight, Time.deltaTime * ((gameState == "gameStateStalking") ? 3f : 4.4f), Time.deltaTime * 3); navStateRight = newNavState; navValRight = newNavVal; //inputVert = navValForward; // disable backward motion inputVert = navValForward + navValBack; // enable backward motion inputHorz = navValRight + navValLeft; if (inputVert == 0) { // reset heading when puma stopped levelManager.pumaHeadingOffset = 0; } }