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

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

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

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

            // Set UI properties
            Control = goControl.transform;

            // Set required parts
            goControl.name = name;

            // Clear menu
            foreach (Transform button in Control)
            {
                if (button == null)
                {
                    continue;
                }
                if (button.name == "BackButton" && addBack)
                {
                    continue;
                }
                GameObject.Destroy(button.gameObject);
            }

            // Finish
            Success = true;
        }
Ejemplo n.º 2
0
        public static Transform DuplicateButton(Transform button, string name, string text, Vector2 offset, Transform parent = null)
        {
            // Create new one
            GameObject goButton = GameObject.Instantiate(button.gameObject);

            if (goButton == null)
            {
                MVRCLogger.LogError("Could not duplicate button!");
                return(null);
            }

            // Get UI components
            Button objButton = goButton.GetComponentInChildren <Button>();
            Text   objText   = goButton.GetComponentInChildren <Text>();

            // Destroy broke components
            GameObject.DestroyImmediate(goButton.GetComponent <RectTransform>());

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

            // Modify RectTransform
            RectTransform rtOriginal = button.GetComponent <RectTransform>();
            RectTransform rtNew      = goButton.GetComponent <RectTransform>();

            rtNew.localScale       = rtOriginal.localScale;
            rtNew.anchoredPosition = rtOriginal.anchoredPosition;
            rtNew.sizeDelta        = rtOriginal.sizeDelta;
            rtNew.localPosition    = rtOriginal.localPosition + new Vector3(offset.x, offset.y, 0f);
            rtNew.localRotation    = rtOriginal.localRotation;

            // Change UI properties
            objText.text      = text;
            objButton.onClick = new Button.ButtonClickedEvent();

            // Finish
            return(goButton.transform);
        }
Ejemplo n.º 3
0
        public VRCEUiPage(string name, string displayName)
        {
            // Get defaults
            GameObject avatarScreen = VRCEUi.AvatarScreen;
            VRCUiPage  avatarPage   = avatarScreen.GetComponent <VRCUiPage>();

            if (avatarScreen == null || avatarPage == null)
            {
                MVRCLogger.LogError("Could not find avatar screen!");
                Success = false;
                return;
            }

            // Create GameObject
            GameObject goControl = new GameObject(name);

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

            // Set UI properties
            Control = goControl.transform;

            // Set control properties
            Page = goControl.AddComponent <VRCUiPage>();

            // Set required parts
            Control.SetParent(avatarScreen.transform.parent, false);

            // Change UI properties
            Page.AudioHide   = avatarPage.AudioHide;
            Page.AudioShow   = avatarPage.AudioShow;
            Page.displayName = displayName;
            Page.screenType  = avatarPage.screenType;

            // Add control events
            Page.onPageActivated   += () => OnPageActivated?.Invoke();
            Page.onPageDeactivated += () => OnpageDeatvitvated?.Invoke();

            // Finish
            Success = true;
        }
Ejemplo n.º 4
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;
        }