Beispiel #1
0
        public static async UniTask ConnectToMasterAsync(
            string masterServerAddress,
            int port,
            string appID,
            CancellationToken token = default)
        {
            if (PhotonNetwork.IsConnected)
            {
                return;
            }

            var task = UniTask.WhenAny(
                Pun2TaskCallback.OnConnectedToMasterAsync().AsAsyncUnitUniTask(),
                Pun2TaskCallback.OnDisconnectedAsync());

            PhotonNetwork.ConnectToMaster(masterServerAddress, port, appID);

            var(winIndex, _, disconnectCause) = await task.WithCancellation(token);

            if (winIndex == 0)
            {
                return;
            }
            throw new ConnectionFailedException(disconnectCause);
        }
Beispiel #2
0
        public static async UniTask ConnectUsingSettingsAsync(
            AppSettings appSettings,
            bool startInOfflineMode = false,
            CancellationToken token = default)
        {
            var task = UniTask.WhenAny(
                Pun2TaskCallback.OnConnectedToMasterAsync().AsAsyncUnitUniTask(),
                Pun2TaskCallback.OnDisconnectedAsync());

            PhotonNetwork.ConnectUsingSettings(appSettings, startInOfflineMode);

            var(winIndex, _, disconnectCause) = await task.WithCancellation(token);

            if (winIndex == 0)
            {
                return;
            }
            throw new ConnectionFailedException(disconnectCause);
        }
Beispiel #3
0
        /// <summary>Can be used to reconnect to the master server after a disconnect.</summary>
        /// <remarks>
        /// After losing connection, you can use this to connect a client to the region Master Server again.
        /// Cache the room name you're in and use RejoinRoom(roomname) to return to a game.
        /// Common use case: Press the Lock Button on a iOS device and you get disconnected immediately.
        /// </remarks>
        public static async UniTask ReconnectAsync(CancellationToken token = default)
        {
            if (PhotonNetwork.IsConnected)
            {
                return;
            }

            var task = UniTask.WhenAny(
                Pun2TaskCallback.OnConnectedToMasterAsync().AsAsyncUnitUniTask(),
                Pun2TaskCallback.OnDisconnectedAsync());

            PhotonNetwork.Reconnect();

            var(winIndex, _, disconnectCause) = await task.WithCancellation(token);

            if (winIndex == 0)
            {
                return;
            }
            throw new ConnectionFailedException(disconnectCause);
        }
Beispiel #4
0
        /// <summary>
        /// Connects to the Photon Cloud region of choice.
        /// </summary>
        /// <remarks>
        /// It's typically enough to define the region code ("eu", "us", etc).
        /// Connecting to a specific cluster may be necessary, when regions get sharded and you support friends / invites.
        ///
        /// In all other cases, you should not define a cluster as this allows the Name Server to distribute
        /// clients as needed. A random, load balanced cluster will be selected.
        ///
        /// The Name Server has the final say to assign a cluster as available.
        /// If the requested cluster is not available another will be assigned.
        ///
        /// Once connected, check the value of CurrentCluster.
        /// </remarks>
        public static async UniTask ConnectToRegionAsync(string region, CancellationToken token = default)
        {
            if (PhotonNetwork.IsConnected)
            {
                return;
            }

            var task = UniTask.WhenAny(
                Pun2TaskCallback.OnConnectedToMasterAsync().AsAsyncUnitUniTask(),
                Pun2TaskCallback.OnDisconnectedAsync());

            PhotonNetwork.ConnectToRegion(region);

            var(winIndex, _, disconnectCause) = await task.AttachExternalCancellation(token);

            if (winIndex == 0)
            {
                return;
            }
            throw new ConnectionFailedException(disconnectCause);
        }