/// <summary> /// Creates the panel object in-game and displays it. /// </summary> private static void Create() { try { // We're now visible - create our gameobject, and give it a unique name for easy finding with ModTools. optionsGameObject = new GameObject("EYMOptionsPanel"); // Attach to game options panel. optionsGameObject.transform.parent = optionsPanel.transform; _panel = optionsGameObject.AddComponent <EYMOptionsPanel>(); _panel.width = optionsPanel.width - 10f; _panel.height = 725f; _panel.clipChildren = false; // Needed to ensure position is consistent if we regenerate after initial opening (e.g. on language change). _panel.relativePosition = new Vector2(10f, 10f); // Set up and show panel. _panel.Setup(optionsPanel.width, optionsPanel.height); } catch (Exception e) { Logging.LogException(e, "exception creating options panel"); } }
/// <summary> /// Closes the panel by destroying the object (removing any ongoing UI overhead). /// </summary> private static void Close() { // Save settings first. ModSettings.Save(); // Enforce C# garbage collection by setting to null. if (_panel != null) { _panel.parent.RemoveUIComponent(_panel); GameObject.Destroy(_panel); _panel = null; } // We're no longer visible - destroy our game object. if (optionsGameObject != null) { GameObject.Destroy(optionsGameObject); optionsGameObject = null; } }