示例#1
0
 /// <summary>
 /// Finds a match being announced on UDP.
 /// </summary>
 /// <param name="onSessionFound"></param>
 public static void Find(Action <int, IPAddress> onSessionFound)
 {
     if (_announcing)
     {
         StopAnnouncing();
     }
     Network.Network.BroadcastConnect();
     _onSessionFound = onSessionFound;
     _announcment    = new SessionAnnouncment();
 }
示例#2
0
 /// <summary>
 /// Regularly sends a message to all networked SessionAnnouncments.
 /// </summary>
 private void Broadcast()
 {
     _broadcast = true;
     while (_broadcast)
     {
         _announcer = new SessionAnnouncment(_hostID);
         _announcer.Announce();
         // Wait .35 seconds before announcing again.
         Thread.Sleep(BROADCAST_FREQUENCY);
     }
 }
示例#3
0
        /// <summary>
        /// Broadcast that a given hostID has a session available to join.
        /// </summary>
        /// <param name="hostID">ID of the host who's session is available.</param>
        public static void Announce(int hostID)
        {
            // Close existing connections.
            if (Network.Network.Connected)
            {
                Network.Network.Disconnect();
            }
            Network.Network.BroadcastConnect();
            StopAnnouncing();

            // Run an announcment in the background.
            _hostID = hostID;
            var broadcast = new Thread(Broadcast);

            _announcment = new SessionAnnouncment(_hostID);
            broadcast.Start();

            UnityEngine.Debug.Log("Announce");
        }
示例#4
0
 public SessionAnnouncer(ref SessionAnnouncment _announcment)
 {
     _announcer = _announcment;
 }
示例#5
0
 /// <summary>
 /// Creates an SessionAnnouncment to recieve broadcasted session information.
 /// Sets up the callback for when session is found.
 /// </summary>
 /// <param name="onSessionFound"></param>
 internal void Find(Action <int> onSessionFound)
 {
     _onSessionFound = onSessionFound;
     // Make sure there is an instance of SessionAnnouncment to recieve.
     _announcmentFinder = new SessionAnnouncment();
 }
示例#6
0
 public SessionFinder(ref SessionAnnouncment announcment)
 {
     _announcmentFinder = announcment;
 }
示例#7
0
 /// <summary>
 /// Called when SessionAnnouncment returns with the id
 /// for a hoast advertising a session.
 /// </summary>
 /// <param name="hostID"></param>
 /// <param name="ip"> </param>
 internal static void OnFoundSession(int hostID, IPAddress ip)
 {
     _onSessionFound.Invoke(hostID, ip);
     _announcment = null;
     UnityEngine.Debug.Log("OnFoundSession(" + hostID + "," + ip + ")");
 }