G2A Many GEOs
SHARE
TWEET

Untitled

a guest Jul 7th, 2015 220 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using BeardedManStudios.Network;
  5. using BeardedManStudios.Forge;
  6.  
  7. public class NetworkMgr : NetworkedMonoBehavior {
  8.  
  9.         [HideInInspector]
  10.         public static readonly string gameTypeName = "Neomex_Exowar_2_Neomex-Studio";
  11.  
  12.         public ushort port = 20555;
  13.  
  14.         private string textArea = "";
  15.         private string textField = "";
  16.         //private string textFieldData = "";
  17.        
  18.         protected override void Awake()
  19.         {
  20.                 AddNetworkVariable(() => textArea, x => textArea = (string)x, new NetSync());
  21.  
  22.                 base.Awake ();
  23.         }
  24.  
  25.         protected override void Start()
  26.         {
  27.                 base.Start();
  28.  
  29.                 DontDestroyOnLoad (this);
  30.  
  31.                 Networking.InitializeFirewallCheck(port);
  32.  
  33.                 if (MultiplayerMenuUI.server) {
  34.                         StartServer ();
  35.                 }
  36.                 if (MultiplayerMenuUI.client) {
  37.                         if(MultiplayerJoinMenuUI.directJoin) {
  38.                                 StartDirectClient();
  39.                         } else {
  40.                                 StartClient ();
  41.                         }
  42.                 }
  43.         }
  44.  
  45.         void StartServer() {
  46.                 Networking.Host (port, Networking.TransportationProtocolType.UDP, 3);
  47.  
  48.                 Networking.Sockets[port].connected += OnServerConnected;
  49.                 Networking.Sockets[port].disconnected += OnServerDisconnected;
  50.                 Networking.Sockets[port].playerConnected += OnServerPlayerConnected;
  51.                 Networking.Sockets[port].playerDisconnected += OnServerPlayerDisconnected;
  52.                 Networking.Sockets[port].error += OnServerError;
  53.         }
  54.  
  55.         void OnServerConnected() {
  56.                 Debug.Log ("Server connected!");
  57.                 //ForgeMasterServer.
  58.         }
  59.  
  60.         void OnServerDisconnected() {
  61.                 Debug.Log ("Server disconnected!");
  62.         }
  63.  
  64.         void OnServerPlayerConnected(NetworkingPlayer player) {
  65.                 Debug.Log ("Player connected: " + player.Ip);
  66.         }
  67.  
  68.         void OnServerPlayerDisconnected(NetworkingPlayer player) {
  69.                 Debug.Log ("Player disconnected: " + player.Ip);
  70.         }
  71.  
  72.         void OnServerError(/*NetworkException exception*/System.Exception exception) {
  73.                 Debug.Log ("Server error: " + exception.Message);
  74.         }
  75.  
  76.         void StartClient() {
  77.         }
  78.  
  79.         void StartDirectClient() {
  80.                 Networking.Connect (MultiplayerJoinMenuUI.directIp, port, Networking.TransportationProtocolType.UDP);
  81.  
  82.                 Networking.Sockets[port].connected += OnClientConnected;
  83.                 Networking.Sockets[port].disconnected += OnClientDisconnected;
  84.                 Networking.Sockets[port].playerConnected += OnClientPlayerConnected;
  85.                 Networking.Sockets[port].playerDisconnected += OnClientPlayerDisconnected;
  86.                 Networking.Sockets[port].error += OnClientError;
  87.                 Networking.Sockets[port].serverDisconnected += OnClientServerDisconnected;
  88.         }
  89.  
  90.         void OnClientConnected() {
  91.                 Debug.Log ("Client connected!");
  92.                 //ForgeMasterServer.
  93.         }
  94.        
  95.         void OnClientDisconnected() {
  96.                 Debug.Log ("Client disconnected!");
  97.         }
  98.        
  99.         void OnClientPlayerConnected(NetworkingPlayer player) {
  100.                 Debug.Log ("Player connected: " + player.Ip);
  101.         }
  102.        
  103.         void OnClientPlayerDisconnected(NetworkingPlayer player) {
  104.                 Debug.Log ("Player disconnected: " + player.Ip);
  105.         }
  106.        
  107.         void OnClientError(/*NetworkException exception*/System.Exception exception) {
  108.                 Debug.Log ("Client error: " + exception.Message);
  109.         }
  110.  
  111.         void OnClientServerDisconnected(string message) {
  112.                 Debug.Log ("Disconnected: " + message);
  113.         }
  114.  
  115.         protected override void Update()
  116.         {
  117.                 base.Update();
  118.         }
  119.  
  120.         void OnGUI() {
  121.                 GUI.TextArea (new Rect (25.0f, 25.0f, 500.0f, 500.0f), textArea);
  122.                 textField = GUI.TextField (new Rect (25.0f, 525.0f, 450.0f, 25.0f), textField);
  123.                 if (GUI.Button (new Rect (475.0f, 525.0f, 50.0f, 25.0f), "Send")) {
  124.                         AppendText();
  125.                 }
  126.         }
  127.  
  128.         void AppendText() {
  129.                 textArea += textField + "\n";
  130.                 textField = "";
  131.         }
  132. }
RAW Paste Data
Ledger Nano X - The secure hardware wallet
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top