Advertisement
diegographics

Untitled

Apr 25th, 2017
538
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 3.42 KB | None | 0 0
  1. //MD5Hash:43859399774eb2884d6d4dfce12ce501;
  2. using UnityEngine;
  3. using System.Collections.Generic;
  4. using UnityEngine.Networking;
  5. using UnityEngine.Networking.Match;
  6. using System;
  7. using UnityEngine.Networking.Types;
  8.  
  9.  
  10. public class Network : UnityEngine.MonoBehaviour
  11. {
  12.     public System.Collections.Generic.List<LobbyList_Data> LobbyList_Data_Output = new System.Collections.Generic.List<LobbyList_Data>();
  13.     public LobbyList_ScrollerController LobbyList_ScrollerController_LobbyList_ScrollerController = null;
  14.  
  15.  
  16.     void Start()
  17.     {
  18.         this.gameObject.GetComponent<UnityEngine.Networking.NetworkManager>().StartMatchMaker();
  19.     }
  20.     void Update()
  21.     {
  22.     }
  23.     public void CreateInternetMatch(string matchName)
  24.     {
  25.         UnityEngine.Networking.NetworkManager.singleton.matchMaker.CreateMatch(matchName, 4, true, "", "", "", 0, 0, OnInternetMatchCreate);
  26.     }
  27.     public void OnInternetMatchCreate(bool success, string extendedInfo, UnityEngine.Networking.Match.MatchInfo matchInfo)
  28.     {
  29.         UnityEngine.Networking.Match.MatchInfo hostInfo = null;
  30.  
  31.         hostInfo = matchInfo;
  32.         if (success)
  33.         {
  34.             UnityEngine.Debug.Log("Create match succeeded");
  35.             UnityEngine.Networking.NetworkServer.Listen(hostInfo, 9000);
  36.             UnityEngine.Networking.NetworkManager.singleton.StartHost(hostInfo);
  37.         }
  38.         else
  39.         {
  40.             UnityEngine.Debug.Log("Create match failed");
  41.         }
  42.  
  43.     }
  44.     public void FindInternetMatch(string matchName)
  45.     {
  46.         UnityEngine.Networking.NetworkManager.singleton.matchMaker.ListMatches(0, 10, matchName, true, 0, 0, OnInternetMatchList);
  47.     }
  48.     public void ListInternetMatch()
  49.     {
  50.         ///Listet alle matches in eine List<MatchInfoSnapshot>
  51.         UnityEngine.Networking.NetworkManager.singleton.matchMaker.ListMatches(0, 99, "", true, 0, 0, OnListInternetMatchList);
  52.     }
  53.     private void OnInternetMatchList(bool success, string extendedInfo, System.Collections.Generic.List<UnityEngine.Networking.Match.MatchInfoSnapshot> matches)
  54.     {
  55.         if (success)
  56.         {
  57.             if ((matches.Count != 0))
  58.             {
  59.                 UnityEngine.Debug.Log("A list of matches was returned");
  60.                 UnityEngine.Networking.NetworkManager.singleton.matchMaker.JoinMatch(matches[(matches.Count - 1)].networkId, "", "", "", 0, 0, OnJoinInternetMatch);
  61.             }
  62.             else
  63.             {
  64.                 UnityEngine.Debug.Log("Some error ocured while the MatchList was checked...");
  65.             }
  66.  
  67.         }
  68.  
  69.     }
  70.     public void OnListInternetMatchList(bool success, string extendedInfo, System.Collections.Generic.List<UnityEngine.Networking.Match.MatchInfoSnapshot> matches)
  71.     {
  72.         if (success)
  73.         {
  74.             if ((matches.Count != 0))
  75.             {
  76.                 foreach (var iterator_257 in matches)
  77.                 {
  78.                     var _TempVar_271_1 = new LobbyList_Data();
  79.                     _TempVar_271_1.matchDescription = "Lorem Impsum dolor sit amet blalbalblablabla blablablabablabla blablablabla";
  80.                     _TempVar_271_1.matchInfo = iterator_257;
  81.                     _TempVar_271_1.matchName = iterator_257.name;
  82.                     LobbyList_Data_Output.Add(_TempVar_271_1);
  83.                     LobbyList_ScrollerController_LobbyList_ScrollerController.RefreshList_Data(LobbyList_Data_Output);
  84.                 }
  85.             }
  86.             else
  87.             {
  88.                 UnityEngine.Debug.Log("There is no match you could join. Please host your own");
  89.             }
  90.  
  91.         }
  92.  
  93.     }
  94.     public void OnJoinInternetMatch(bool success, string extendedInfo, UnityEngine.Networking.Match.MatchInfo matchInfo)
  95.     {
  96.         if (success)
  97.         {
  98.             UnityEngine.Debug.Log("Able to join a match");
  99.             UnityEngine.Networking.NetworkManager.singleton.StartClient(matchInfo);
  100.         }
  101.         else
  102.         {
  103.             UnityEngine.Debug.Log("Join match failed");
  104.         }
  105.  
  106.     }
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement