Esempio n. 1
0
        private static bool OnQueueStatusThunk(QueueStatus status)
        {
            if (SpatialOS.OnQueueStatus != null)
            {
                SpatialOS.OnQueueStatus(status);
            }

            return(!SpatialOS.Disconnecting);
        }
        private IEnumerator Connect()
        {
            if (ShouldGetDeploymentList())
            {
                var callback = SpatialOS.OnDeploymentListReceived ?? OnDeploymentListReceived;
                var getList  = WorkerConnection.GetDeploymentListAsync(parameters, callback, chosenDeployment => Deployment = chosenDeployment);

                yield return(getList);

                var listWait = new WaitUntil(() => Deployment.HasValue);
                yield return(listWait);
            }

            // Can't start prepooling assets until a deployment is chosen, since the Streaming strategy needs to know which assembly it should stream assets from.
            if (legacyEntityPipeline != null)
            {
                var prepareAssetsCoroutine = legacyEntityPipeline.PrepareAssets();
                if (prepareAssetsCoroutine != null)
                {
                    yield return(prepareAssetsCoroutine);
                }
            }

            var connect = WorkerConnection.ConnectAsync(parameters, Deployment, AttachConnection);

            yield return(connect);

            SpatialOS.ConnectionWasSuccessful = Connection.IsConnected;
            if (SpatialOS.ConnectionWasSuccessful)
            {
                logger = new LogSender(() => SpatialOS.IsConnected, Connection.SendLogMessage, SpatialOS.Configuration, SpatialOS.LogFilter);
                SetupComponents();

                if (SpatialOS.Configuration.ProtocolLoggingOnStartup)
                {
                    Connection.SetProtocolLoggingEnabled(true);
                }

                eventHandler.ConnectionReady();

                var componentCommander = new ComponentCommander(null, spatialCommunicator);

                Commander          = new Commander(componentCommander, spatialCommunicator);
                ComponentCommander = componentCommander;

                SpatialOS.OnConnectedInternal();
            }
        }
        private void Dispose()
        {
            if (IsDisposed)
            {
                return;
            }

            TryDisposeAndResetReference(ref legacyEntityPipeline);
            TryDispose(EntityPipeline.Internal);
            TryDisposeAndResetReference(ref eventHandler);
            TryDisposeAndResetReference(ref view);
            TryDisposeAndResetReference(ref connection);
            TryDisposeAndResetReference(ref componentCommander);
            TryDisposeAndResetReference(ref commander);
            TryDisposeAndResetReference(ref deferredActionDispatcher);
            TryDisposeAndResetReference(ref logger);

            try
            {
                RemoveComponents();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            try
            {
                SpatialOS.Dispose();
            }
            catch (Exception e)
            {
                Debug.LogException(e);
            }

            IsDisposed = true; // This needs to happen before Destroy(this) because OnDisable() will be called as part of Destroy().
            Destroy(this);
        }
Esempio n. 4
0
 public static void ProcessEvents()
 {
     SpatialOS.ProcessEvents();
 }
 // It is necessary to dispose in OnApplicationQuit() if possible. If we dispose at a later time, we risk getting
 // errors because we interfere with Unity's scene teardown.
 // (Unity will call OnDisable and OnDestroy on all gameobjects immediately rather than calling OnDisable on all objects first
 // before calling the first OnDestroy).
 private void OnApplicationQuit()
 {
     SpatialOS.SignalApplicationQuit();
     Dispose();
 }