Exemple #1
0
        private PhotonPing GetPingImplementation()
        {
            PhotonPing ping = null;

            #if !NETFX_CORE
            if (LoadBalancingPeer.PingImplementation == typeof(PingMono))
            {
                ping = new PingMono(); // using this type explicitly saves it from IL2CPP bytecode stripping
            }
            #endif
            #if NATIVE_SOCKETS
            if (LoadBalancingPeer.PingImplementation == typeof(PingNativeDynamic))
            {
                ping = new PingNativeDynamic();
            }
            #endif
            #if UNITY_WEBGL
            if (LoadBalancingPeer.PingImplementation == typeof(PingHttp))
            {
                ping = new PingHttp();
            }
            #endif

            if (ping == null)
            {
                ping = (PhotonPing)Activator.CreateInstance(LoadBalancingPeer.PingImplementation);
            }

            return(ping);
        }
        public bool Start()
        {
            // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
            // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).
            string address      = this.region.HostAndPort;
            int    indexOfColon = address.LastIndexOf(':');

            if (indexOfColon > 1)
            {
                address = address.Substring(0, indexOfColon);
            }
            this.regionAddress = ResolveHost(address);


            this.ping = this.GetPingImplementation();


            this.Done           = false;
            this.CurrentAttempt = 0;
            this.rttResults     = new List <int>(Attempts);

            #if PING_VIA_COROUTINE
            MonoBehaviourEmpty.Instance.StartCoroutine(this.RegionPingCoroutine());
            #elif UNITY_SWITCH
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0);
            #else
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0, "RegionPing_" + this.region.Code + "_" + this.region.Cluster);
            #endif

            return(true);
        }
        public bool Start()
        {
            // all addresses for Photon region servers will contain a :port ending. this needs to be removed first.
            // PhotonPing.StartPing() requires a plain (IP) address without port or protocol-prefix (on all but Windows 8.1 and WebGL platforms).
            string address      = this.region.HostAndPort;
            int    indexOfColon = address.LastIndexOf(':');

            if (indexOfColon > 1)
            {
                address = address.Substring(0, indexOfColon);
            }
            this.regionAddress = ResolveHost(address);


            this.ping = this.GetPingImplementation();


            this.Done           = false;
            this.CurrentAttempt = 0;

            #if PING_VIA_COROUTINE
            GameObject go = new GameObject();
            go.name = "RegionPing_" + this.region.Code + "_" + this.region.Cluster;
            this.coroutineMonoBehaviour = go.AddComponent <MonoBehaviourEmpty>();        // is defined below, as special case for Unity WegGL
            this.coroutineMonoBehaviour.StartCoroutine(this.RegionPingCoroutine());
            #else
            SupportClass.StartBackgroundCalls(this.RegionPingThreaded, 0, "RegionPing_" + this.region.Code + "_" + this.region.Cluster);
            #endif

            return(true);
        }
        /// <summary>Selects the best fitting ping implementation or uses the one set in RegionHandler.PingImplementation.</summary>
        /// <returns>PhotonPing instance to use.</returns>
        private PhotonPing GetPingImplementation()
        {
            PhotonPing ping = null;

            // using each type explicitly in the conditional code, makes sure Unity doesn't strip the class / constructor.

            #if !UNITY_EDITOR && NETFX_CORE
            if (RegionHandler.PingImplementation == null || RegionHandler.PingImplementation == typeof(PingWindowsStore))
            {
                ping = new PingWindowsStore();
            }
            #elif NATIVE_SOCKETS || NO_SOCKET
            if (RegionHandler.PingImplementation == null || RegionHandler.PingImplementation == typeof(PingNativeDynamic))
            {
                ping = new PingNativeDynamic();
            }
            #elif UNITY_WEBGL
            if (RegionHandler.PingImplementation == null || RegionHandler.PingImplementation == typeof(PingHttp))
            {
                ping = new PingHttp();
            }
            #else
            if (RegionHandler.PingImplementation == null || RegionHandler.PingImplementation == typeof(PingMono))
            {
                ping = new PingMono();
            }
            #endif

            if (ping == null)
            {
                if (RegionHandler.PingImplementation == null)
                {
                    ping = new PingMono();
                }
                else
                {
                    ping = (PhotonPing)Activator.CreateInstance(RegionHandler.PingImplementation);
                }
            }

            return(ping);
        }