storage optimized, end screen fixed, multi touch error fixed, error logs on server, fixes...

This commit is contained in:
2026-05-16 23:49:09 +05:30
parent 22e1a8cf50
commit 5d2eb3aaea
2589 changed files with 19080 additions and 267645 deletions
+189 -25
View File
@@ -2,6 +2,10 @@ using UnityEngine;
using Mirror;
using UnityEngine.EventSystems;
using System.Collections;
using LegacyTouchPhase = UnityEngine.TouchPhase;
#if ENABLE_INPUT_SYSTEM
using UnityEngine.InputSystem;
#endif
public class NetPlayer : NetworkBehaviour
{
@@ -88,6 +92,11 @@ public class NetPlayer : NetworkBehaviour
public Vector2 startPosition;
public float curPuckPullForce;
// Single drag at a time; extra fingers are ignored while isDragging.
bool isDragging;
Vector2 lastDragScreenPosition;
bool serverDragActive;
#region EMOTES
public void SendTextEmote(string txtName){
if(isServer){
@@ -171,29 +180,188 @@ public class NetPlayer : NetworkBehaviour
entry.callback.AddListener(OnDrag);
GameCanvas.instance.gameInputPanel.triggers.Add(entry);
}
bool TryGetPointerEvent(BaseEventData eventData, out PointerEventData pointerEventData)
{
pointerEventData = eventData as PointerEventData;
return pointerEventData != null;
}
static int CountPressedTouches()
{
#if ENABLE_INPUT_SYSTEM
if (Touchscreen.current != null)
{
int count = 0;
var touches = Touchscreen.current.touches;
for (int i = 0; i < touches.Count; i++)
{
if (touches[i].press.isPressed)
count++;
}
return count;
}
#endif
return Input.touchCount;
}
void UpdateDragScreenPosition(Vector2 screenPosition)
{
lastDragScreenPosition = screenPosition;
curPosition = screenPosition;
if (GameManager.SelectedPuck != null)
curPuckPullForce = GameManager.SelectedPuck.lineEnd.magnitude;
}
void Update()
{
if (!isLocalPlayer || !isDragging)
return;
if (!TryReadPointerHeld(out Vector2 screenPosition, out bool isPressed))
{
curPosition = lastDragScreenPosition;
return;
}
UpdateDragScreenPosition(screenPosition);
if (!isPressed && CountPressedTouches() == 0)
CompleteActivePointerDrag();
}
bool TryReadPointerHeld(out Vector2 screenPosition, out bool isPressed)
{
screenPosition = lastDragScreenPosition;
isPressed = false;
#if ENABLE_INPUT_SYSTEM
if (Touchscreen.current != null)
{
var primary = Touchscreen.current.primaryTouch;
if (primary.press.isPressed)
{
screenPosition = primary.position.ReadValue();
isPressed = true;
return true;
}
if (primary.press.wasReleasedThisFrame)
{
screenPosition = primary.position.ReadValue();
return true;
}
var touches = Touchscreen.current.touches;
for (int i = 0; i < touches.Count; i++)
{
var touch = touches[i];
if (!touch.press.isPressed)
continue;
screenPosition = touch.position.ReadValue();
isPressed = true;
return true;
}
}
if (Mouse.current != null)
{
if (Mouse.current.leftButton.isPressed)
{
screenPosition = Mouse.current.position.ReadValue();
isPressed = true;
return true;
}
if (Mouse.current.leftButton.wasReleasedThisFrame)
{
screenPosition = Mouse.current.position.ReadValue();
return true;
}
}
#endif
if (Input.touchCount > 0)
{
UnityEngine.Touch touch = Input.GetTouch(0);
screenPosition = touch.position;
isPressed = touch.phase != LegacyTouchPhase.Ended && touch.phase != LegacyTouchPhase.Canceled;
return true;
}
if (Input.GetMouseButton(0))
{
screenPosition = Input.mousePosition;
isPressed = true;
return true;
}
if (Input.GetMouseButtonUp(0))
{
screenPosition = Input.mousePosition;
return true;
}
return false;
}
void CompleteActivePointerDrag()
{
if (!isDragging)
return;
if (CountPressedTouches() > 0)
return;
isDragging = false;
if (GameManager.SelectedPuck == null)
return;
if (GameManager.instance == null)
return;
if (GameManager.instance.SelectedTeam != myTeam)
return;
Vector2 direction = GameManager.SelectedPuck.lineEnd;
CmdOnPointerUp(direction);
if (CameraEffects.instance != null)
CameraEffects.instance.ReleaseStretchFactor();
}
void OnPointerDown(BaseEventData eventData){
if(GameManager.instance == null){return;}
if(GameManager.instance.SelectedTeam != myTeam){return;}
if(GameManager.instance.m_isMoving){return;}
if(isDragging){return;}
if(CountPressedTouches() > 1){return;}
if(!TryGetPointerEvent(eventData, out PointerEventData pointerEventData)){return;}
PointerEventData pointerEventData = eventData as PointerEventData;
Vector2 position = pointerEventData.position;
Vector3 worldPosition = Camera.main.ScreenToWorldPoint(new Vector3(position.x, position.y, Camera.main.nearClipPlane));
curPosition= position;
Puck closestPuck = GameManager.instance.GetClosestPuck(worldPosition);
GameManager.SelectedPuck = closestPuck;
//Temporarily set the puck until server validates
if (closestPuck == null)
return;
isDragging = true;
UpdateDragScreenPosition(position);
GameManager.SelectedPuck = closestPuck;
CmdOnPointerDown(worldPosition);
}
[Command]
void CmdOnPointerDown(Vector2 position){
if(GameManager.instance.SelectedTeam != myTeam){return;}
if (GameManager.instance == null)
return;
if (serverDragActive)
return;
if (GameManager.instance.SelectedTeam != myTeam)
return;
Puck closestPuck = GameManager.instance.GetClosestPuck(position);
if (closestPuck == null || closestPuck.gameObject == null)
return;
serverDragActive = true;
GameManager.SelectedPuck = closestPuck;
RpcOnPointerDown(closestPuck.gameObject);
}
@@ -212,31 +380,27 @@ public class NetPlayer : NetworkBehaviour
void OnDrag(BaseEventData eventData){
PointerEventData pointerEventData = eventData as PointerEventData;
curPosition = pointerEventData.position;
if(GameManager.SelectedPuck!=null){
curPuckPullForce = GameManager.SelectedPuck.lineEnd.magnitude;
}
if(!isDragging){return;}
if(!TryGetPointerEvent(eventData, out PointerEventData pointerEventData)){return;}
UpdateDragScreenPosition(pointerEventData.position);
}
void OnPointerUp(BaseEventData eventData){
if(GameManager.SelectedPuck==null){return;}
if(GameManager.instance.SelectedTeam != myTeam){return;}
PointerEventData pointerEventData = eventData as PointerEventData;
Vector2 position = pointerEventData.position;
Vector2 direction = GameManager.SelectedPuck.lineEnd;
CmdOnPointerUp(direction);
CameraEffects.instance.ReleaseStretchFactor();
if(!isDragging){return;}
if(TryGetPointerEvent(eventData, out PointerEventData pointerEventData))
UpdateDragScreenPosition(pointerEventData.position);
if (CountPressedTouches() > 0)
return;
CompleteActivePointerDrag();
}
[Command]
void CmdOnPointerUp(Vector2 direction){
if(GameManager.instance.SelectedTeam != myTeam){return;}
serverDragActive = false;
if (GameManager.instance == null)
return;
if (GameManager.instance.SelectedTeam != myTeam)
return;
Debug.Log("Pointer up");