Guest User

pisio

a guest
Oct 15th, 2012
42
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. using UnityEngine;
  2. using System.Collections;
  3.  
  4. public class Server : MonoBehaviour {
  5.  
  6.     public  bool is_started = false;
  7.     public int num_connections = 30;
  8.     public int server_port = 5551;
  9.     public int server_start_time;
  10.    
  11.     public int toolbarInt = 0;
  12.    
  13.     // Use this for initialization
  14.     void Start () {
  15.    
  16.     }
  17.    
  18.     // Update is called once per frame
  19.     void Update () {
  20.         print ("Delta Time"+ Time.fixedTime);
  21.         //print(Time.time);
  22.     }
  23.    
  24.     void OnGUI()
  25.     {
  26.         StartAction();
  27.         ServerStatus();
  28.        
  29.            
  30.     }
  31.    
  32.    
  33.     void StartAction()
  34.     {
  35.         if(is_started == false)
  36.         {
  37.             if(GUI.Button(new Rect(10,50,150,30),"Start Server"))
  38.             {
  39.                 Network.InitializeServer(num_connections,server_port,false);
  40.                 server_start_time = (int)Network.time;
  41.                 is_started = true;
  42.             }
  43.         }else{
  44.             if(GUI.Button(new Rect(10,50,150,30),"STOP Server"))
  45.             {
  46.                 Network.Disconnect();
  47.                
  48.                 is_started = false;
  49.             }
  50.         }
  51.        
  52.     }
  53.    
  54.    
  55.     void ServerStatus()
  56.     {
  57.         if(is_started == false){
  58.             return ;
  59.         }
  60.         double serverLifeTime = Network.time - server_start_time;
  61.        
  62.         GUI.Label(new Rect(200,50,200,30),"Max ppls: "+ Network.maxConnections+"/"+Network.connections.Length);
  63.         GUI.Label(new Rect(200,100,200,30),"Server Time: "+serverLifeTime.ToString("F0")); 
  64.        
  65.        
  66.     }
  67. }
RAW Paste Data