コード例 #1
0
        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);
                }
            }
            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);
            }
        }
コード例 #2
0
        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;
            Destroy(this);
            if (GameObject.GetComponents <Window>().Any(w => w._isOpen) == false)
            {
                AreWindowsOpenChange?.Invoke(false);
            }
        }