Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //MD5Hash:43859399774eb2884d6d4dfce12ce501;
- using UnityEngine;
- using System.Collections.Generic;
- using UnityEngine.Networking;
- using UnityEngine.Networking.Match;
- using System;
- using UnityEngine.Networking.Types;
- public class Network : UnityEngine.MonoBehaviour
- {
- public System.Collections.Generic.List<LobbyList_Data> LobbyList_Data_Output = new System.Collections.Generic.List<LobbyList_Data>();
- public LobbyList_ScrollerController LobbyList_ScrollerController_LobbyList_ScrollerController = null;
- void Start()
- {
- this.gameObject.GetComponent<UnityEngine.Networking.NetworkManager>().StartMatchMaker();
- }
- void Update()
- {
- }
- public void CreateInternetMatch(string matchName)
- {
- UnityEngine.Networking.NetworkManager.singleton.matchMaker.CreateMatch(matchName, 4, true, "", "", "", 0, 0, OnInternetMatchCreate);
- }
- public void OnInternetMatchCreate(bool success, string extendedInfo, UnityEngine.Networking.Match.MatchInfo matchInfo)
- {
- UnityEngine.Networking.Match.MatchInfo hostInfo = null;
- hostInfo = matchInfo;
- if (success)
- {
- UnityEngine.Debug.Log("Create match succeeded");
- UnityEngine.Networking.NetworkServer.Listen(hostInfo, 9000);
- UnityEngine.Networking.NetworkManager.singleton.StartHost(hostInfo);
- }
- else
- {
- UnityEngine.Debug.Log("Create match failed");
- }
- }
- public void FindInternetMatch(string matchName)
- {
- UnityEngine.Networking.NetworkManager.singleton.matchMaker.ListMatches(0, 10, matchName, true, 0, 0, OnInternetMatchList);
- }
- public void ListInternetMatch()
- {
- ///Listet alle matches in eine List<MatchInfoSnapshot>
- UnityEngine.Networking.NetworkManager.singleton.matchMaker.ListMatches(0, 99, "", true, 0, 0, OnListInternetMatchList);
- }
- private void OnInternetMatchList(bool success, string extendedInfo, System.Collections.Generic.List<UnityEngine.Networking.Match.MatchInfoSnapshot> matches)
- {
- if (success)
- {
- if ((matches.Count != 0))
- {
- UnityEngine.Debug.Log("A list of matches was returned");
- UnityEngine.Networking.NetworkManager.singleton.matchMaker.JoinMatch(matches[(matches.Count - 1)].networkId, "", "", "", 0, 0, OnJoinInternetMatch);
- }
- else
- {
- UnityEngine.Debug.Log("Some error ocured while the MatchList was checked...");
- }
- }
- }
- public void OnListInternetMatchList(bool success, string extendedInfo, System.Collections.Generic.List<UnityEngine.Networking.Match.MatchInfoSnapshot> matches)
- {
- if (success)
- {
- if ((matches.Count != 0))
- {
- foreach (var iterator_257 in matches)
- {
- var _TempVar_271_1 = new LobbyList_Data();
- _TempVar_271_1.matchDescription = "Lorem Impsum dolor sit amet blalbalblablabla blablablabablabla blablablabla";
- _TempVar_271_1.matchInfo = iterator_257;
- _TempVar_271_1.matchName = iterator_257.name;
- LobbyList_Data_Output.Add(_TempVar_271_1);
- LobbyList_ScrollerController_LobbyList_ScrollerController.RefreshList_Data(LobbyList_Data_Output);
- }
- }
- else
- {
- UnityEngine.Debug.Log("There is no match you could join. Please host your own");
- }
- }
- }
- public void OnJoinInternetMatch(bool success, string extendedInfo, UnityEngine.Networking.Match.MatchInfo matchInfo)
- {
- if (success)
- {
- UnityEngine.Debug.Log("Able to join a match");
- UnityEngine.Networking.NetworkManager.singleton.StartClient(matchInfo);
- }
- else
- {
- UnityEngine.Debug.Log("Join match failed");
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement