private void OnDestroy()
    {
        if (IsInitialized)
        {
            controls.Disable();
        }

        TimeManager.Deinitialize();
        Sensors.Deinitialize();
        RenderLimiter.RenderLimitEnabled();

        DestroyImmediate(ManagerHolder);
    }
Beispiel #2
0
        private void Awake()
        {
            stopWatch.Start();
            SIM.Identify();
            RenderLimiter.RenderLimitEnabled();
            if (!PlayerPrefs.HasKey("Salt"))
            {
                byte[] toReadBytes           = new byte[8];
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                rng.GetBytes(toReadBytes);
                PlayerPrefs.SetString("Salt", ByteArrayToString(toReadBytes));
            }

            Config.salt = StringToByteArray(PlayerPrefs.GetString("Salt"));
        }
Beispiel #3
0
    private void Awake()
    {
        if (_instance == null)
        {
            _instance = this;
        }

        if (_instance != this)
        {
            DestroyImmediate(gameObject);
        }

        var unixEpoch = new DateTime(1970, 1, 1, 0, 0, 0, System.DateTimeKind.Utc);

        CurrentTime      = (DateTime.UtcNow - unixEpoch).TotalSeconds;
        SessionStartTime = CurrentTime;
        RenderLimiter.RenderLimitDisabled();
    }
Beispiel #4
0
        private void Awake()
        {
            stopWatch.Start();
            RenderLimiter.RenderLimitEnabled();

            var info = Resources.Load <BuildInfo>("BuildInfo");

            SIM.Init(info == null ? "Development" : info.Version);

            if (PlayerPrefs.HasKey("Salt"))
            {
                Config.salt = StringToByteArray(PlayerPrefs.GetString("Salt"));
            }
            else
            {
                Config.salt = new byte[8];
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                rng.GetBytes(Config.salt);
                PlayerPrefs.SetString("Salt", ByteArrayToString(Config.salt));
                PlayerPrefs.Save();
            }
        }
Beispiel #5
0
        private void Init()
        {
            RenderLimiter.RenderLimitEnabled();
            if (Instance != null)
            {
                Destroy(gameObject);
                return;
            }

            stopWatch.Start();

            var info = Resources.Load <BuildInfo>("BuildInfo");

            SIM.Init(info == null ? "Development" : info.Version);

            if (PlayerPrefs.HasKey("Salt"))
            {
                Config.salt = StringToByteArray(PlayerPrefs.GetString("Salt"));
            }
            else
            {
                Config.salt = new byte[8];
                RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider();
                rng.GetBytes(Config.salt);
                PlayerPrefs.SetString("Salt", ByteArrayToString(Config.salt));
                PlayerPrefs.Save();
            }

            if (Config.RunAsMaster)
            {
                var masterGameObject = new GameObject("MasterManager");
                Network.Master = masterGameObject.AddComponent <MasterManager>();
                masterGameObject.AddComponent <MainThreadDispatcher>();
                Network.Master.SetSettings(NetworkSettings);
                Network.Master.StartConnection();
                DontDestroyOnLoad(masterGameObject);
            }
            else
            {
                var clientGameObject = new GameObject("ClientManager");
                Network.Client = clientGameObject.AddComponent <ClientManager>();
                clientGameObject.AddComponent <MainThreadDispatcher>();
                Network.Client.SetSettings(NetworkSettings);
                Network.Client.StartConnection();
                Network.Initialize(SimulationNetwork.ClusterNodeType.Client, NetworkSettings);
                DontDestroyOnLoad(clientGameObject);
            }

            DatabaseManager.Init();

            DownloadManager.Init();
            RestartPendingDownloads();

            if (Config.RunAsMaster)
            {
                try
                {
                    var host = Config.WebHost == "*" ? "localhost" : Config.WebHost;
                    Address = $"http://{host}:{Config.WebPort}";

                    var config = new HostConfiguration {
                        RewriteLocalhost = Config.WebHost == "*"
                    };

                    Server = new NancyHost(new UnityBootstrapper(), config, new Uri(Address));
                    if (!string.IsNullOrEmpty(Config.Username))
                    {
                        LoginAsync();
                    }
                    else
                    {
                        Server.Start();
                    }
                }
                catch (SocketException ex)
                {
                    Debug.LogException(ex);
#if UNITY_EDITOR
                    UnityEditor.EditorApplication.isPlaying = false;
#else
                    // return non-zero exit code
                    Application.Quit(1);
#endif
                    return;
                }
            }

            LoaderScene = SceneManager.GetActiveScene().name;
            SIM.LogSimulation(SIM.Simulation.ApplicationStart);

            DontDestroyOnLoad(this);
            Instance = this;
        }