Пример #1
0
        public VRCEUiButton(string name, Vector2 position, string text, Transform parent = null)
        {
            // Get required information
            Transform orgControl = VRCEUi.InternalUserInfoScreen.FavoriteButton;

            if (orgControl == null)
            {
                ExtendedLogger.LogError("Could not find Favorite button!");
                Success = false;
                return;
            }

            // Duplicate object
            GameObject goControl = GameObject.Instantiate(orgControl.gameObject);

            if (goControl == null)
            {
                ExtendedLogger.LogError("Could not duplicate Favorite button!");
                Success = false;
                return;
            }

            // Set UI properties
            Control       = goControl.transform;
            ButtonControl = Control.Find("FavoriteButton");
            ImageControl  = ButtonControl.Find("Image");
            TextControl   = Control.GetComponentInChildren <Text>().transform;

            // Remove components that may cause issues
            GameObject.DestroyImmediate(Control.GetComponent <RectTransform>());
            GameObject.DestroyImmediate(ButtonControl.GetComponent <VRCUiButton>());

            // Set control properties
            Button = ButtonControl.GetComponent <Button>();
            Text   = TextControl.GetComponent <Text>();

            // Set required parts
            if (parent != null)
            {
                Control.SetParent(parent);
            }
            goControl.name     = name;
            ButtonControl.name = name + "Button";

            // Modify RectTransform
            Position = Control.GetComponent <RectTransform>();
            RectTransform tmpRT = orgControl.GetComponent <RectTransform>();

            Position.localScale       = tmpRT.localScale;
            Position.anchoredPosition = tmpRT.anchoredPosition;
            Position.sizeDelta        = tmpRT.sizeDelta;
            Position.localPosition    = new Vector3(position.x, position.y, 0f);
            Position.localRotation    = tmpRT.localRotation;

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

            // Finish
            Success = true;
        }