Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using UnityEngine;
- using System.Collections;
- using System.Net;
- using System.Net.Sockets;
- using System.Threading;
- using System.Linq;
- using System.Collections.Generic;
- using System.Globalization;
- public class ElationNetwork : MonoBehaviour
- {
- public enum Modes { Client, Server, Dedicated };
- private Modes _Mode = Modes.Client;
- private string serverHost = "";
- public string ServerHost { get { return serverHost; } }
- private int serverPort = 37659;
- public int ServerPort { get { return serverPort; } }
- #region Stats
- private int _Ping = 0;
- private int _RPCIn = 0;
- private int _RPCOut = 0;
- private int _RPCAcks = 0;
- private int _NetworkBytesIn = 0;
- private int _NetworkBytesOut = 0;
- public string Ping { get { return "Ping: " + _Ping.ToString(); } }
- public string RPCIn { get { return "RPCIn: " + _RPCIn.ToString(); } }
- public string RPCOut { get { return "RPCOut: " + _RPCOut.ToString(); } }
- public string RPCAcks { get { return "RPCAcks: " + _RPCAcks.ToString(); } }
- public string NetworkBytesIn { get { return "Network In (bps): " + _NetworkBytesIn.ToString(); } }
- public string NetworkBytesOut { get { return "Network Out (bps): " + _NetworkBytesOut.ToString(); } }
- public string Mode { get { return "Network Mode: " + _Mode.ToString(); } }
- #endregion
- #region GUI
- public NoesisGUIPanel gui;
- private Noesis.Grid root;
- private Noesis.TextBlock tbRPC_In;
- private Noesis.TextBlock tbRPC_Out;
- private Noesis.TextBlock tbRPC_Acks;
- private Noesis.TextBlock tbPing;
- private Noesis.TextBlock tbNetworkIn;
- private Noesis.TextBlock tbNetworkOut;
- private Noesis.TextBlock tbMode;
- private Noesis.TextBox txtServerHost;
- private Noesis.Button btnConnect;
- private Noesis.Button btnHost;
- #endregion
- // Use this for initialization
- void Start()
- {
- StartCoroutine(InitGUI());
- }
- private IEnumerator InitGUI()
- {
- yield return new WaitForSeconds(1.0f);
- #region Init GUI Variables
- if (gui)
- {
- root = gui.GetRoot<Noesis.Grid>();
- Noesis.StackPanel spStats = root.FindName<Noesis.StackPanel>("spNetworkStats");
- if (spStats != null)
- {
- Debug.Log("Found spStats");
- Noesis.UIElementCollection statLabels = spStats.GetChildren();
- for (uint i = 0; i < statLabels.Count(); i++)
- {
- //Debug.Log("Name: " + statLabels.Get(i).As<Noesis.FrameworkElement>().name));
- }
- // TODO -- Sigh.. Why doesn't this work?
- //tbRPC_In = spStats.FindName<Noesis.TextBlock>("nsRPCIn");
- tbRPC_In = spStats.GetChildren().Get(0).As<Noesis.TextBlock>();
- //tbRPC_Out = spStats.FindName<Noesis.TextBlock>("nsRPCOut");
- tbRPC_Out = spStats.GetChildren().Get(1).As<Noesis.TextBlock>();
- //tbRPC_Acks = spStats.FindName<Noesis.TextBlock>("nsRPCAcks");
- tbRPC_Acks = spStats.GetChildren().Get(2).As<Noesis.TextBlock>();
- //tbNetworkIn = spStats.FindName<Noesis.TextBlock>("nsNetworkIn");
- tbNetworkIn = spStats.GetChildren().Get(3).As<Noesis.TextBlock>();
- //tbNetworkOut = spStats.FindName<Noesis.TextBlock>("nsNetworkOut");
- tbNetworkOut = spStats.GetChildren().Get(4).As<Noesis.TextBlock>();
- //tbPing = spStats.FindName<Noesis.TextBlock>("nsPing");
- tbPing = spStats.GetChildren().Get(5).As<Noesis.TextBlock>();
- tbMode = spStats.GetChildren().Get(6).As<Noesis.TextBlock>();
- Noesis.StackPanel spStatus = root.FindName<Noesis.StackPanel>("spNetworkStatus");
- if (spStatus != null)
- {
- Debug.Log("Found the Network Status Panel!");
- Noesis.FrameworkElement fe = Noesis.LogicalTreeHelper.FindName(spStatus, "btnConnect");
- if (fe != null)
- {
- Debug.Log("Found the connect button!");
- }
- Noesis.UIElementCollection uiec = spStats.GetChildren();
- txtServerHost = spStats.FindName<Noesis.TextBox>("txtServerHost");
- //btnConnect = (Noesis.Button)Noesis.LogicalTreeHelper.FindName(spStatus, "btnConnect");
- btnConnect = spStats.FindName<Noesis.Button>("btnConnect");
- btnHost = spStats.FindName<Noesis.Button>("btnHost");
- btnConnect.Click += new Noesis.BaseButton.ClickDelegate(btnConnect_Click);
- btnHost.Click += new Noesis.BaseButton.ClickDelegate(btnHost_Click);
- }
- UpdateGUI();
- }
- }
- #endregion
- }
- void btnHost_Click(Noesis.BaseComponent sender, Noesis.RoutedEventArgs e)
- {
- //throw new System.NotImplementedException();
- txtServerHost.SetText("127.0.0.1");
- this._Mode = Modes.Server;
- }
- void btnConnect_Click(Noesis.BaseComponent sender, Noesis.RoutedEventArgs e)
- {
- //throw new System.NotImplementedException();
- }
- // Update is called once per frame
- void Update()
- {
- _Ping += 1;
- //if (tbPing != null) tbPing.SetText(this.Ping);
- UpdateGUI();
- }
- void UpdateGUI()
- {
- if (tbRPC_In != null) tbRPC_In.SetText(this.RPCIn);
- if (tbRPC_Out != null) tbRPC_Out.SetText(this.RPCOut);
- if (tbRPC_Acks != null) tbRPC_Acks.SetText(this.RPCAcks);
- if (tbNetworkIn != null) tbNetworkIn.SetTag(this.NetworkBytesIn);
- if (tbNetworkOut != null) tbNetworkOut.SetTag(this.NetworkBytesOut);
- if (tbPing != null) tbPing.SetText(this.Ping);
- if (tbMode != null) tbMode.SetText(this.Mode);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement