Example #1
0
    public void Send_Sync_Position(MoveSyncFlag reportToSever)
    {
        // trace
        if (m_pFSM == null)
        {
            Trace.LogError("CreatureState_Jomp.cs Send_Sync_Position m_pFSM == null");
            return;
        }

        //如果上报位置范围不对,则输出至LOG,退出
        if (float.IsNaN(tr.position.x) || float.IsNaN(tr.position.y) || float.IsNaN(tr.position.z) || Math.Abs(tr.position.x) > SceneManager.MAX_SCENE_SIZE || Math.Abs(tr.position.y) > SceneManager.MAX_SCENE_SIZE || Math.Abs(tr.position.z) > SceneManager.MAX_SCENE_SIZE)
        {
            Debug.LogError(m_pFSM.name + " Jumping Send_Sync_Position Position Error " + tr.position);
            return;
        }


        cmd_creature_rigidbody_sync data = new cmd_creature_rigidbody_sync();

        data.nCreatureState = (int)EntityState.Glide;
        data.fPosition_x    = tr.position.x;
        data.fPosition_y    = tr.position.y;
        data.fPosition_z    = tr.position.z;

        // 直接用欧拉角
        data.fRotation_x = tr.rotation.eulerAngles.x;
        data.fRotation_y = tr.rotation.eulerAngles.y;
        data.fRotation_z = tr.rotation.eulerAngles.z;

        data.fVelocity_x = m_pFSM.syncVelocity.x;
        data.fVelocity_y = m_pFSM.syncVelocity.y;
        data.fVelocity_z = m_pFSM.syncVelocity.z;
        data.nSyn2Server = (int)reportToSever;

        EntityEventHelper.Instance.SendCommand <cmd_creature_rigidbody_sync>(m_pFSM.entityID, EntityLogicDef.ENTITY_CMD_SET_POS, ref data);

        // 通知主角位置发生变化
        U3D_Render.EntityLocUpdate.SendActorLocationChange(new Vector3(tr.position.x, tr.position.y, tr.position.z));
        EntityBatchCommunicator.SendEntityPro(m_pFSM.entityID, tr.position, tr.rotation.eulerAngles);
    }
    ///////////////////////////////////////////////////////////////////////////////////////////////////////////
    // 发送一次位置同步
    public void Send_Sync_Position(MoveSyncFlag reportToSever)
    {
        if (m_pFSM == null)
        {
            Trace.LogError("CreatureState_Standing.cs Send_Sync_Position m_pFSM == null");
            return;
        }

        //如果上报位置范围不对,则输出至LOG,退出
        if (float.IsNaN(m_pFSM.syncPosition.x) || float.IsNaN(m_pFSM.syncPosition.y) || float.IsNaN(m_pFSM.syncPosition.z) || Math.Abs(m_pFSM.syncPosition.x) > SceneManager.MAX_SCENE_SIZE || Math.Abs(m_pFSM.syncPosition.y) > SceneManager.MAX_SCENE_SIZE || Math.Abs(m_pFSM.syncPosition.z) > SceneManager.MAX_SCENE_SIZE)
        {
            Debug.LogError(m_pFSM.name + " standing Send_Sync_Position Position Error " + m_pFSM.syncPosition);
            return;
        }


        cmd_creature_rigidbody_sync data = new cmd_creature_rigidbody_sync();

        data.nCreatureState = (int)EntityState.WallWalking;
        data.fPosition_x    = m_pFSM.syncPosition.x;
        data.fPosition_y    = m_pFSM.syncPosition.y;
        data.fPosition_z    = m_pFSM.syncPosition.z;

        // 直接用欧拉角
        data.fRotation_x = m_pFSM.syncAngle.x;
        data.fRotation_y = m_pFSM.syncAngle.y;
        data.fRotation_z = m_pFSM.syncAngle.z;

        data.fVelocity_x = m_pFSM.syncVelocity.x;
        data.fVelocity_y = m_pFSM.syncVelocity.y;
        data.fVelocity_z = m_pFSM.syncVelocity.z;
        data.nSyn2Server = (int)reportToSever;

        EntityEventHelper.Instance.SendCommand <cmd_creature_rigidbody_sync>(m_pFSM.entityID, EntityLogicDef.ENTITY_CMD_SET_POS, ref data);

        if (tr == null)
        {
            Trace.LogError("CreatureState_Standing.cs Send_Sync_Position tr == null");
            return;
        }

        if (tr.position == null)
        {
            Trace.LogError("CreatureState_WallWalking.cs Send_Sync_Position tr.SetPosition== null");
            return;
        }

        if (tr.rotation == null)
        {
            Trace.LogError("CreatureState_WallWalking.cs Send_Sync_Position tr.rotation == null");
            return;
        }

        if (tr.rotation.eulerAngles == null)
        {
            Trace.LogError("CreatureState_WallWalking.cs Send_Sync_Position tr.rotation.eulerAngles == null");
            return;
        }

        EntityBatchCommunicator.SendEntityPro(m_pFSM.entityID, tr.position, tr.rotation.eulerAngles);

        if (m_pFSM.isHero)
        {
            U3D_Render.EntityView ev = EntityFactory.getPlayerViewByID(m_pFSM.entityID);
            MapFinderManager.MoveObject(ref ev, tr.position);
        }
    }