// looking any available wp 2, and switch to the walking wp 2 state // if not, switch to the looking for waiting point state void Looking_For_WP_2() { // if the place is null, return to looking for wp 1 state if (!place) { state = STATE.Looking_WP_1; return; } spot = place.Any_Available_Spot(); // find a available spot if (spot) { // switch to walking state = STATE.Walking_to_WP_2; // set the destination agent.SetDestination(spot.transform.position); // play animation. role_controller.Play_Animation(HHK_Role_Controller.Walk); agent.speed = speed_walk; } // go to the waiting point // if there is no any waiting point, go back to the looking for wp 1 state else { if (place.waittingPoint) { // get the waiting point; waiting_point = place.waittingPoint; // go to the waitting line state = STATE.Walking_to_Waiting_Point; // join the line, and get the index of the line, // otherwise, looking for the next wp 1 if (!waiting_point.Join_To_This_Place(role)) { state = STATE.Looking_WP_1; return; } index_of_waiting_line = waiting_point.Get_My_Index(role); // set the destination agent.SetDestination(waiting_point.Get_My_Position(role)); // play animation. role_controller.Play_Animation(HHK_Role_Controller.Walk); agent.speed = speed_walk; } // switch to walking else { state = STATE.Looking_WP_1; } } }
// walking to the waiting point // keep checking the new waiting index of the line // keep checking any availabe spot void Walking_to_Waiting_Point() { if (!waiting_point) { state = STATE.Looking_WP_1; return; } // if at the right position, switch to the in spot state if (agent.desiredVelocity.magnitude <= speed_for_stop_limit) { state = STATE.In_Waiting_Line; // stop // agent.Stop(); // play animation. role_controller.Play_Animation(HHK_Role_Controller.Idle); } // keep checking the new waiting index of the line, move to the new position if (index_of_waiting_line != waiting_point.Get_My_Index(role)) { // go to the waitting line state = STATE.Walking_to_Waiting_Point; // join the line, and get the index of the line index_of_waiting_line = waiting_point.Get_My_Index(role); // set the destination agent.SetDestination(waiting_point.Get_My_Position(role)); // play animation. role_controller.Play_Animation(HHK_Role_Controller.Walk); agent.speed = speed_walk; } // keep checking any availabe spot if (index_of_waiting_line == 0) { spot = place.Any_Available_Spot(); if (spot) { // switch to walking to wp 2 state = STATE.Walking_to_WP_2; // leave this place waiting_point.Leave_From_This_Place(role); // join the wp2 spot.Join_From_The_Waiting_Line(role); // set the destination agent.SetDestination(spot.transform.position); // play animation role_controller.Play_Animation(HHK_Role_Controller.Walk); agent.speed = speed_walk; } } }
// in the waiting line // keep checking the new waiting index of the line // keep checking any availabe spot void In_the_Waiting_Line() { role_controller.Play(HHK_Role_Controller.AnimName.idle); if (!waiting_point) { state = STATE.Looking_WP_1; return; } // rotataion transform.rotation = Quaternion.Lerp(transform.rotation, waiting_point.transform.rotation, agent.angularSpeed * Time.deltaTime); // keep checking the new waiting index of the line, move to the new position if (index_of_waiting_line != waiting_point.Get_My_Index(role)) { // go to the new waiting position state = STATE.Walking_to_Waiting_Point; // join the line, and get the index of the line index_of_waiting_line = waiting_point.Get_My_Index(role); // set the destination agent.SetDestination(waiting_point.Get_My_Position(role)); // play animation. role_controller.Play(HHK_Role_Controller.AnimName.motion); agent.speed = speed_walk; } // keep checking any availabe spot if (index_of_waiting_line == 0) { spot = place.Any_Available_Spot(); if (spot) { // switch to walking to wp 2 state = STATE.Walking_to_WP_2; // leave this place waiting_point.Leave_From_This_Place(role); // join the wp2 spot.Join_From_The_Waiting_Line(role); // set the destination agent.SetDestination(spot.transform.position); // play animation role_controller.Play(HHK_Role_Controller.AnimName.motion); agent.speed = speed_walk; } } }
// in the waiting line // keep checking the new waiting index of the line // keep checking any availabe spot void In_the_Waiting_Line() { if (!waiting_point) { state = STATE.Looking_WP_1; return; } // keep checking the new waiting index of the line, move to the new position if (index_of_waiting_line != waiting_point.Get_My_Index(role)) { // go to the new waiting position state = STATE.Walking_to_Waiting_Point; // join the line, and get the index of the line index_of_waiting_line = waiting_point.Get_My_Index(role); // set the destination agent.SetDestination(waiting_point.Get_My_Position(role)); // play animation. } // keep checking any availabe spot if (index_of_waiting_line == 0) { spot = place.Any_Available_Spot(); if (spot) { // switch to walking to wp 2 state = STATE.Walking_to_WP_2; // leave this place waiting_point.Leave_From_This_Place(role); // join the wp2 spot.Join_From_The_Waiting_Line(role); // set the destination agent.SetDestination(spot.transform.position); // play animation } } }