public override void OnLevelUnloading() { if (_mode != LoadMode.LoadGame && _mode != LoadMode.NewGame) { return; } TransportObserver.ClearSubscribers(); GameObject.Destroy(_extendedBusPanel.gameObject); GameObject.Destroy(_extendedMetroPanel.gameObject); GameObject.Destroy(_extendedTrainPanel.gameObject); }
public override void OnLevelUnloading() { if (_mode != LoadMode.LoadGame && _mode != LoadMode.NewGame) { return; } TransportObserver.ClearSubscribers(); // Making absolutely sure to unsubscribe ALL callbacks that where set on // loading the mod. It seems the game sometimes(?) caches UI Elements even // when going back to the main menu. This obviously leads to issues when // the now non-existent GameObjects are being referenced. if (_busPanel != null) { if (_busPanel.parent != null) { _busPanel.parent.eventVisibilityChanged -= InfoPanelOnEventVisibilityChanged; } _busPanel.eventClick -= BusPanelOnEventClick; _busPanel.eventMouseHover -= BusPanelOnEventMouseHover; _busPanel.eventMouseLeave -= BusPanelOnEventMouseLeave; } if (_metroPanel != null) { _metroPanel.eventClick -= MetroPanelOnEventClick; _metroPanel.eventMouseHover -= MetroPanelOnEventMouseHover; _metroPanel.eventMouseLeave -= MetroPanelOnEventMouseLeave; } if (_trainPanel != null) { _trainPanel.eventClick -= TrainPanelOnEventClick; _trainPanel.eventMouseHover -= TrainPanelOnEventMouseHover; _trainPanel.eventMouseLeave -= TrainPanelOnEventMouseLeave; } if (_extendedBusPanel != null) { GameObject.Destroy(_extendedBusPanel.gameObject); } if (_extendedMetroPanel != null) { GameObject.Destroy(_extendedMetroPanel.gameObject); } if (_extendedTrainPanel != null) { GameObject.Destroy(_extendedTrainPanel.gameObject); } }