Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using UnityEngine.UI;
- using UnityEngine.Networking;
- using UnityEngine.Networking.Types;
- using UnityEngine.Networking.Match;
- using System.Collections;
- using System.Collections.Generic;
- public class ENetManager : NetworkLobbyManager {
- static public ENetManager Current;
- public GameObject MainCam;
- public Vector3 SpawnLocation;
- [HideInInspector]
- public List<GameObject> Players = new List<GameObject>();
- [HideInInspector]
- public GameObject OurLocalPlayer;
- void Start() {
- Current = this;
- }
- public override void OnLobbyClientSceneChanged(NetworkConnection conn) {
- //Only do it for the local player (?)
- if (!conn.playerControllers[0].unetView.isLocalPlayer) {
- return;
- }
- //If we're still in the lobby....
- if (Application.loadedLevelName == lobbyScene) {
- Debug.Log("In Lobby!");
- } else {
- //We're not in the lobby
- Debug.Log("In-Game!");
- }
- }
- public override void OnServerAddPlayer(NetworkConnection conn, short playerControllerId) {
- Debug.Log("Add player!");
- /*
- //Instantiate the player
- GameObject Player = (GameObject)Instantiate(playerPrefab, SpawnLocation, Quaternion.identity);
- //Instantiate Camera
- GameObject Cam = (GameObject)Instantiate(MainCam, transform.position, Quaternion.identity);
- //Set references
- Player.GetComponent<PBattle>()._Cam = Cam.GetComponent<UnityStandardAssets.Cameras.FollowCam>();
- Cam.GetComponent<UnityStandardAssets.Cameras.FollowCam>().SetTarget(Player.transform);
- //Spawn the player
- NetworkServer.AddPlayerForConnection(conn, Player, playerControllerId);
- */
- GameObject playerGO = (GameObject)Instantiate(gamePlayerPrefab, SpawnLocation, Quaternion.identity);
- OurLocalPlayer = playerGO;
- GameObject cameraGO = (GameObject)Instantiate(MainCam, playerGO.transform.position + new Vector3(0, 0, -5), Quaternion.identity);
- NetworkServer.AddPlayerForConnection(conn, playerGO, playerControllerId);
- }
- public override void OnMatchCreate(UnityEngine.Networking.Match.CreateMatchResponse matchInfo) {
- base.OnMatchCreate(matchInfo);
- }
- //SERVER MANAGEMENT//
- public void StopHosting() {
- }
- //OTHER//
- public override void OnStartHost() {
- Debug.Log("Started host!");
- base.OnStartHost();
- MainMenu.Current.LobbyB();
- //ChangeTo(lobbyPanel);
- //backDelegate = StopHostClbk;
- //SetServerInfo("Hosting", networkAddress);
- }
- //When a client connects to the server...
- public override void OnClientConnect(NetworkConnection conn) {
- Debug.Log("Client connected!");
- base.OnClientConnect(conn);
- if (!NetworkServer.active) {//only to do on pure client (not self hosting client)
- MainMenu.Current.LobbyB();
- }
- }
- public void OnMatchDestroyed(BasicResponse resp) {
- //StopMatchMaker();
- StopHost();
- }
- //SERVER CALLBACKS//
- /*
- public override GameObject OnLobbyServerCreateLobbyPlayer(NetworkConnection conn, short playerControllerId) {
- Debug.Log("HAI");
- GameObject LPlayer = Instantiate(lobbyPlayerPrefab.gameObject) as GameObject;
- return LPlayer;
- }*/
- public override void OnLobbyServerDisconnect(NetworkConnection conn) {
- }
- public override bool OnLobbyServerSceneLoadedForPlayer(GameObject lobbyPlayer, GameObject gamePlayer) {
- return true;
- }
- //CLIENT CALLBACKS//
- public override void OnClientDisconnect(NetworkConnection conn) {
- //Disconnect & go to the main menu...
- base.OnClientDisconnect(conn);
- MainMenu.Current.QuitMatchMaking();
- }
- public override void OnClientError(NetworkConnection conn, int errorCode) {
- //Just go back to the main menu...
- MainMenu.Current.QuitMatchMaking();
- Debug.Log("Cient error : " + (errorCode == 6 ? "timeout" : errorCode.ToString()));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement