예제 #1
0
        public static GameObject create_btn(bool toggle_state, ButtonType type, string text, string tooltip, Color textColor, Color backgroundColor, float x_pos, float y_pos, Transform parent, Action listener, Action SecondListener = null, int should_half = 0)
        {
            Transform transform = instantiate(type.to_type());
            var       quickMenu = utils.get_quick_menu();

            float num  = quickMenu.transform.Find("UserInteractMenu/ForceLogoutButton").localPosition.x - quickMenu.transform.Find("UserInteractMenu/BanButton").localPosition.x;
            float num2 = quickMenu.transform.Find("UserInteractMenu/ForceLogoutButton").localPosition.x - quickMenu.transform.Find("UserInteractMenu/BanButton").localPosition.x;

            transform.localPosition = new Vector3(transform.localPosition.x + num * x_pos, transform.localPosition.y + num2 * y_pos, transform.localPosition.z);

            transform.SetParent(parent, false);

            switch (type)
            {
            case ButtonType.Toggle:
                var EnableButton  = transform.Find("Toggle_States_Visible/ON").gameObject;
                var DisableButton = transform.Find("Toggle_States_Visible/OFF").gameObject;

                EnableButton.GetComponentsInChildren <Text>()[0].text  = $"{text}\nON";
                DisableButton.GetComponentsInChildren <Text>()[0].text = $"{text}\nON";

                EnableButton.GetComponentsInChildren <Text>()[1].text  = $"OFF";
                DisableButton.GetComponentsInChildren <Text>()[1].text = $"OFF";

                EnableButton.GetComponentInChildren <Image>().color  = Color.green;
                DisableButton.GetComponentInChildren <Image>().color = Color.red;

                transform.transform.GetComponent <UiTooltip>().text          = tooltip;
                transform.transform.GetComponent <UiTooltip>().alternateText = tooltip;

                transform.transform.GetComponent <UiTooltip>().set_tooltip();

                transform.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();

                if (!toggle_state)
                {
                    EnableButton.SetActive(false);
                    DisableButton.SetActive(true);
                }
                else
                {
                    EnableButton.SetActive(true);
                    DisableButton.SetActive(false);
                }

                transform.GetComponent <Button>().onClick.AddListener(new Action(() =>
                {
                    if (EnableButton.activeSelf)
                    {
                        SecondListener.Invoke();
                        EnableButton.SetActive(false);
                        DisableButton.SetActive(true);
                    }
                    else
                    {
                        listener.Invoke();
                        DisableButton.SetActive(false);
                        EnableButton.SetActive(true);
                    }
                }));
                break;

            case ButtonType.Default:
                transform.GetComponentInChildren <Text>().text      = text;
                transform.GetComponentInChildren <UiTooltip>().text = tooltip;
                transform.GetComponentInChildren <Text>().color     = textColor;
                transform.GetComponentInChildren <Image>().color    = backgroundColor;

                if (should_half == 1)
                {
                    transform.localPosition += new Vector3(0, transform.GetComponent <RectTransform>().sizeDelta.y / 6, 0);
                    transform.GetComponent <RectTransform>().sizeDelta = new Vector2(transform.GetComponent <RectTransform>().sizeDelta.x, transform.GetComponent <RectTransform>().sizeDelta.y / 2);
                }
                else if (should_half == 2)
                {
                    transform.localPosition += new Vector3(0, transform.GetComponent <RectTransform>().sizeDelta.y / 5, 0);
                    transform.localPosition -= new Vector3(0, transform.GetComponent <RectTransform>().sizeDelta.y / 2, 0);
                    transform.GetComponent <RectTransform>().sizeDelta = new Vector2(transform.GetComponent <RectTransform>().sizeDelta.x, transform.GetComponent <RectTransform>().sizeDelta.y / 2);
                }

                transform.GetComponent <Button>().onClick = new Button.ButtonClickedEvent();
                transform.GetComponent <Button>().onClick.AddListener(listener);
                break;
            }

            return(transform.gameObject);
        }