コード例 #1
0
        public IEnumerator StartNetwork(bool bHost)
        {
            //start listening to other hosts
            NetworkDiscoveryCustom discovery = GetComponent <NetworkDiscoveryCustom>();

            discovery.Initialize();
            if (bHost)
            {
                discovery.StartAsServer();
                StartHost();
            }
            else
            {
                discovery.StartAsClient();

                while (discovery.running)
                {
                    yield return(new WaitForEndOfFrame());
                }
            }
        }
コード例 #2
0
        /// <summary>
        /// Searches for other LAN games in the current network.
        /// </summary>
        public IEnumerator DiscoverNetwork()
        {
            //start listening to other hosts
            NetworkDiscoveryCustom discovery = GetComponent <NetworkDiscoveryCustom>();

            discovery.Initialize();
            discovery.StartAsClient();

            //wait few seconds for broadcasts to arrive
            yield return(new WaitForSeconds(8));

            //we haven't found a match, open our own
            if (discovery.running)
            {
                discovery.StopBroadcast();
                yield return(new WaitForSeconds(0.5f));

                discovery.StartAsServer();
                StartHost();
            }
        }