public void Reset() { m_state = AccumulateOffsetState; m_command_crc = 0; m_offset = Vector3.zero; if (m_task != null) { m_task.Cancel(); RenderTask.Recycle(m_task); m_task = null; } }
void PredictEntityMove(EntityMoveCommand cmd) { switch (cmd.m_move_type) { case EntityMoveCommand.DirectionType: { m_copy_state = NoCopy; bool exist = false; uint crc = CalculateMoveCommandCRC(cmd); //LogWrapper.LogDebug("PredictEntityMove, DirectionType, time =", GetCurrentTime(), ", dir = ", cmd.m_vector.ToString(), ", crc = ", crc); for (int i = 0; i < m_movement_predicts.Count; ++i) { MovementPredict predict = m_movement_predicts[i]; if (predict.m_command_crc == crc) { if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState) { exist = true; } } else if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState) { predict.m_state = MovementPredict.EliminateOffsetState; predict.m_task.Cancel(); } } if (!exist) { Vector3 direction = RenderWorld.Vector3FP_To_Vector3(cmd.m_vector); PredictLocomotionTask task = RenderTask.Create <PredictLocomotionTask>(); task.Construct(this, direction, m_max_predict_time); var task_scheduler = GetRenderWorld().GetTaskScheduler(); task_scheduler.Schedule(task, GetRenderWorld().CurrentTime, FixPoint.PrecisionFP); MovementPredict predict = RecyclableObject.Create <MovementPredict>(); predict.m_state = MovementPredict.AccumulateOffsetState; predict.m_command_crc = crc; predict.m_task = task; m_movement_predicts.Add(predict); PlayMoveAnimation(direction); } } break; case EntityMoveCommand.DestinationType: { if (m_copy_state == NoCopy) { m_copy_state = WaitCopy; } //下面这段代码和EntityMoveCommand.StopMoving差不多 for (int i = 0; i < m_movement_predicts.Count; ++i) { MovementPredict predict = m_movement_predicts[i]; if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState) { predict.m_state = MovementPredict.EliminateOffsetState; predict.m_task.Cancel(); } } MovementPredict temp = RecyclableObject.Create <MovementPredict>(); temp.m_state = MovementPredict.CopyLogicState; m_movement_predicts.Add(temp); Vector3 direction = RenderWorld.Vector3FP_To_Vector3(cmd.m_vector) - m_model_component.GetCurrentPosition(); PlayMoveAnimation(direction); } break; case EntityMoveCommand.StopMoving: { m_copy_state = NoCopy; for (int i = 0; i < m_movement_predicts.Count; ++i) { MovementPredict predict = m_movement_predicts[i]; if (predict.m_state == MovementPredict.AccumulateOffsetState || predict.m_state == MovementPredict.FollowLogicState) { predict.m_state = MovementPredict.EliminateOffsetState; predict.m_task.Cancel(); } } MovementPredict temp = RecyclableObject.Create <MovementPredict>(); temp.m_state = MovementPredict.StopState; m_movement_predicts.Add(temp); StopMoveAnimation(); //LogWrapper.LogDebug("PredictEntityMove, StopMoving, time =", GetCurrentTime()); } break; default: break; } }