public override void OnStartLocalPlayer() { gamesLoaded = false; base.OnStartLocalPlayer(); BuildDebugger.Log("Joined match"); if (isLocalPlayer) { CmdGetConnection(Network.player.ipAddress); } }
public void StartGameplay() { BuildDebugger.Log("gameplay started"); gameplayStarted = true; foreach (var connection in clientConnection.clients) { if (connection.isConnected) { connection.client.SetGameplayState(true, connection.isLoggedIn); } } }
public ClientConnection Get(NetworkConnection clientConnection, Client client) { BuildDebugger.Log("connections available: " + clients.Count); foreach (var connection in clients) { if (connection.address == clientConnection.address && !connection.isConnected) { BuildDebugger.Log("reconnected client connection " + clientConnection.connectionId + " from ip: " + clientConnection.address); connection.networkConnection = clientConnection; connection.isConnected = true; connection.client = client; foreach (Team temp in data.teams.teams) { if (temp.teamName == currentTeam.teamName) { if (temp.chosen == false) { temp.chosen = true; teamJoined.Raise(); } else { currentTeam = new Team(); isLoggedIn = false; } break; } } if (connection.OnReconnected != null) { connection.OnReconnected(connection); } return(connection); } } BuildDebugger.Log("added client connection " + clientConnection.connectionId + " from ip: " + clientConnection.address); ClientConnection newConnection = Instantiate(this); newConnection.networkConnection = clientConnection; newConnection.address = clientConnection.address; newConnection.connectionID = clientConnection.connectionId; newConnection.isConnected = true; newConnection.client = client; newConnection.isLoggedIn = false; clients.Add(newConnection); if (OnClientAdded != null) { OnClientAdded(newConnection); } return(newConnection); }
private void OnJoinInternetMatch(bool success, string extendedInfo, MatchInfo responseData) { if (success) { StartClient(responseData); BuildDebugger.Log("Joining match"); } else { BuildDebugger.Log("Join match failed"); } }
private void RpcSetGameplayState(bool state, bool isLoggedIn) { if (!isLocalPlayer) { return; } BuildDebugger.Log("gameplay state set to " + state); clientState.gameplayStarted = state; if (isLoggedIn && gamesLoaded) { sceneManagement.ReloadScenes(); } }
public override void OnClientDisconnect(NetworkConnection conn) { base.OnClientDisconnect(conn); if (conn.lastError == NetworkError.Timeout && !isConnected) { BuildDebugger.Log("Couldn't connect to server, is server running?"); } else { BuildDebugger.Log("Lost connection to server"); sceneManagement.Reset(); SceneManager.LoadScene(0); } }
public void RpcPassLoginState(bool loggedIn) { if (!isLocalPlayer) { return; } if (!loggedIn) { BuildDebugger.Log("Alright, time to login"); onDisplayLogin.Raise(); } else { BuildDebugger.Log("Don't need to login, already logged"); UpdateLocalTeamInfo(); } }
private void OnInternetMatchCreate(bool success, string extendedInfo, MatchInfo responseData) { if (success) { NetworkServer.Listen(responseData, responseData.port); Debug.Log(responseData.port); var serverStarted = StartServer(responseData); if (!serverStarted) { BuildDebugger.Log("Server creation failed"); } } else { BuildDebugger.Log("Could not create match on Unity Matchmaker"); } }
public void Disconnected() { BuildDebugger.Log("lost client connection " + connectionID + " from ip: " + address); isConnected = false; foreach (Team temp in data.teams.teams) { if (temp.teamName == currentTeam.teamName) { temp.chosen = false; teamJoined.Raise(); } } if (OnDisconnected != null) { OnDisconnected(this); } }
private void OnInternetMatchList(bool success, string extendedInfo, List <MatchInfoSnapshot> matches) { if (success) { if (matches.Count != 0) { matchMaker.JoinMatch(matches[matches.Count - 1].networkId, "", "", "", 0, 0, OnJoinInternetMatch); } else { BuildDebugger.Log("No running matches found"); onConnectionLost.Raise(); } } else { BuildDebugger.Log("Couldn't connect to Unity Matchmaker"); onConnectionLost.Raise(); } }
private static BuildDebugger CreateInstance() { GameObject obj = new GameObject("BuildDebugger"); DontDestroyOnLoad(obj); BuildDebugger buildDebugger = obj.AddComponent <BuildDebugger>(); buildDebugger.logItems = new List <LogItem>(); GameObject canvasObject = new GameObject("Canvas"); canvasObject.transform.SetParent(obj.transform); Canvas canvas = canvasObject.AddComponent <Canvas>(); canvas.renderMode = RenderMode.ScreenSpaceOverlay; canvas.targetDisplay = 0; canvas.sortingOrder = 10000; CanvasScaler scaler = canvasObject.AddComponent <CanvasScaler>(); scaler.uiScaleMode = CanvasScaler.ScaleMode.ScaleWithScreenSize; scaler.referenceResolution = new Vector2(2048, 1536); scaler.screenMatchMode = CanvasScaler.ScreenMatchMode.Shrink; canvasObject.AddComponent <GraphicRaycaster>(); GameObject planeObject = new GameObject("Plane"); planeObject.transform.SetParent(canvasObject.transform); RectTransform planeTransform = planeObject.AddComponent <RectTransform>(); planeTransform.anchoredPosition = Vector2.zero; planeTransform.anchorMin = new Vector2(0.05f, 0.75f); planeTransform.anchorMax = new Vector2(.25f, 0.9f); planeObject.AddComponent <Image>(); planeObject.GetComponent <Image>().color = new Color(1, 1, 1, 0.3f); GameObject logTextObject = new GameObject("LogText"); logTextObject.transform.SetParent(planeObject.transform); RectTransform logTextTransform = logTextObject.AddComponent <RectTransform>(); logTextTransform.anchoredPosition = Vector2.zero; logTextTransform.anchorMin = new Vector2(.2f, .2f); logTextTransform.anchorMax = new Vector2(.8f, .8f); buildDebugger.logText = logTextObject.AddComponent <Text>(); buildDebugger.logText.text = ""; buildDebugger.logText.color = Color.black; buildDebugger.logText.fontSize = 30; //GameObject closeButtonObject = new GameObject("CloseButton"); //closeButtonObject.transform.SetParent(planeObject.transform); //RectTransform closeButtonTransform = closeButtonObject.AddComponent<RectTransform>(); //closeButtonTransform.anchorMin = new Vector2(0.5f, 0); //closeButtonTransform.anchorMax = new Vector2(0.5f, 0); //closeButtonTransform.anchoredPosition = new Vector2(0, 150); //closeButtonTransform.sizeDelta = new Vector2(400, 80); //Image buttonBG = closeButtonObject.AddComponent<Image>(); //buttonBG.color = Color.grey; //Button closeButton = closeButtonObject.AddComponent<Button>(); //closeButton.onClick.AddListener(buildDebugger.DestroyDebugger); //GameObject buttonTextObject = new GameObject("ButtonText"); //buttonTextObject.transform.SetParent(closeButtonObject.transform); //RectTransform buttonTextTransform = buttonTextObject.AddComponent<RectTransform>(); //buttonTextTransform.anchorMin = Vector2.zero; //buttonTextTransform.anchorMax = new Vector2(1, 1); //buttonTextTransform.anchoredPosition = Vector2.zero; ////buttonTextTransform.sizeDelta //Text buttonText = buttonTextObject.AddComponent<Text>(); //buttonText.color = Color.black; //buttonText.text = "close"; //buttonText.fontSize = 40; //buttonText.alignment = TextAnchor.MiddleCenter; buildDebugger.logText.font = Resources.GetBuiltinResource <Font>("Arial.ttf"); //buttonText.font = buildDebugger.logText.font; buildDebugger.logIndex = 0; return(buildDebugger); }
private void TeamCreationSucceeded(bool succes, string errorMessage) { BuildDebugger.Log("TeamCreation: " + (succes ? "succeeded" : "failed") + " | " + errorMessage); RpcTeamCreationSucceeded(succes); }
// called when client is no longer connected to server public void Remove() { BuildDebugger.Log("removed client connection for team: " + currentTeam.teamName); clients.Remove(this); Destroy(this); }
public override void OnStopServer() { BuildDebugger.Log("Server stopped"); }
public override void OnStartServer() { BuildDebugger.Log("Server creation succeeded"); onServerStarted.Raise(); }