示例#1
0
        internal void Unload()
        {
            try {
                GeometryNotifierDisposable?.Dispose();
                GeometryNotifierDisposable = null;

                CustomPathManager._instance?.OnLevelUnloading();
                foreach (ICustomManager manager in RegisteredManagers.AsEnumerable().Reverse())
                {
                    try {
                        Log.Info($"OnLevelUnloading: {manager.GetType().Name}");
                        manager.OnLevelUnloading();
                    } catch (Exception ex) {
                        ex.LogException(true);
                    }
                }

                try {
                    Flags.OnLevelUnloading();
                }
                catch (Exception ex) {
                    ex.LogException(true);
                }

                GlobalConfig.OnLevelUnloading();

                // destroy immidately to prevent duplicates after hot-reload.
                var uiviewGO = UIView.GetAView().gameObject;
                DestroyImmediate(uiviewGO.GetComponent <RoadSelectionPanels>());
                DestroyImmediate(uiviewGO.GetComponent <RemoveVehicleButtonExtender>());
                DestroyImmediate(uiviewGO.GetComponent <RemoveCitizenInstanceButtonExtender>());
                DestroyImmediate(uiviewGO.GetComponent <RemoveCitizenInstanceButtonExtender>());
                DestroyImmediate(uiviewGO.GetComponent <UITransportDemand>());

                Log.Info("Removing Controls from UI.");
                if (ModUI.Instance)
                {
                    ModUI.Instance.CloseMainMenu(); // Hide the UI ASAP
                    ModUI.Instance.Destroy();
                    Log._Debug("removed UIBase instance.");
                }
            } catch (Exception ex) {
                ex.LogException(true);
            }

            Patcher.Uninstall();

            IsGameLoaded    = false;
            InGameHotReload = false;
        }
示例#2
0
        internal void Load()
        {
            try {
                Log.Info($"TMPELifecycle.Load() called. Mode={Mode}, UpdateMode={UpdateMode}, Scene={Scene}");

                if (Scene == "ThemeEditor")
                {
                    return;
                }

                IsGameLoaded = false;

                InGameUtil.Instantiate();

                VersionUtil.CheckGameVersion();

                IsGameLoaded = true;

                CustomPathManager.OnLevelLoaded();

                ModUI.OnLevelLoaded();
                if (PlayMode)
                {
                    UIView uiView = UIView.GetAView();
                    uiView.AddUIComponent(typeof(UITransportDemand));
                    uiView.gameObject.AddComponent <RemoveVehicleButtonExtender>();
                    uiView.gameObject.AddComponent <RemoveCitizenInstanceButtonExtender>();
                    uiView.gameObject.AddComponent <RoadSelectionPanels>();
                }

                Patcher.Install();

                Log.Info("Notifying managers...");
                foreach (ICustomManager manager in RegisteredManagers)
                {
                    Log.Info($"OnLevelLoading: {manager.GetType().Name}");
                    manager.OnLevelLoading();
                }

                // must be subscribed last to notify other mods about TMPE changes
                // after all TMPE rules are applied.
                GeometryNotifierDisposable = GeometryManager.Instance.Subscribe(new GeometryNotifier());
                Notifier.Instance.OnLevelLoaded();
                Log.Info("OnLevelLoaded complete.");
            } catch (Exception ex) {
                ex.LogException(true);
            }
        }