Example #1
0
        private void AddPageButtons()
        {
            try
            {
                RectTransform viewport = _mainSettingsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Viewport");
                viewport.anchorMin        = new Vector2(0f, 0.5f);
                viewport.anchorMax        = new Vector2(1f, 0.5f);
                viewport.sizeDelta        = new Vector2(0f, 48f);
                viewport.anchoredPosition = new Vector2(0f, 0f);

                RectTransform container = (RectTransform)_mainSettingsTableView.transform;


                if (_pageUpButton == null)
                {
                    _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageUpButton")), container);

                    _pageUpButton.transform.SetParent(container.parent);
                    _pageUpButton.transform.localScale    /= 1.4f;
                    _pageUpButton.transform.localPosition += new Vector3(0, 4f);
                    //_pageUpButton.interactable = false;

                    _pageUpButton.onClick.RemoveAllListeners();
                    _pageUpButton.onClick.AddListener(() =>
                    {
                        subMenuTableView.GetPrivateField <RectTransform>("_scrollRectTransform").SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 48);
                        subMenuTableViewHelper.PageScrollUp();
                    });
                }

                if (_pageDownButton == null)
                {
                    _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PageDownButton")), container);

                    _pageDownButton.transform.SetParent(container.parent);
                    _pageDownButton.transform.localScale    /= 1.4f;
                    _pageDownButton.transform.localPosition -= new Vector3(0, 5f);
                    //_pageDownButton.interactable = false;

                    _pageDownButton.onClick.RemoveAllListeners();
                    _pageDownButton.onClick.AddListener(() =>
                    {
                        subMenuTableView.GetPrivateField <RectTransform>("_scrollRectTransform").SetSizeWithCurrentAnchors(RectTransform.Axis.Vertical, 48);
                        subMenuTableViewHelper.PageScrollDown();
                    });
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[SettingsUI] Crash when trying to add page buttons! Exception: {ex.ToString()}");
            }
        }
Example #2
0
        private void AddPageButtons()
        {
            try
            {
                RectTransform viewport = _mainSettingsTableView.GetComponentsInChildren <RectTransform>().First(x => x.name == "Viewport");
                viewport.anchorMin        = new Vector2(0f, 0.5f);
                viewport.anchorMax        = new Vector2(1f, 0.5f);
                viewport.sizeDelta        = new Vector2(0f, 48f);
                viewport.anchoredPosition = new Vector2(0f, 0f);

                RectTransform container = (RectTransform)_mainSettingsTableView.transform;

                if (_pageUpButton == null)
                {
                    _pageUpButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageUpButton")), container);

                    _pageUpButton.transform.SetParent(container.parent);
                    _pageUpButton.transform.localScale     = Vector3.one;
                    _pageUpButton.transform.localPosition -= new Vector3(0, 4.5f);
                    _pageUpButton.interactable             = false;
                    _pageUpButton.onClick.AddListener(delegate()
                    {
                        subMenuTableViewHelper.PageScrollUp();
                    });
                }

                if (_pageDownButton == null)
                {
                    _pageDownButton = Instantiate(Resources.FindObjectsOfTypeAll <Button>().First(x => (x.name == "PageDownButton")), container);

                    _pageDownButton.transform.SetParent(container.parent);
                    _pageDownButton.transform.localScale     = Vector3.one;
                    _pageDownButton.transform.localPosition -= new Vector3(0, 6.5f);
                    _pageDownButton.interactable             = false;
                    _pageDownButton.onClick.AddListener(delegate()
                    {
                        subMenuTableViewHelper.PageScrollDown();
                    });
                }

                subMenuTableViewHelper._pageUpButton   = _pageUpButton;
                subMenuTableViewHelper._pageDownButton = _pageDownButton;
            }
            catch (Exception ex)
            {
                Console.WriteLine($"[SettingsUI] Crash when trying to add page buttons! Exception: {ex.ToString()}");
            }
        }