diff --git a/client/client/Assets/Scripts/CoreGame/AFramSync/Render/View/JoystickRender.cs b/client/client/Assets/Scripts/CoreGame/AFramSync/Render/View/JoystickRender.cs index 9e44d2ac..ead7e5aa 100644 --- a/client/client/Assets/Scripts/CoreGame/AFramSync/Render/View/JoystickRender.cs +++ b/client/client/Assets/Scripts/CoreGame/AFramSync/Render/View/JoystickRender.cs @@ -18,13 +18,13 @@ namespace CoreGame.Render [HideInInspector] public Vector2 input = Vector2.zero; private RectTransform m_BaseRect; private Canvas m_Canvas; - private Vector2 m_StartPos = Vector2.zero; - private Vector2 m_StartPosInWorld = Vector2.zero; + // private Vector2 m_StartPos = Vector2.zero; + // private Vector2 m_StartPosInWorld = Vector2.zero; private bool m_IsPointDown; private Camera m_UICamera; [SerializeField] private Vector2 m_BackGroundOriginPos = new Vector2(0, -535); - private const float MinDist = 1000f; + private const float MinDist = 1f; private Coroutine m_JoystickCanvasCoroutine; private WaitForSeconds m_WaitForSeconds = new WaitForSeconds(1.0f); private bool m_IsForcePointerUp = false; @@ -42,18 +42,18 @@ namespace CoreGame.Render if (m_Canvas == null) Debug.LogError("The Joystick is not placed inside a canvas"); - Vector2 center = new(0.5f, 0.5f); - background.pivot = center; - - handle.anchorMin = center; - handle.anchorMax = center; - handle.pivot = center; - handle.anchoredPosition = Vector2.zero; + // Vector2 center = new(0.5f, 0.5f); + // background.pivot = center; + // + // handle.anchorMin = center; + // handle.anchorMax = center; + // handle.pivot = center; + // handle.anchoredPosition = Vector2.zero; m_IsPointDown = false; input = Vector2.zero; - background.anchoredPosition = m_BackGroundOriginPos; + // background.anchoredPosition = m_BackGroundOriginPos; // if (BattleModule.Instance.worldType == WorldType.Community) // { // m_JoystickCanvasCoroutine = StartCoroutine(CanvasGroupAlphaUpdate(0.5f)); @@ -64,9 +64,9 @@ namespace CoreGame.Render public void OnPointerDown(PointerEventData eventData) { m_IsForcePointerUp = false; - background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position); - m_StartPos = eventData.position; - m_StartPosInWorld = m_UICamera.ScreenToWorldPoint(eventData.position); + // background.anchoredPosition = ScreenPointToAnchoredPosition(eventData.position); + // m_StartPos = eventData.position; + // m_StartPosInWorld = m_UICamera.ScreenToWorldPoint(eventData.position); // if (BattleModule.Instance.worldType == WorldType.Community) // { // if (m_JoystickCanvasCoroutine != null) @@ -97,8 +97,8 @@ namespace CoreGame.Render return; if (m_IsPointDown == false) { - float dist = (eventData.position - m_StartPos).sqrMagnitude; - + // float dist = (eventData.position - m_StartPos).sqrMagnitude; + float dist = eventData.delta.sqrMagnitude; if (dist > MinDist) { SetPointer(true); @@ -108,15 +108,15 @@ namespace CoreGame.Render return; } - Vector2 position = background.anchoredPosition; - Vector2 radius = background.sizeDelta / 2; - Vector2 worldPoint = m_UICamera.ScreenToWorldPoint(eventData.position); - var posVector2 = ScreenPointToAnchoredPosition(eventData.position); + // Vector2 position = background.anchoredPosition; + // Vector2 radius = background.sizeDelta / 2; + // Vector2 worldPoint = m_UICamera.ScreenToWorldPoint(eventData.position); + // var posVector2 = ScreenPointToAnchoredPosition(eventData.position); // input = (posVector2 - position) / (radius * m_Canvas.scaleFactor); input = eventData.delta; - m_StartPosInWorld = worldPoint; + // m_StartPosInWorld = worldPoint; // HandleInput(input.magnitude, input.normalized); - handle.anchoredPosition = input * radius * handleRange; + // handle.anchoredPosition = input * radius * handleRange; } public void OnPointerUp(PointerEventData eventData) @@ -124,8 +124,8 @@ namespace CoreGame.Render if (m_IsForcePointerUp) return; input = Vector2.zero; - background.anchoredPosition = m_BackGroundOriginPos; - handle.anchoredPosition = Vector2.zero; + // background.anchoredPosition = m_BackGroundOriginPos; + // handle.anchoredPosition = Vector2.zero; SetPointer(false); // if (BattleModule.Instance.worldType == WorldType.Community) // { @@ -171,6 +171,7 @@ namespace CoreGame.Render private static readonly List s_InputRemove = new List(); private static float m_LruSpan = 1.5f; + private static float m_KeyBoardSpeed = 10f; private void Update() { @@ -180,19 +181,19 @@ namespace CoreGame.Render Vector2 direction = Vector2.zero; if (Input.GetKey(KeyCode.W) ) { - direction.y += 200; + direction.y += m_KeyBoardSpeed; } if (Input.GetKey(KeyCode.A) ) { - direction.x += -200; + direction.x += -m_KeyBoardSpeed; } if (Input.GetKey(KeyCode.S) ) { - direction.y += -200; + direction.y += -m_KeyBoardSpeed; } if (Input.GetKey(KeyCode.D)) { - direction.x += 200; + direction.x += m_KeyBoardSpeed; } // if (CoreUIBridge.s_InputKey.Count > 0) @@ -221,6 +222,7 @@ namespace CoreGame.Render m_IsInputCtrl = true; OnPointerDown(pointerEventData); pointerEventData.position = pos + direction; + pointerEventData.delta = direction; // 模拟拖动 OnDrag(pointerEventData); m_IsKeyBoardControl = true;