public void Close() { var node = new ConfigNode(Title.Replace(' ', '_')); node.AddValue("x", (int)_windowRect.x); node.AddValue("y", (int)_windowRect.y); if (WindowPos.SetNode(node.name, node) == false) { WindowPos.AddNode(node); } SaveWindowPos(); _isOpen = false; GameEvents.onScreenResolutionModified.Remove(OnScreenResolutionModified); Destroy(this); if (GameObject.GetComponents <Window>().Any(w => w._isOpen) == false) { AreWindowsOpenChange?.Invoke(false); } }
public static void Create(string title, bool savepos, bool ensureUniqueTitle, int width, int height, Action <Window> drawFunc) { var allOpenWindows = GameObject.GetComponents <Window>(); if (ensureUniqueTitle && allOpenWindows.Any(w => w.Title == title)) { Extensions.Log("Not opening window \"" + title + "\", already open"); return; } var winx = 100; var winy = 100; if (savepos) { var winposNode = WindowPos.GetNode(title.Replace(' ', '_')); if (winposNode != null) { winposNode.TryGetValue("x", ref winx, int.TryParse); winposNode.TryGetValue("y", ref winy, int.TryParse); } else { Extensions.Log("No winpos found for \"" + title + "\", defaulting to " + winx + "," + winy); } if (winx >= Screen.width - width) { winx = Screen.width - width; } if (height == -1) { if (winy >= Screen.height - 100) { winy = (Screen.height - 100) / 2; } } else { if (winy > Screen.height - height) { winy = Screen.height - height; } } Extensions.Log("Screen.width: " + Screen.width.ToString() + " width: " + width.ToString() + " winx: " + winx.ToString()); Extensions.Log("Screen.height: " + Screen.height.ToString() + " height: " + height.ToString() + " winy: " + winy.ToString()); } else { winx = (Screen.width - width) / 2; winy = (Screen.height - height) / 2; } var window = GameObject.AddComponent <Window>(); window._isOpen = true; window._shrinkHeight = height == -1; if (window._shrinkHeight) { height = 5; } window.Title = title; window._windowRect = new Rect(winx, winy, width, height); window._drawFunc = drawFunc; if (allOpenWindows.Length == 0) { AreWindowsOpenChange?.Invoke(true); } }