Exemple #1
0
 protected virtual void Awake()
 {
     if (Singleton == null)
     {
         GetComponent <LiteNetLib4MirrorTransport>().InitializeTransport();
         Singleton = this;
     }
 }
Exemple #2
0
        private IEnumerator StartDiscovery()
        {
            _noDiscovering = false;

            LiteNetLib4MirrorDiscovery.InitializeFinder();
            LiteNetLib4MirrorDiscovery.Singleton.onDiscoveryResponse.AddListener(OnClientDiscoveryResponse);
            while (!_noDiscovering)
            {
                LiteNetLib4MirrorDiscovery.SendDiscoveryRequest(string.Empty);
                yield return(new WaitForSeconds(discoveryInterval));
            }

            LiteNetLib4MirrorDiscovery.Singleton.onDiscoveryResponse.RemoveListener(OnClientDiscoveryResponse);
            LiteNetLib4MirrorDiscovery.StopDiscovery();
        }
        /*private void Awake()
         * {
         *      _managerHud = GetComponent<NetworkManagerHUD>();
         * }*/

        /*private void OnGUI()
         * {
         *      if (!_managerHud.showGUI)
         *      {
         *              _noDiscovering = true;
         *              return;
         *      }
         *
         *      GUILayout.BeginArea(new Rect(10 + _managerHud.offsetX + 215 + 10, 40 + _managerHud.offsetY, 215, 9999));
         *      if (!NetworkClient.isConnected && !NetworkServer.active)
         *      {
         *              if (_noDiscovering)
         *              {
         *                      if (GUILayout.Button("Start Discovery"))
         *                      {
         *                              StartCoroutine(StartDiscovery());
         *                      }
         *              }
         *              else
         *              {
         *                      GUILayout.Label("Discovering..");
         *                      GUILayout.Label($"LocalPort: {LiteNetLib4MirrorTransport.Singleton.port}");
         *                      if (GUILayout.Button("Stop Discovery"))
         *                      {
         *                              _noDiscovering = true;
         *                      }
         *              }
         *      }
         *      else
         *      {
         *              _noDiscovering = true;
         *      }
         *
         *      GUILayout.EndArea();
         *
         * }*/

        private IEnumerator StartDiscovery()
        {
            _noDiscovering = false;

            LiteNetLib4MirrorDiscovery.InitializeFinder();
            LiteNetLib4MirrorDiscovery.Singleton.onDiscoveryResponse.AddListener(OnClientDiscoveryResponse);
            while (!_noDiscovering)
            {
                ResetList();
                for (int i = 0; i < 20; i++)
                {
                    LiteNetLib4MirrorDiscovery.SendDiscoveryRequest("NetworkManagerHUD");
                    yield return(new WaitForSeconds(discoveryInterval / 100f));
                }
                yield return(new WaitForSeconds(discoveryInterval));
            }

            LiteNetLib4MirrorDiscovery.Singleton.onDiscoveryResponse.RemoveListener(OnClientDiscoveryResponse);
            LiteNetLib4MirrorDiscovery.StopDiscovery();
        }