Exemple #1
0
 void Awake()
 {
     m_instance = this;
     MessageBox.Init();
     Debug.Log(this.name);
     if (!connected)
     {
         if (PlayerPrefs.HasKey(HOST) && PlayerPrefs.HasKey(PORT))
         {
             string host = PlayerPrefs.GetString(HOST);
             short  port = (short)PlayerPrefs.GetInt(PORT);
             connected = MyNetwork.Connect(host, port);
             if (!connected)
             {
                 MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
             }
         }
     }
     if (!connected)
     {
         string host = this.address;
         short  port = this.port;
         connected = MyNetwork.Connect(host, port);
         if (!connected)
         {
             MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
         }
     }
     if (gameScene)
     {
         if (connected)
         {
             // for debug only ...
             CLogin login = new CLogin();
             login.user     = "******";
             login.password = "******";
             // Send(login);
         }
         SceneManager.sceneLoaded += RecvSceneLoaded;
     }
     if (connected && heartBeatTimer == null)
     {
         heartBeatTimer          = new Timer();
         heartBeatTimer.Interval = 3000;
         heartBeatTimer.Elapsed += delegate
         {
             CHeartBeat msg = new CHeartBeat();
             Send(msg);
         };
         heartBeatTimer.Start();
     }
 }
Exemple #2
0
        void Awake()
        {
            m_instance = this;
            MessageBox.Init();
            if (!connected)
            {
                if (PlayerPrefs.HasKey(HOST) && PlayerPrefs.HasKey(PORT))
                {
                    string host = PlayerPrefs.GetString(HOST);
                    short  port = (short)PlayerPrefs.GetInt(PORT);
                    connected = MyNetwork.Connect(host, port);
                    if (!connected)
                    {
                        MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
                    }
                }
            }
            if (!connected)
            {
                string host = this.address;
                short  port = this.port;
                connected = MyNetwork.Connect(host, port);
                if (!connected)
                {
                    MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
                }
            }
            if (gameScene)
            {
                if (connected)
                {
                    // for debug only ...
                    //CLogin login = new CLogin();
                    //Send(login);
                }
                SceneManager.sceneLoaded += RecvSceneLoaded;
            }

            // ask for mall info every 5 min
            ThreadPool.QueueUserWorkItem(incomming.AskMallUpdate, 300000);
            ThreadPool.QueueUserWorkItem(incomming.AskFriendUpdate, 300000);
            ThreadPool.QueueUserWorkItem(incomming.AskFriendRequestUpdate, 300000);
        }
Exemple #3
0
 void Awake()
 {
     m_instance = this;
     MessageBox.Init();
     if (!connected)
     {
         if (PlayerPrefs.HasKey(HOST) && PlayerPrefs.HasKey(PORT))
         {
             string host = PlayerPrefs.GetString(HOST);
             short  port = (short)PlayerPrefs.GetInt(PORT);
             connected = MyNetwork.Connect(host, port);
             if (!connected)
             {
                 MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
             }
         }
     }
     if (!connected)
     {
         string host = this.address;
         short  port = this.port;
         connected = MyNetwork.Connect(host, port);
         if (!connected)
         {
             MessageBox.Show(string.Format("connect to {0}:{1} fail", host, port));
         }
     }
     if (gameScene)
     {
         if (connected)
         {
             // for debug only ...
             CLogin login = new CLogin();
             //Send(login);
         }
         SceneManager.sceneLoaded += RecvSceneLoaded;
     }
 }