storage optimized, end screen fixed, multi touch error fixed, error logs on server, fixes...
This commit is contained in:
@@ -418,10 +418,12 @@ public class GameManager : NetworkBehaviour
|
||||
}
|
||||
public static Puck SelectedPuck{
|
||||
get{
|
||||
return instance.selectedPuck;
|
||||
return instance != null ? instance.selectedPuck : null;
|
||||
}
|
||||
|
||||
set{
|
||||
if (instance == null)
|
||||
return;
|
||||
instance.SetSelectedPuck(value);
|
||||
}
|
||||
}
|
||||
@@ -444,6 +446,8 @@ public class GameManager : NetworkBehaviour
|
||||
|
||||
foreach (Puck puck in pucks)
|
||||
{
|
||||
if (puck == null)
|
||||
continue;
|
||||
if(puck.team != SelectedTeam){continue;}
|
||||
float dist = Vector2.Distance(position, puck.transform.position);
|
||||
if (dist < minDistance)
|
||||
@@ -459,6 +463,10 @@ public class GameManager : NetworkBehaviour
|
||||
Coroutine coroutinePostLaunch;
|
||||
public void OnPointerUp(Vector2 direction)
|
||||
{
|
||||
if(selectedPuck == null){
|
||||
return;
|
||||
}
|
||||
|
||||
if(direction.magnitude < puckDragMinClamp){
|
||||
selectedPuck = null;
|
||||
GameEvents.OnSelectedPuckChanged?.Invoke(null);
|
||||
|
||||
@@ -34,6 +34,7 @@ public class GameOverCanvas : MonoBehaviour
|
||||
public Button btnRematch;
|
||||
public Button btnLeave;
|
||||
public TMP_Text rematchWarningLoser;
|
||||
public TMP_Text txtBetRC;
|
||||
public TMP_Text txtRewardRC;
|
||||
public TMP_Text txtRewardCC;
|
||||
public TMP_Text countdownTxt;
|
||||
@@ -128,7 +129,7 @@ public class GameOverCanvas : MonoBehaviour
|
||||
|
||||
|
||||
void OnBtnLeaveGameClicked(){
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
GameManager.instance.Leave();
|
||||
}
|
||||
|
||||
void CollectOriginalPositionsAndScales(){
|
||||
@@ -246,7 +247,7 @@ public class GameOverCanvas : MonoBehaviour
|
||||
}
|
||||
|
||||
if(winningTeam == myTeam){
|
||||
rcPrize = 8.2f;
|
||||
rcPrize = CoinHelper.Format(GameManager.MatchRcPrizeCoins);
|
||||
}
|
||||
|
||||
btnRematch.interactable = winningTeam != myTeam;
|
||||
@@ -293,6 +294,8 @@ public class GameOverCanvas : MonoBehaviour
|
||||
StartCoroutine(CoroutineSetTextNumber(rcPrize, txtRewardRC, 10, "N1", "+", " RC"));
|
||||
StartCoroutine(CoroutineSetTextNumber(100, txtRewardCC, 100, "N0", "+", " CC"));
|
||||
|
||||
txtBetRC.text = CoinHelper.FormatString(GameManager.MatchRcPrizeCoins) + " RC";
|
||||
|
||||
yield return new WaitForSeconds(1f);
|
||||
|
||||
foreach (var item in comingDown)
|
||||
@@ -329,9 +332,11 @@ public class GameOverCanvas : MonoBehaviour
|
||||
yield return new WaitForSecondsRealtime(1f);
|
||||
}
|
||||
|
||||
LevelLoadManager.LoadLevel("MainMenu");
|
||||
|
||||
GameManager.instance.Leave();
|
||||
}
|
||||
|
||||
|
||||
public void ShowRematchPanel(){
|
||||
SetRematchPendingState(true);
|
||||
StartCoroutine(CoroutineShowRematchPanel());
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
@@ -16,6 +17,87 @@ public class NetManager : NetworkManager
|
||||
|
||||
static bool s_IntentionalClientDisconnect;
|
||||
|
||||
public override void Awake()
|
||||
{
|
||||
base.Awake();
|
||||
Transport.active.OnClientError += OnTransportClientError;
|
||||
}
|
||||
|
||||
void OnDestroy()
|
||||
{
|
||||
if (Transport.active != null)
|
||||
Transport.active.OnClientError -= OnTransportClientError;
|
||||
}
|
||||
|
||||
static void OnTransportClientError(TransportError error, string reason)
|
||||
{
|
||||
Logger.Log($"Transport client error ({error}): {reason}");
|
||||
}
|
||||
|
||||
public override void OnStartServer()
|
||||
{
|
||||
base.OnStartServer();
|
||||
Application.logMessageReceived += ForwardMirrorServerLogToLogger;
|
||||
Logger.Log("Mirror server exception logging enabled");
|
||||
}
|
||||
|
||||
|
||||
public override void OnServerError(NetworkConnectionToClient conn, TransportError error, string reason)
|
||||
{
|
||||
int connId = conn != null ? conn.connectionId : -1;
|
||||
Logger.Log($"Mirror server transport error (connId={connId}, {error}): {reason}");
|
||||
base.OnServerError(conn, error, reason);
|
||||
}
|
||||
|
||||
public override void OnServerTransportException(NetworkConnectionToClient conn, Exception exception)
|
||||
{
|
||||
int connId = conn != null ? conn.connectionId : -1;
|
||||
Logger.Log($"Mirror server transport exception (connId={connId}): {exception}");
|
||||
base.OnServerTransportException(conn, exception);
|
||||
}
|
||||
|
||||
public override void OnServerDisconnect(NetworkConnectionToClient conn)
|
||||
{
|
||||
if (conn != null)
|
||||
Logger.Log($"Mirror server: client disconnected (connId={conn.connectionId})");
|
||||
base.OnServerDisconnect(conn);
|
||||
}
|
||||
|
||||
static void ForwardMirrorServerLogToLogger(string logString, string stackTrace, LogType type)
|
||||
{
|
||||
if (!NetworkServer.active)
|
||||
return;
|
||||
if (!ShouldForwardMirrorServerLog(logString, stackTrace, type))
|
||||
return;
|
||||
|
||||
if (string.IsNullOrEmpty(stackTrace))
|
||||
Logger.Log($"[Mirror/{type}] {logString}");
|
||||
else
|
||||
Logger.Log($"[Mirror/{type}] {logString}\n{stackTrace}");
|
||||
}
|
||||
|
||||
static bool ShouldForwardMirrorServerLog(string message, string stackTrace, LogType type)
|
||||
{
|
||||
if (type == LogType.Exception)
|
||||
return ContainsMirrorNetworkContext(message, stackTrace);
|
||||
|
||||
if (type != LogType.Error)
|
||||
return false;
|
||||
|
||||
return message.Contains("Disconnecting connection:")
|
||||
|| message.Contains("NetworkServer:")
|
||||
|| message.Contains("because handling a message")
|
||||
|| message.Contains("because reading a message")
|
||||
|| message.Contains("failed to unpack and invoke")
|
||||
|| message.Contains("was too short (messages should start with message id)");
|
||||
}
|
||||
|
||||
static bool ContainsMirrorNetworkContext(string message, string stackTrace)
|
||||
{
|
||||
return (message != null && (message.Contains("Mirror") || message.Contains("NetworkServer")))
|
||||
|| (stackTrace != null && stackTrace.Contains("Mirror"));
|
||||
}
|
||||
|
||||
public static void MarkIntentionalClientDisconnect()
|
||||
{
|
||||
s_IntentionalClientDisconnect = true;
|
||||
@@ -30,6 +112,8 @@ public class NetManager : NetworkManager
|
||||
|
||||
public override void OnStopServer()
|
||||
{
|
||||
Application.logMessageReceived -= ForwardMirrorServerLogToLogger;
|
||||
|
||||
GameManager.ReportDedicatedMatchRoomClosed();
|
||||
base.OnStopServer();
|
||||
}
|
||||
|
||||
+189
-25
@@ -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");
|
||||
|
||||
|
||||
@@ -116,5 +116,9 @@ public class TutorialManagerMainMenu : MonoBehaviour
|
||||
if(curScreen == 5 && MainMenuManager.instance.gameModesScreen.activeSelf){
|
||||
OnNext5();
|
||||
}
|
||||
|
||||
if(curScreen == 6 && CupidLobby.instance.isMatchmaking){
|
||||
OnTutorialCompleted();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user