/// <summary> /// Closes the panel by destroying the object (removing any ongoing UI overhead). /// </summary> internal static void Close() { // Don't do anything if no panel. if (panel == null) { return; } // Destroy game objects. GameObject.Destroy(panel); GameObject.Destroy(uiGameObject); // Let the garbage collector do its work (and also let us know that we've closed the object). panel = null; uiGameObject = null; // Show previous window, if any. InfoPanelManager.Panel?.Show(); }
/// <summary> /// Creates the panel object in-game and displays it. /// </summary> /// <param name="isTree">True if it should be created with trees selected, false for props</param> /// <param name="selectedPrefab">Already selected prefab (null if none)</param> internal static void Create(bool isTree, PrefabInfo selectedPrefab) { try { // If no GameObject instance already set, create one. if (uiGameObject == null) { // Give it a unique name for easy finding with ModTools. uiGameObject = new GameObject("BOBScalePanel"); uiGameObject.transform.parent = UIView.GetAView().transform; // Create new panel instance and add it to GameObject. panel = uiGameObject.AddComponent <BOBScalePanel>(); panel.transform.parent = uiGameObject.transform.parent; // Set tree status. if (isTree) { panel.treeCheck.isChecked = true; } // Select previously selected prefab, if any. if (selectedPrefab != null) { panel.SelectedLoadedPrefab = selectedPrefab; panel.loadedList.FindItem(selectedPrefab); } // Hide previous window, if any. InfoPanelManager.Panel?.Hide(); } } catch (Exception e) { Logging.LogException(e, "exception creating scale panel"); } }