//This is hooked to the Host Server button public void StartHost() { if (!NetworkServer.active) { MultiplayerManager.GetInstance().StartHost(); } }
public void DoChangeTeam(short team) { if (isLocalPlayer) { if (MultiplayerManager.GetInstance().localPlayerTeam != team) { GameObject.Find("SwitchTeam").GetComponent <AudioSource>().Play(); //only play if actually changing teams } MultiplayerManager.GetInstance().localPlayerTeam = team; if (team == 0) { lobby.redTeam.parent.GetComponent <Button>().interactable = false; lobby.blueTeam.parent.GetComponent <Button>().interactable = true; lobby.blueTeam.parent.GetComponent <Button>().OnPointerExit(null); } else { lobby.blueTeam.parent.GetComponent <Button>().interactable = false; lobby.redTeam.parent.GetComponent <Button>().interactable = true; lobby.redTeam.parent.GetComponent <Button>().OnPointerExit(null); } } if (team == 0) { transform.SetParent(lobby.redTeam, false); } else { transform.SetParent(lobby.blueTeam, false); } }
public void RpcLockTeams() { LockTeams(); List <Player> list = MultiplayerManager.GetInstance().playerList; Player localPlayer = MultiplayerManager.FindPlayer(GetLocalPlayer().GetComponent <NetworkIdentity>().netId); string info = "You are on the " + (localPlayer.team == 0 ? "Red" : "Blue") + " team "; List <Player> teammates = list.FindAll(p => p.team == localPlayer.team && !p.Equals(localPlayer)); if (teammates.Count > 0) { info += "(Teammates: "; for (int i = 0; i < teammates.Count - 1; i++) { info += teammates[i].name + ", "; } info += teammates[teammates.Count - 1].name + ")"; } infoText.text = info; //Disable other team's player names foreach (Player p in list) { if (p.team != localPlayer.team) { ClientScene.FindLocalObject(p.objectId).SetActive(false); } } humanToggle.isOn = true; }
//This is hooked to the Join Server button public void StartClient() { if (!NetworkClient.active) { MultiplayerManager.GetInstance().StartClient(); } }
public void OnCancelClick() { MultiplayerManager.GetInstance().StopMatchMaker(); startBtn.SetActive(true); cancelBtn.SetActive(false); dialogue.SetActive(false); }
//function to run when exit to main menu button clicked void ExitToMainMenButtonClickProcess() { //set current state to quit game pauseMenuCurrentState = QUIT_GAME; //disconnect from network MultiplayerManager.GetInstance().StopHost(); }
public void CmdChangeTeam(short team) { if (lobby.currentState != LobbyManager.LobbyState.TeamSelect || MultiplayerManager.GetInstance().playerList.FindAll(p => p.team == team).Count >= 4) { return; //team to switch to already has 4 players, abort } MultiplayerManager.FindPlayer(GetComponent <NetworkIdentity>().netId).team = team; playerTeam = team; RpcChangeTeam(team); }
public void CmdLockIn() { MultiplayerManager.FindPlayer(GetComponent <NetworkIdentity>().netId).ready = true; List <Player> playerList = MultiplayerManager.GetInstance().playerList; textColor = new Color(0.4f, 0.8f, 0.4f); if (playerList.FindAll(p => p.ready).Count == playerList.Count) { lobby.LockShips(); lobby.RpcLockShips(); } }
public void DoChangeShip(Ship ship) { if (isLocalPlayer) { MultiplayerManager.GetInstance().localShipType = ship; } if (lobby.currentState != LobbyManager.LobbyState.ShipSelect) { return; } transform.SetParent(lobby.ShipSelectNameContainers[(short)ship].transform, false); }
// Use this for initialization void Start() { if (MultiplayerManager.GetInstance().startFinding) { startBtn.SetActive(false); cancelBtn.SetActive(true); dialogue.SetActive(true); MultiplayerManager.GetInstance().StopMatchMaker(); Invoke("OnStartClick", 4f); MultiplayerManager.GetInstance().startFinding = false; } if (ParseUser.CurrentUser == null) { registerObj.SetActive(true); } // ParseUser.LogOutAsync(); }
/// <summary> /// This method should be used for all changes to a ship's health. /// It should only be called on the server. /// Use NetworkInstanceId.Invalid if there is no damage source. /// </summary> /// <param name="amount">Amount to change health by</param> /// <param name="source">ID of the damage/heal source. Can be NetworkInstanceId.Invalid</param> public void ChangeHealth(float amount, NetworkInstanceId source) { if ((health == 0 || currentInvincibleTimer > 0) && amount < 0) { return; //don't register damage taken after death or while invincible } //Todo: add back in this functionality in the Stat System using an event hook for PlayerDamaged if (amount < 0) //only for damage { amount *= defenseStat; // Multiplier effect for defense stat } Player.ActivateEventPlayerDamaged(MultiplayerManager.FindPlayer(GetComponent <NetworkIdentity>().netId), MultiplayerManager.FindPlayer(source), ref amount); //By setting this variable in a serverside context, the OnChangeHealth hook is called on all clients health = Mathf.Clamp(health + amount, 0, 100); if (health == 0) //Tell the server about this kill { MultiplayerManager.GetInstance().PlayerKill(MultiplayerManager.FindPlayer(GetComponent <NetworkIdentity>().netId), source); } }
//call when server created public void Init() { //starting from menu scene DontDestroyOnLoad(gameObject); clients = new List <ServerClient> (); disconnectList = new List <ServerClient> (); try { server = new TcpListener(IPAddress.Any, port); server.Start(); serverStarted = true; Debug.Log("Server started"); //listen for incoming connection StartListening(); } catch (System.Exception e) { Debug.Log("Socket error: " + e.Message); MultiplayerManager.GetInstance().OnHostFailed(); } }
//entry point public bool ConnectToServer(string hostAddress, int port, bool hostOnFail) { if (socketReady) { return(false); } try { socket = new TcpClient(hostAddress, port); stream = socket.GetStream(); writer = new StreamWriter(stream); reader = new StreamReader(stream); socketReady = true; DontDestroyOnLoad(gameObject); } catch (Exception e) { Debug.Log("Socket error: " + e.Message); MultiplayerManager.GetInstance().OnJoinFailed(hostOnFail); } return(socketReady); }
//DW // void Start() { MultiplayerManager mm = MultiplayerManager.GetInstance(); Cursor.lockState = CursorLockMode.None; Cursor.visible = true; if (SaveLoad.Load()) { mm.localPlayerName = Game.current.name; mm.networkAddress = Game.current.IPaddress; } if (mm != null) { HostNameField.text = mm.localPlayerName; JoinNameField.text = mm.localPlayerName; IPField.text = mm.networkAddress; } //just in case input is locked InputWrapper.ReleaseKeyboard(); InputWrapper.ReleaseMouse(); }
// Use this for initialization void Start() { instance = this; //Variable initialization manager = MultiplayerManager.GetInstance(); //This if statement statement checks if it's running on the host if (!MultiplayerManager.IsHost()) { startButton.SetActive(false); gameOptions.SetActive(false); } else { CmdSetHostName(MultiplayerManager.GetLocalPlayer().name); CmdSetHostIP(MultiplayerManager.GetLocalIPAddress(), "Fetching..."); StartCoroutine(GetAssignPublicIPAddress()); } OnHostNameChange(hostName); OnHostPubIPChange(hostPublicIP); OnHostLANIPChange(hostLANIP); }
public void QuitToMenu() { MultiplayerManager.GetInstance().StopHost(); }
public void CmdEnterGame() { MultiplayerManager.GetInstance().EnterGame(); }
private void Start() { manager = MultiplayerManager.GetInstance(); //manager.client.RegisterHandler(MultiplayerManager.ExtMsgType.State, UpdateScoreboard); }
//Called when the port field is changed public void SetPort(string port) { MultiplayerManager.GetInstance().networkPort = int.Parse(port); }
//Called when the name field is changed public void SetName(string name) { MultiplayerManager.GetInstance().localPlayerName = (name.Equals("") ? "???" : name); Game.current.name = name; SaveLoad.SaveGame(); }
//This is called when changes to the Server IP field are submitted public void SetIP(string ip) { MultiplayerManager.GetInstance().networkAddress = ip; Game.current.IPaddress = ip; SaveLoad.SaveGame(); }
public void Connect() { MultiplayerManager.GetInstance().Connect(); }
//tells server about a player variable changing private void NotifyServerStateChanged() { MultiplayerManager.GetInstance().SendGameState(); }