sounds and screens with improved matchmaker
This commit is contained in:
+18
-2
@@ -1,7 +1,8 @@
|
||||
using System.Collections;
|
||||
using Mirror;
|
||||
using UnityEngine;
|
||||
|
||||
public class Ball : MonoBehaviour
|
||||
public class Ball : NetworkBehaviour
|
||||
{
|
||||
[HideInInspector]public Rigidbody2D rb;
|
||||
Vector3 startPosition;
|
||||
@@ -35,8 +36,10 @@ public class Ball : MonoBehaviour
|
||||
public bool touchingB,touchingL,touchingR,touchingT = false;
|
||||
void Update()
|
||||
{
|
||||
WallDetection();
|
||||
CheckNearGoal();
|
||||
|
||||
if(!isServer){return;}
|
||||
WallDetection();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,6 +53,7 @@ public class Ball : MonoBehaviour
|
||||
}
|
||||
}
|
||||
distToGoal = closestDist;
|
||||
|
||||
AudioManager.instance.SetIsBallNearGoal(distToGoal < nearGoalThreshold);
|
||||
}
|
||||
|
||||
@@ -92,13 +96,25 @@ public class Ball : MonoBehaviour
|
||||
|
||||
if(collision.collider.CompareTag("wall")){
|
||||
AudioManager.instance.PlayWallHit(vol);
|
||||
RpcWallHitAudio(vol);
|
||||
}
|
||||
else if(collision.collider.CompareTag("Puck")){
|
||||
AudioManager.instance.PlayBallHit(vol);
|
||||
RpcBallHitAudio(vol);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcWallHitAudio(float vol){
|
||||
AudioManager.instance.PlayWallHit(vol);
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcBallHitAudio(float vol){
|
||||
AudioManager.instance.PlayBallHit(vol);
|
||||
}
|
||||
|
||||
void WallDetection(){
|
||||
// Linecast for each direction
|
||||
Vector3 pos = transform.position;
|
||||
|
||||
@@ -33,7 +33,17 @@ public class CameraEffects : MonoBehaviour
|
||||
isBeingStretched = true;
|
||||
}
|
||||
|
||||
|
||||
public void SetUpsideDown(bool isUpsideDown){
|
||||
if(isUpsideDown){
|
||||
transform.rotation = Quaternion.Euler(0, 0, 180);
|
||||
transform.position = new Vector3(transform.position.x, Mathf.Abs(transform.position.y), transform.position.z);
|
||||
}else{
|
||||
transform.rotation = Quaternion.Euler(0, 0, 0);
|
||||
transform.position = new Vector3(transform.position.x, -Mathf.Abs(transform.position.y), transform.position.z);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void ReleaseStretchFactor(){
|
||||
stretchFactor = 0;
|
||||
|
||||
@@ -23,6 +23,7 @@ public class GameCanvas : MonoBehaviour
|
||||
public Color blueColor = Color.blue;
|
||||
public TMP_Text blueTurnTimer;
|
||||
[FormerlySerializedAs("txtTurnTimer")] public TMP_Text redTurnTimer;
|
||||
public TMP_Text redName,blueName;
|
||||
public TMP_Text txtWhosTurn;
|
||||
public Image blueTurnTimerRound;
|
||||
[FormerlySerializedAs("turnTimerRound")] public Image redTurnTimerRound;
|
||||
@@ -30,6 +31,11 @@ public class GameCanvas : MonoBehaviour
|
||||
public GameObject waitingForOpponentPanel;
|
||||
|
||||
|
||||
void Start(){
|
||||
redName.text = GameManager.RedPlayer.Name;
|
||||
blueName.text = GameManager.BluePlayer.Name;
|
||||
}
|
||||
|
||||
public void ShowWaitingForOpponentPanel(){
|
||||
waitingForOpponentPanel.SetActive(true);
|
||||
}
|
||||
|
||||
@@ -1,14 +1,61 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using UnityEngine;
|
||||
using UnityEngine.EventSystems;
|
||||
using UnityEngine.Networking;
|
||||
using UnityEngine.Serialization;
|
||||
using TMPro;
|
||||
using Mirror;
|
||||
|
||||
public class GameManager : NetworkBehaviour
|
||||
{
|
||||
public static MatchmadePlayer RedPlayer { get; set; }
|
||||
public static MatchmadePlayer BluePlayer { get; set; }
|
||||
/// <summary>Set by dedicated server startup (e.g. CupidConnector parsing <c>-matchId</c>). PATCH is skipped if id ≤ 0 or secret is empty.</summary>
|
||||
public static int DedicatedMatchId { get; private set; }
|
||||
/// <summary>Sent as <c>X-Dedicated-Server-Secret</c>. From <c>-dedicatedSecret</c> arg or <c>DEDICATED_SERVER_SECRET</c> env.</summary>
|
||||
public static string DedicatedMatchSecret { get; private set; } = "";
|
||||
/// <summary>Base URL for internal match API (no trailing slash), default <c>http://127.0.0.1:2612</c>.</summary>
|
||||
public static string DedicatedInternalApiBase { get; private set; } = LoginManager.AuthBaseUrl;
|
||||
|
||||
public static void ConfigureDedicatedMatchReporting(int matchId, string secret=null, string internalApiBaseUrl = null)
|
||||
{
|
||||
DedicatedMatchId = matchId;
|
||||
DedicatedMatchSecret = secret ?? "38516e39d3406225b7c3015a66e5d25c54e9b2024c0755212122bdcea3e3a328";
|
||||
if (!string.IsNullOrWhiteSpace(internalApiBaseUrl))
|
||||
DedicatedInternalApiBase = internalApiBaseUrl.TrimEnd('/');
|
||||
|
||||
Logger.Log($"Configured dedicated match reporting for match id {matchId} with secret {DedicatedMatchSecret} and internal api base {DedicatedInternalApiBase}");
|
||||
}
|
||||
|
||||
/// <summary>Sets match <c>status</c> to <c>-1</c> (room closed). Safe to call from shutdown paths; runs synchronously so it completes before <c>Application.Quit</c>.</summary>
|
||||
public static void ReportDedicatedMatchRoomClosed()
|
||||
{
|
||||
if (_dedicatedRoomClosedReported || DedicatedMatchId <= 0 || string.IsNullOrEmpty(DedicatedMatchSecret))
|
||||
return;
|
||||
_dedicatedRoomClosedReported = true;
|
||||
|
||||
if (DedicatedMatchId <= 0 || string.IsNullOrEmpty(DedicatedMatchSecret))
|
||||
return;
|
||||
|
||||
using (var req = DedicatedMatschInternalApi.BuildRequest(DedicatedInternalApiBase, DedicatedMatchId, DedicatedMatchSecret, "{\"status\":-1}"))
|
||||
{
|
||||
var op = req.SendWebRequest();
|
||||
while (!op.isDone)
|
||||
System.Threading.Thread.Sleep(16);
|
||||
DedicatedMatschInternalApi.LogIfFailed(req);
|
||||
}
|
||||
}
|
||||
|
||||
static bool _dedicatedRoomClosedReported;
|
||||
static string Iso8601UtcNow() => DateTime.UtcNow.ToString("yyyy-MM-dd'T'HH:mm:ss.fff'Z'", System.Globalization.CultureInfo.InvariantCulture);
|
||||
|
||||
bool _dedicatedReportedRedJoin;
|
||||
bool _dedicatedReportedBlueJoin;
|
||||
bool _dedicatedReportedGameOver;
|
||||
|
||||
public static Action<Team> OnTeamChanged;
|
||||
public static bool isMoving{
|
||||
get{
|
||||
@@ -32,7 +79,7 @@ public class GameManager : NetworkBehaviour
|
||||
[SyncVar(hook = nameof(OnSelectedTeamChanged))]
|
||||
public Team SelectedTeam = Team.Red;
|
||||
void OnSelectedTeamChanged(Team oldTeam, Team newTeam){
|
||||
Debug.Log($"Selected team changed from {oldTeam} to {newTeam}");
|
||||
Logger.Log($"Selected team changed from {oldTeam} to {newTeam}");
|
||||
OnTeamChanged?.Invoke(newTeam);
|
||||
|
||||
if (!isClient || !gameStarted || oldTeam == newTeam)
|
||||
@@ -109,6 +156,71 @@ public class GameManager : NetworkBehaviour
|
||||
instance = this;
|
||||
}
|
||||
|
||||
/// <summary>Server-only: called from <see cref="NetPlayer.CmdSetTeam"/> after <c>myTeam</c> is set.</summary>
|
||||
public void OnMatchPlayerTeamAssigned(Team team)
|
||||
{
|
||||
if (!isServer || DedicatedMatchId <= 0 || string.IsNullOrEmpty(DedicatedMatchSecret))
|
||||
return;
|
||||
|
||||
int n = FindObjectsByType<NetPlayer>(FindObjectsSortMode.None).Length;
|
||||
string ts = Iso8601UtcNow();
|
||||
|
||||
if (team == Team.Red && !_dedicatedReportedRedJoin)
|
||||
{
|
||||
_dedicatedReportedRedJoin = true;
|
||||
int status = n >= 2 ? 2 : 1;
|
||||
string json = "{\"red_joined_at\":\"" + ts + "\",\"status\":" + status + "}";
|
||||
StartCoroutine(DedicatedMatchPatch(DedicatedInternalApiBase, DedicatedMatchId, DedicatedMatchSecret, json));
|
||||
// StartCoroutine(DedicatedMatchInternalApi.Patch(DedicatedInternalApiBase, DedicatedMatchId, DedicatedMatchSecret, json));
|
||||
}
|
||||
else if (team == Team.Blue && !_dedicatedReportedBlueJoin)
|
||||
{
|
||||
_dedicatedReportedBlueJoin = true;
|
||||
int status = n >= 2 ? 2 : 1;
|
||||
string json = "{\"blue_joined_at\":\"" + ts + "\",\"status\":" + status + "}";
|
||||
StartCoroutine(DedicatedMatchPatch(DedicatedInternalApiBase, DedicatedMatchId, DedicatedMatchSecret, json));
|
||||
}
|
||||
}
|
||||
|
||||
IEnumerator DedicatedMatchPatch(string baseUrl, int matchId, string secret, string json){
|
||||
if (matchId <= 0 || string.IsNullOrEmpty(secret))
|
||||
yield break;
|
||||
|
||||
using (var req = DedicatedMatschInternalApi.BuildRequest(baseUrl, matchId, secret, json))
|
||||
{
|
||||
yield return req.SendWebRequest();
|
||||
DedicatedMatschInternalApi.LogIfFailed(req);
|
||||
}
|
||||
}
|
||||
|
||||
public IEnumerator DedicatedMatchPatchWinner(string baseUrl, int matchId, string secret, string winnerLower)
|
||||
{
|
||||
if (matchId <= 0 || string.IsNullOrEmpty(secret))
|
||||
yield break;
|
||||
|
||||
string jsonBody = "{\"winner\":\"" + winnerLower + "\"}";
|
||||
using (var req = DedicatedMatschInternalApi.BuildWinnerRequest(baseUrl, matchId, secret, jsonBody))
|
||||
{
|
||||
yield return req.SendWebRequest();
|
||||
DedicatedMatschInternalApi.LogIfFailed(req);
|
||||
}
|
||||
}
|
||||
|
||||
void ReportDedicatedMatchGameOver(Team winningTeam)
|
||||
{
|
||||
if (!isServer || DedicatedMatchId <= 0 || string.IsNullOrEmpty(DedicatedMatchSecret) || _dedicatedReportedGameOver)
|
||||
return;
|
||||
_dedicatedReportedGameOver = true;
|
||||
StartCoroutine(CoReportDedicatedMatchGameOver(winningTeam));
|
||||
}
|
||||
|
||||
IEnumerator CoReportDedicatedMatchGameOver(Team winningTeam)
|
||||
{
|
||||
yield return DedicatedMatchPatch(DedicatedInternalApiBase, DedicatedMatchId, DedicatedMatchSecret, "{\"status\":3}");
|
||||
string winner = winningTeam == Team.Red ? "red" : "blue";
|
||||
yield return DedicatedMatchPatchWinner(DedicatedInternalApiBase, DedicatedMatchId, DedicatedMatchSecret, winner);
|
||||
}
|
||||
|
||||
void Start()
|
||||
{
|
||||
GameEvents.OnSelectedPuckChanged?.Invoke(null);
|
||||
@@ -135,7 +247,7 @@ public class GameManager : NetworkBehaviour
|
||||
[SerializeField]Puck selectedPuck;
|
||||
|
||||
void OnSelectedPuckChanged(Puck oldPuck, Puck newPuck){
|
||||
// Debug.Log($"Selected puck changed from {oldPuck} to {newPuck}");
|
||||
// Logger.Log($"Selected puck changed from {oldPuck} to {newPuck}");
|
||||
GameEvents.OnSelectedPuckChanged?.Invoke(newPuck);
|
||||
}
|
||||
public static Puck SelectedPuck{
|
||||
@@ -192,8 +304,8 @@ public class GameManager : NetworkBehaviour
|
||||
coroutinePostLaunch = StartCoroutine(CoroutinePostLaunch());
|
||||
curPuckPullForce = direction.magnitude;
|
||||
float force = puckForce * puckForceCurve.Evaluate(curPuckPullForce);
|
||||
Debug.Log($"force = {puckForce} * {puckForceCurve.Evaluate(curPuckPullForce)} = {force}");
|
||||
Debug.Log($"launching puck at {direction} with {force * -direction} force");
|
||||
Logger.Log($"force = {puckForce} * {puckForceCurve.Evaluate(curPuckPullForce)} = {force}");
|
||||
Logger.Log($"launching puck at {direction} with {force * -direction} force");
|
||||
selectedPuck.GetComponent<Rigidbody2D>().AddForce(-direction * force, ForceMode2D.Impulse);
|
||||
hitCounter++;
|
||||
|
||||
@@ -270,14 +382,14 @@ public class GameManager : NetworkBehaviour
|
||||
if(Input.GetKeyDown(KeyCode.Space)){
|
||||
gameStarted = true;
|
||||
GameCanvas.instance.HideWaitingForOpponentPanel();
|
||||
Debug.Log("Game started On Server, EDITOR ONLY, DEBUG ONLY");
|
||||
Logger.Log("Game started On Server, EDITOR ONLY, DEBUG ONLY");
|
||||
}
|
||||
#endif
|
||||
if (players.Length == 2)
|
||||
{
|
||||
gameStarted = true;
|
||||
GameCanvas.instance.HideWaitingForOpponentPanel();
|
||||
Debug.Log("Game started On Server");
|
||||
Logger.Log("Game started On Server");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -405,7 +517,7 @@ public class GameManager : NetworkBehaviour
|
||||
|
||||
if(hitCounter == 1){
|
||||
//kickoff goal
|
||||
Debug.Log("Kickoff goal");
|
||||
Logger.Log("Kickoff goal");
|
||||
StartCoroutine(CoroutineOnGoal(team,true));//true = Kickoff goal, reset only the ball
|
||||
hitCounter = 0;
|
||||
|
||||
@@ -423,9 +535,11 @@ public class GameManager : NetworkBehaviour
|
||||
|
||||
|
||||
if(blueScore >= 3){
|
||||
ReportDedicatedMatchGameOver(Team.Blue);
|
||||
RpcGameOver(Team.Blue);
|
||||
gameOver(Team.Blue);
|
||||
}else if(redScore >= 3){
|
||||
ReportDedicatedMatchGameOver(Team.Red);
|
||||
RpcGameOver(Team.Red);
|
||||
gameOver(Team.Red);
|
||||
}else{
|
||||
@@ -478,7 +592,7 @@ public class GameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
void OnScoreChanged(int oldScore, int newScore){
|
||||
Debug.Log($"Score changed from {oldScore} to {newScore}");
|
||||
Logger.Log($"Score changed from {oldScore} to {newScore}");
|
||||
redScoreText.text = redScore.ToString();
|
||||
blueScoreText.text = blueScore.ToString();
|
||||
}
|
||||
@@ -505,3 +619,43 @@ public class GameManager : NetworkBehaviour
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// <summary>Headless dedicated server → matchmaker internal PATCH. Runs only where started (server-side coroutines).</summary>
|
||||
static class DedicatedMatschInternalApi
|
||||
{
|
||||
|
||||
public static UnityWebRequest BuildRequest(string baseUrl, int matchId, string secret, string jsonBody)
|
||||
{
|
||||
string url = baseUrl.TrimEnd('/') + "/internal/match/" + matchId;
|
||||
return BuildPatchJson(url, secret, jsonBody);
|
||||
}
|
||||
|
||||
public static UnityWebRequest BuildWinnerRequest(string baseUrl, int matchId, string secret, string jsonBody)
|
||||
{
|
||||
string url = baseUrl.TrimEnd('/') + "/internal/match/" + matchId + "/winner";
|
||||
return BuildPatchJson(url, secret, jsonBody);
|
||||
}
|
||||
|
||||
static UnityWebRequest BuildPatchJson(string url, string secret, string jsonBody)
|
||||
{
|
||||
byte[] bodyRaw = Encoding.UTF8.GetBytes(jsonBody);
|
||||
var req = new UnityWebRequest(url, "PATCH")
|
||||
{
|
||||
uploadHandler = new UploadHandlerRaw(bodyRaw),
|
||||
downloadHandler = new DownloadHandlerBuffer()
|
||||
};
|
||||
req.SetRequestHeader("Content-Type", "application/json");
|
||||
req.SetRequestHeader("X-Dedicated-Server-Secret", secret);
|
||||
return req;
|
||||
}
|
||||
|
||||
public static void LogIfFailed(UnityWebRequest req)
|
||||
{
|
||||
if (req.result == UnityWebRequest.Result.Success){
|
||||
Logger.Log("Dedicated match PATCH success: " + req.responseCode + " " + (req.downloadHandler != null ? req.downloadHandler.text : ""));
|
||||
}else{
|
||||
Logger.Log("Dedicated match PATCH failed: " + req.responseCode + " " + req.error + " " + (req.downloadHandler != null ? req.downloadHandler.text : ""));
|
||||
Logger.Log("More details : " + req.url + " " + req.method + " " + req.uploadHandler.data + " " + req.downloadHandler.text);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,10 @@
|
||||
using System;
|
||||
using System.Collections;
|
||||
using System.IO;
|
||||
using System.Text;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using TMPro;
|
||||
using UnityEngine;
|
||||
using UnityEngine.Networking;
|
||||
@@ -9,7 +13,7 @@ using UnityEngine.UI;
|
||||
|
||||
public class LoginManager : MonoBehaviour
|
||||
{
|
||||
const string AuthBaseUrl = "http://vps.playpoolstudios.com:2612";
|
||||
public const string AuthBaseUrl = "http://vps.playpoolstudios.com:2612";
|
||||
const string PlayerPrefsAuthKey = "WalkInvest.AuthToken";
|
||||
|
||||
const int MIN_USERNAME_LENGTH = 3;
|
||||
@@ -33,6 +37,33 @@ public class LoginManager : MonoBehaviour
|
||||
|
||||
public static string AuthToken { get; private set; }
|
||||
|
||||
/// <summary>Assigned side from the matchmaker <c>your_team</c> field. <c>null</c> until a room is found or after clear.</summary>
|
||||
public static Team? MatchYourTeam { get; private set; }
|
||||
|
||||
/// <summary>Parses matchmaker strings such as <c>"red"</c> / <c>"blue"</c> (case-insensitive).</summary>
|
||||
public static void SetMatchYourTeam(string matchmakerYourTeam)
|
||||
{
|
||||
MatchYourTeam = ParseMatchmakerTeam(matchmakerYourTeam);
|
||||
}
|
||||
|
||||
static Team? ParseMatchmakerTeam(string s)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(s))
|
||||
return null;
|
||||
switch (s.Trim().ToLowerInvariant())
|
||||
{
|
||||
case "red": return Team.Red;
|
||||
case "blue": return Team.Blue;
|
||||
default:
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public static void ClearMatchYourTeam()
|
||||
{
|
||||
MatchYourTeam = null;
|
||||
}
|
||||
|
||||
/// <summary>Latest user payload from the server. Reading this schedules a refresh (one in flight at a time).</summary>
|
||||
public static UserData CurrentUser
|
||||
{
|
||||
@@ -49,29 +80,6 @@ public class LoginManager : MonoBehaviour
|
||||
static UserData _currentUser;
|
||||
bool _userDataReadRefreshPending;
|
||||
|
||||
[Serializable]
|
||||
class AuthApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
public string token;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class AuthUserApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
public UserData user;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
class PurchaseRcApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
}
|
||||
|
||||
public static LoginManager instance;
|
||||
|
||||
void Awake()
|
||||
@@ -92,13 +100,47 @@ public class LoginManager : MonoBehaviour
|
||||
btnLogin.onClick.AddListener(OnLogin);
|
||||
btnRegister.onClick.AddListener(OnRegister);
|
||||
|
||||
#if UNITY_EDITOR
|
||||
// Dev: log in with clone-aware credentials instead of resuming a saved session.
|
||||
AuthToken = "";
|
||||
PlayerPrefs.DeleteKey(PlayerPrefsAuthKey);
|
||||
PlayerPrefs.Save();
|
||||
|
||||
bool cloneWorkspace = EditorWorkspaceLooksLikeClone();
|
||||
string devUser = cloneWorkspace ? "warlock2" : "warlock";
|
||||
const string devPass = "12345678";
|
||||
if (usernameInputLogin != null) usernameInputLogin.text = devUser;
|
||||
if (passwordInputLogin != null) passwordInputLogin.text = devPass;
|
||||
|
||||
string loginJson = "{\"username\":\"" + EscapeJsonString(devUser) + "\",\"password\":\"" + EscapeJsonString(devPass) + "\"}";
|
||||
StartCoroutine(AuthPostCoroutine(AuthBaseUrl + "/auth/login", loginJson, "Signed in."));
|
||||
#else
|
||||
if (!string.IsNullOrEmpty(AuthToken))
|
||||
{
|
||||
SetBusy(true);
|
||||
StartCoroutine(ResumeSessionCoroutine());
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#if UNITY_EDITOR
|
||||
static bool EditorWorkspaceLooksLikeClone()
|
||||
{
|
||||
// Project folder is parent of Assets (same as editor project path).
|
||||
string projectRoot = Path.GetDirectoryName(Application.dataPath);
|
||||
if (!string.IsNullOrEmpty(projectRoot) &&
|
||||
projectRoot.IndexOf("clone", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
string product = PlayerSettings.productName;
|
||||
if (!string.IsNullOrEmpty(product) &&
|
||||
product.IndexOf("clone", StringComparison.OrdinalIgnoreCase) >= 0)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
IEnumerator ResumeSessionCoroutine()
|
||||
{
|
||||
yield return StartCoroutine(FetchUserDataCoroutine(null, true));
|
||||
@@ -433,39 +475,3 @@ public class LoginManager : MonoBehaviour
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class UserData
|
||||
{
|
||||
public int id;
|
||||
public string username;
|
||||
public int cc;
|
||||
public int rc;
|
||||
public string created_at;
|
||||
public string last_logged_at;
|
||||
}
|
||||
|
||||
/// <summary>Typical <c>pack</c> ids for <see cref="LoginManager.PurchaseRcPack"/>; prefer <see cref="LoginManager.GetRcPacks"/> for the live list.</summary>
|
||||
public static class RcPack
|
||||
{
|
||||
public const string Usd5 = "usd_5";
|
||||
public const string Usd20 = "usd_20";
|
||||
public const string Usd50 = "usd_50";
|
||||
|
||||
public static bool IsValid(string packId)
|
||||
{
|
||||
return packId == Usd5 || packId == Usd20 || packId == Usd50;
|
||||
}
|
||||
}
|
||||
|
||||
public static class CoinHelper{
|
||||
public static float Format(int coins){
|
||||
int whole = coins / 4;
|
||||
int fraction = coins % 4;
|
||||
return float.Parse(whole + "." + fraction);
|
||||
}
|
||||
|
||||
public static string FormatString(int coins){
|
||||
return Format(coins).ToString("N2");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,6 +1,11 @@
|
||||
using UnityEngine;
|
||||
using Mirror;
|
||||
|
||||
public class NetManager : NetworkManager
|
||||
{
|
||||
|
||||
public override void OnStopServer()
|
||||
{
|
||||
GameManager.ReportDedicatedMatchRoomClosed();
|
||||
base.OnStopServer();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -22,11 +22,19 @@ public class NetPlayer : NetworkBehaviour
|
||||
myTeam = Team.Blue;
|
||||
CmdSetTeam(Team.Blue);
|
||||
}
|
||||
|
||||
if(myTeam == Team.Blue){
|
||||
CameraEffects.instance.SetUpsideDown(true);
|
||||
}else{
|
||||
CameraEffects.instance.SetUpsideDown(false);
|
||||
}
|
||||
}
|
||||
|
||||
[Command]
|
||||
void CmdSetTeam(Team team){
|
||||
myTeam = team;
|
||||
if (GameManager.instance != null)
|
||||
GameManager.instance.OnMatchPlayerTeamAssigned(team);
|
||||
}
|
||||
|
||||
|
||||
|
||||
+10
-1
@@ -130,8 +130,17 @@ public class Puck : NetworkBehaviour
|
||||
Debug.Log("Puck collision speed: " + otherSpeed);
|
||||
float maxVolSpeed =5f;
|
||||
float vol = Mathf.Clamp(otherSpeed / maxVolSpeed,0.1f,1);
|
||||
if (AudioManager.instance != null)
|
||||
if (AudioManager.instance != null){
|
||||
AudioManager.instance.PlayPuckHit(vol);
|
||||
if(isServer){
|
||||
RpcPuckHitAudio(vol);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
[ClientRpc]
|
||||
void RpcPuckHitAudio(float vol){
|
||||
AudioManager.instance.PlayPuckHit(vol);
|
||||
}
|
||||
|
||||
public void Reset(Vector3? position = null, float duration = 0.5f)
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
public static class CoinHelper
|
||||
{
|
||||
public static float Format(int coins)
|
||||
{
|
||||
int whole = coins / 4;
|
||||
int fraction = coins % 4;
|
||||
return float.Parse(whole + "." + fraction);
|
||||
}
|
||||
|
||||
public static string FormatString(int coins)
|
||||
{
|
||||
return Format(coins).ToString("N2");
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5bf3c59f7c1a7e640a05edc5f9828abd
|
||||
@@ -3,6 +3,7 @@ using UnityEngine.UI;
|
||||
using DG.Tweening;
|
||||
using UnityEngine.SceneManagement;
|
||||
using System.Collections;
|
||||
using TMPro;
|
||||
public class LevelLoadManager : MonoBehaviour
|
||||
{
|
||||
public static LevelLoadManager instance;
|
||||
@@ -13,6 +14,14 @@ public class LevelLoadManager : MonoBehaviour
|
||||
|
||||
public bool isShowing => canvasGroup.alpha == 1;
|
||||
|
||||
[Header("Matchmade UI")]
|
||||
public GameObject matchmadeUI;
|
||||
public GameObject p1_red,p2_red,p1_blue,p2_blue;
|
||||
public Image p1_icon, p2_icon;
|
||||
public TMP_Text p1_name, p2_name;
|
||||
public TMP_Text p1_l10, p2_l10;
|
||||
public Sprite redIcon, blueIcon;
|
||||
|
||||
void Awake()
|
||||
{
|
||||
if(instance != null){
|
||||
@@ -24,6 +33,8 @@ public class LevelLoadManager : MonoBehaviour
|
||||
|
||||
DontDestroyOnLoad(gameObject);
|
||||
Hide();
|
||||
|
||||
matchmadeUI.SetActive(false);
|
||||
}
|
||||
|
||||
|
||||
@@ -38,7 +49,11 @@ public class LevelLoadManager : MonoBehaviour
|
||||
IEnumerator CoroutineLoadLevel(string levelName){
|
||||
instance.Show();
|
||||
yield return new WaitForSeconds(transitionDuration);
|
||||
if(matchmadeUI.activeSelf){
|
||||
yield return new WaitForSeconds(3f);
|
||||
}
|
||||
yield return SceneManager.LoadSceneAsync(levelName);
|
||||
|
||||
instance.Hide();
|
||||
}
|
||||
|
||||
@@ -58,4 +73,32 @@ public class LevelLoadManager : MonoBehaviour
|
||||
canvasGroup.DOFade(0, transitionDuration).SetEase(Ease.InSine);
|
||||
contentImage.DOFillAmount(0, transitionDuration).SetEase(Ease.InSine);
|
||||
}
|
||||
|
||||
|
||||
public void SetupMatchMade(Team myTeam, string opponentName, string myName, string myL10, string opponentL10){
|
||||
matchmadeUI.SetActive(true);
|
||||
|
||||
if(myTeam == Team.Red){
|
||||
p1_red.SetActive(true);
|
||||
p1_blue.SetActive(false);
|
||||
p2_red.SetActive(false);
|
||||
p2_blue.SetActive(true);
|
||||
|
||||
p1_icon.sprite = redIcon;
|
||||
p2_icon.sprite = blueIcon;
|
||||
}else{
|
||||
p1_red.SetActive(false);
|
||||
p1_blue.SetActive(true);
|
||||
p2_red.SetActive(true);
|
||||
p2_blue.SetActive(false);
|
||||
|
||||
p1_icon.sprite = blueIcon;
|
||||
p2_icon.sprite = redIcon;
|
||||
}
|
||||
|
||||
p1_name.text = myName;
|
||||
p2_name.text = opponentName;
|
||||
p1_l10.text = myL10;
|
||||
p2_l10.text = opponentL10;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: fd2602c01ff00f047aab3e93a95bb230
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,12 @@
|
||||
/// <summary>Typical <c>pack</c> ids for <see cref="LoginManager.PurchaseRcPack"/>; prefer <see cref="LoginManager.GetRcPacks"/> for the live list.</summary>
|
||||
public static class RcPack
|
||||
{
|
||||
public const string Usd5 = "usd_5";
|
||||
public const string Usd20 = "usd_20";
|
||||
public const string Usd50 = "usd_50";
|
||||
|
||||
public static bool IsValid(string packId)
|
||||
{
|
||||
return packId == Usd5 || packId == Usd20 || packId == Usd50;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 241f412d7db597748af9c1138e640e0e
|
||||
@@ -0,0 +1,13 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class UserData
|
||||
{
|
||||
public int id;
|
||||
public string username;
|
||||
public int cc;
|
||||
public int rc;
|
||||
public string created_at;
|
||||
public string last_logged_at;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 7fa72c32d6a0d1e4abc0b724b1988d8c
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 031adef9a13d67c48b0969916c4e2160
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class AuthApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
public string token;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 91e26300ebc95df47949bbd3744bf975
|
||||
@@ -0,0 +1,10 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class AuthUserApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
public UserData user;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d82de2425d5fb6448bc038942fb1aa88
|
||||
@@ -0,0 +1,23 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class MatchmadePlayer
|
||||
{
|
||||
public string Name;
|
||||
public long LastSeen;
|
||||
public int l10_wins;
|
||||
public int l10_losses;
|
||||
public int UserId;
|
||||
}
|
||||
|
||||
[Serializable]
|
||||
public class MatchmadeResponse
|
||||
{
|
||||
public MatchmadePlayer[] Players;
|
||||
public string GameName;
|
||||
public int Port;
|
||||
public long InitTime;
|
||||
public int match_id;
|
||||
public string your_team;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f3314f8ed9de9c4babeefda34b3026c
|
||||
@@ -0,0 +1,9 @@
|
||||
using System;
|
||||
using UnityEngine;
|
||||
|
||||
[Serializable]
|
||||
public class PurchaseRcApiResponse
|
||||
{
|
||||
public bool ok;
|
||||
public string error;
|
||||
}
|
||||
@@ -0,0 +1,2 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 4aef938f509352a43920aa7bc5eb593d
|
||||
Reference in New Issue
Block a user