egametang / ET

Unity3D Client And C# Server Framework
Other
8.6k stars 2.97k forks source link

ET8.1,在hotfixView包下的键盘移动,打包后移动速度比编辑器模式下快很多,表现不正常。 #602

Closed MrTigerZhang closed 1 month ago

MrTigerZhang commented 1 month ago

我在编辑器下正常移动,但是打包后一动就不正常了。 移动速度明显快了很多,不正常。 using System.Runtime.CompilerServices; using Unity.Mathematics; using UnityEngine;

namespace ET.Client { [EntitySystemOf(typeof(OperaComponent))] [FriendOf(typeof(OperaComponent))] public static partial class OperaComponentSystem { [EntitySystem] private static void Awake(this OperaComponent self) { self.mapMask = LayerMask.GetMask("Map"); }

    [EntitySystem]
    private static void Update(this OperaComponent self)
    {
        // HandleMouseInput(self);
        HandleKeyboardInput(self);
    }

    private static void HandleMouseInput(OperaComponent self)
    {
        if (Input.GetMouseButtonDown(1))
        {
            Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            if (Physics.Raycast(ray, out RaycastHit hit, 1000, self.mapMask))
            {
                C2M_PathfindingResult c2MPathfindingResult = C2M_PathfindingResult.Create();
                c2MPathfindingResult.Position = hit.point;
                self.Root().GetComponent<ClientSenderComponent>().Send(c2MPathfindingResult);
            }
        }
    }

    private static void HandleKeyboardInput(OperaComponent self)
    {
        float axisX = Input.GetAxis("Horizontal");
        float axisY = Input.GetAxis("Vertical");

        if (axisX == 0 && axisY == 0)
        {
            return;
        }

        long myId = self.Root().GetComponent<PlayerComponent>().MyId;
        Unit unit = self.Root().CurrentScene().GetComponent<UnitComponent>().Get(myId);
        float3 directionVector = new float3(axisX, 0, axisY);
        unit.Position += directionVector * 1 * 0.01f;
        quaternion targetRotation = quaternion.LookRotationSafe(directionVector, math.up());
        // 平滑插值
        unit.Rotation = math.slerp(unit.Rotation, targetRotation, 0.1f);
        Log.Debug($"{unit.Position}");
      //  unit.GetComponent<UnitTransformSyncCmp>().SyncTransformToServer().Coroutine();
    }

}

}

MrTigerZhang commented 1 month ago

ce

MrTigerZhang commented 1 month ago

测试了几圈,发现是update的deltaTime 不同,在编辑器模式下,打印出的时间间隔是13-16ms;打包后打印出的时间间隔是4-5ms/