コード例 #1
0
        void CreateModel()
        {
            m_unity_go = UnityResourceManager.Instance.CreateGameObject(m_asset_name);
            if (m_unity_go == null)
            {
                return;
            }

            if (m_bodyctrl_path != null)
            {
                m_bodyctrl_tr = m_unity_go.transform.FindChild(m_bodyctrl_path);
            }
            else
            {
                m_bodyctrl_tr = m_unity_go.transform;
            }
            m_bodyctrl_obj = m_bodyctrl_tr.gameObject;

            if (m_headctrl_path != null)
            {
                m_headctrl_tr = m_unity_go.transform.FindChild(m_headctrl_path);
            }
            if (m_headctrl_tr != null)
            {
                m_headctrl_obj = m_headctrl_tr.gameObject;
            }

            Entity logic_entity = GetLogicEntity();

            m_position_component = logic_entity.GetComponent(PositionComponent.ID) as PositionComponent;
            if (m_position_component != null)
            {
                m_last_position                = RenderWorld.Vector3FP_To_Vector3(m_position_component.CurrentPosition);
                m_bodyctrl_tr.localPosition    = m_last_position;
                m_bodyctrl_tr.localEulerAngles = new Vector3(0, (float)m_position_component.BaseAngle, 0);
                if (m_headctrl_tr != null)
                {
                    m_bodyctrl_tr.localEulerAngles = new Vector3(0, (float)m_position_component.HeadAngle, 0);
                }
            }

            UnityObjectBinding binding = m_bodyctrl_tr.gameObject.GetComponent <UnityObjectBinding>();

            if (binding == null)
            {
                binding = m_bodyctrl_tr.gameObject.AddComponent <UnityObjectBinding>();
            }
            binding.EntityID = logic_entity.ID;
        }
コード例 #2
0
 public bool UpdatePosition()
 {
     if (m_unity_go == null)
     {
         LogWrapper.LogError("ModelComponent.UpdatePosition, Object has already been destroyed!!!!!!!!!");
         return(false); //ZZWTODO
     }
     m_last_position = RenderWorld.Vector3FP_To_Vector3(m_position_component.CurrentPosition);
     if (m_predict_component != null)
     {
         m_predict_component.OnLogicUpdatePosition(m_last_position - m_bodyctrl_tr.localPosition);
     }
     m_bodyctrl_tr.localPosition = m_last_position;
     return(true);
 }
コード例 #3
0
        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;
            }
        }