Ejemplo n.º 1
0
        void Awake()
        {
            Thread worker = new Thread(() =>
            {
                // Bind to application quit event.
                MainThreadDispatcher.OnApplicationQuitAsObservable().Subscribe(_ => Debug.Log("OnApplicationQuitAsObservable"));

                // Create capsules one by one.
                Observable.Interval(TimeSpan.FromMilliseconds(300))
                .Take(5)
                .Subscribe((s) =>
                {
                    var g  = GameObject.CreatePrimitive(PrimitiveType.Capsule);
                    g.name = "Capsule " + s;
                    g.transform.position += new Vector3(s, 0, 0);
                });
            });

            worker.Start();
        }
Ejemplo n.º 2
0
            public static void Register()
            {
                lock (staticLock)
                {
                    if (!hooksRegistered)
                    {
#if NETSTANDARD1_5
                        System.Runtime.Loader.AssemblyLoadContext.Default.Unloading += (assemblyLoadContext) => { HandleShutdown(); };
#elif UNITY_EDITOR
                        MainThreadDispatcher.OnApplicationQuitAsObservable().Subscribe(_ =>
                        {
                            HandleShutdown();
                        });
#else
                        AppDomain.CurrentDomain.ProcessExit  += (sender, eventArgs) => { HandleShutdown(); };
                        AppDomain.CurrentDomain.DomainUnload += (sender, eventArgs) => { HandleShutdown(); };
#endif
                    }
                    hooksRegistered = true;
                }
            }
Ejemplo n.º 3
0
        public ObservablePhotonPeer(ConnectionProtocol protocolType, string peerName = null, int serviceCallRate = 20)
            : base(new ObservablePhotonPeerListener(), protocolType)
        {
            if (serviceCallRate <= 0)
            {
                throw new ArgumentOutOfRangeException("serviceCallRate must be > 0, serviceCallRate:" + serviceCallRate);
            }

            this.Timeout        = TimeSpan.FromSeconds(15); // default timeout
            this.PeerName       = peerName;
            this.callIntervalMs = (int)(1000 / serviceCallRate);
            this.serviceLoop    = new Timer(CallService, null, callIntervalMs, System.Threading.Timeout.Infinite);

#if UNITY_EDITOR
            PhotonWire.Editor.PhotonWireWindow.AddConnection(this);

            MainThreadDispatcher.OnApplicationQuitAsObservable().Subscribe(_ =>
            {
                // If connection is leaked, unity freeze on play again.
                // http://forum.photonengine.com/discussion/6082/leaked-connection-causes-unity-to-freeze
                this.Dispose();
            });
#endif
        }
Ejemplo n.º 4
0
 private void RegisterApplicationQuitEvent(object a)
 {
     MainThreadDispatcher.OnApplicationQuitAsObservable().Subscribe(_ => Debug.Log("OnApplicationQuitAsObservable"));
 }