Exemplo n.º 1
0
        public VRCEUiQuickScrollMenu(string name, bool addBack = true)
        {
            // Get required information
            Transform orgControl = VRCEUi.InternalQuickMenu.EmojiMenu;

            if (orgControl == null)
            {
                MVRCLogger.LogError("Could not find Emoji Menu!");
                Success = false;
                return;
            }

            // Duplicate object
            GameObject goControl = GameObject.Instantiate(orgControl.gameObject, VRCEUi.QuickMenu.transform);

            if (goControl == null)
            {
                MVRCLogger.LogError("Could not duplicate Emoji Menu!");
                Success = false;
                return;
            }

            // Create game object
            GameObject goContent = new GameObject("Content");

            // Get positions
            ContentPosition = goContent.GetOrAddComponent <RectTransform>();

            // Set UI properties
            Control        = goControl.transform;
            ContentControl = goContent.transform;

            // Get buttons
            UpButtonObject   = Control.Find("PageUp").GetComponent <Button>();
            DownButtonObject = Control.Find("PageDown").GetComponent <Button>();

            // Setup UpButton
            UpButtonObject.onClick      = new Button.ButtonClickedEvent();
            UpButtonObject.interactable = false;
            UpButtonObject.onClick.AddListener(() =>
            {
                if (CurrentPage < 1)
                {
                    return;
                }

                SetPage(CurrentPage - 1);
            });

            // Setup DownButton
            DownButtonObject.onClick      = new Button.ButtonClickedEvent();
            DownButtonObject.interactable = false;
            DownButtonObject.onClick.AddListener(() =>
            {
                if (CurrentPage >= (Pages.Count - 1))
                {
                    return;
                }

                SetPage(CurrentPage + 1);
            });

            // Set required parts
            goControl.name = name;

            // Setup Content
            RectTransform rtBtn = UpButtonObject.transform.GetComponent <RectTransform>();

            ContentControl.SetParent(Control);
            ContentControl.localScale     = Vector3.one;
            ContentControl.localRotation  = Quaternion.identity;
            ContentControl.localPosition  = Vector3.zero;
            ContentPosition.anchorMin     = new Vector2(0f, 0f);
            ContentPosition.anchorMax     = new Vector2(0f, 0f);
            ContentPosition.pivot         = new Vector2(0f, 1f);
            ContentPosition.sizeDelta     = new Vector2(rtBtn.sizeDelta.x * 3f, (rtBtn.sizeDelta.y - 10f) * 3f);
            ContentPosition.localPosition = new Vector3(-((ContentPosition.sizeDelta.x / 2f) + (rtBtn.sizeDelta.x / 2f)), ContentPosition.sizeDelta.y, 0f);

            // Clear menu
            foreach (Transform button in ContentControl)
            {
                if (button == null)
                {
                    continue;
                }
                GameObject.Destroy(button.gameObject);
            }
            foreach (Transform button in Control)
            {
                if (button == null)
                {
                    continue;
                }
                if (button.name == "Content")
                {
                    continue;
                }
                if (button.name == "BackButton" && addBack)
                {
                    continue;
                }
                if (button.name == "PageUp")
                {
                    continue;
                }
                if (button.name == "PageDown")
                {
                    if (!addBack)
                    {
                        button.GetComponent <RectTransform>().localPosition = orgControl.transform.Find("BackButton").GetComponent <RectTransform>().localPosition;
                    }
                    continue;
                }
                GameObject.Destroy(button.gameObject);
            }

            // Finish
            VRCEUiScrollPage page = new VRCEUiScrollPage(this);

            page.SetActive(true);
            Pages.Add(page);
            Success = true;
        }
Exemplo n.º 2
0
        public VRCEUiPageScrollView(string name, Vector2 position, Vector2 size, float spacing, int itemsPerPage, float padding = 0f, Transform parent = null)
        {
            // Create game objects
            GameObject goControl        = new GameObject(name);
            GameObject goContentControl = new GameObject("Content");

            // Get positions
            Position        = goControl.GetOrAddComponent <RectTransform>();
            ContentPosition = goContentControl.GetOrAddComponent <RectTransform>();

            // Set UI properties
            Control        = goControl.transform;
            ContentControl = goContentControl.transform;

            // Set required parts
            if (parent != null)
            {
                Control.SetParent(parent);
            }

            // Setup Control
            Control.localScale     = Vector3.one;
            Control.localRotation  = Quaternion.identity;
            Control.localPosition  = Vector3.zero;
            Position.anchorMin     = new Vector2(0.5f, 0f);
            Position.anchorMax     = new Vector2(0.5f, 0f);
            Position.pivot         = new Vector2(0.5f, 1f);
            Position.localPosition = new Vector3(position.x, position.y, 0f);
            Position.sizeDelta     = size;

            // Create buttons
            VRCEUiButton buttonUp   = new VRCEUiButton("UpButton", new Vector2(0f, -30f), "ʌ Up ʌ", goControl.transform);
            VRCEUiButton buttonDown = new VRCEUiButton("DownButton", new Vector2(0f, (30f - size.y)), "v Down v", goControl.transform);

            // Setup UpButton
            UpButtonPosition            = buttonUp.Position;
            UpButtonObject              = buttonUp.ButtonObject;
            UpButtonControl             = buttonUp.Control;
            UpButtonObject.interactable = false;
            UpButtonPosition.sizeDelta -= new Vector2(0f, Mathf.Ceil(UpButtonPosition.sizeDelta.y / 2f));
            UpButtonObject.onClick.AddListener(() =>
            {
                if (CurrentPage < 1)
                {
                    return;
                }

                SetPage(CurrentPage - 1);
            });

            // Setup DownButton
            DownButtonPosition            = buttonDown.Position;
            DownButtonObject              = buttonDown.ButtonObject;
            DownButtonControl             = buttonDown.Control;
            DownButtonObject.interactable = false;
            DownButtonPosition.sizeDelta -= new Vector2(0f, Mathf.Ceil(DownButtonPosition.sizeDelta.y / 2f));
            DownButtonObject.onClick.AddListener(() =>
            {
                if (CurrentPage >= (Pages.Count - 1))
                {
                    return;
                }

                SetPage(CurrentPage + 1);
            });

            // Setup Content
            ContentControl.SetParent(Control);
            ContentControl.localScale     = Vector3.one;
            ContentControl.localRotation  = Quaternion.identity;
            ContentControl.localPosition  = Vector3.zero;
            ContentPosition.anchorMin     = new Vector2(0.5f, 0f);
            ContentPosition.anchorMax     = new Vector2(0.5f, 0f);
            ContentPosition.pivot         = new Vector2(0.5f, 1f);
            ContentPosition.localPosition = new Vector3(0f, -60f, 0f);
            ContentPosition.sizeDelta     = new Vector2(size.x, size.y - (UpButtonPosition.sizeDelta.y + 100f));

            // Finish
            ItemsPerPage = itemsPerPage;
            Spacing      = spacing;
            Padding      = padding;
            VRCEUiScrollPage page = new VRCEUiScrollPage(itemsPerPage, spacing, padding, this);

            page.SetActive(true);
            Pages.Add(page);
            Success = true;
        }