示例#1
0
        public static GameObject CreateButton(ButtonType type, string text, string tooltip, Color textColor, Color backgroundColor, float x_pos, float y_pos, Transform parent, Action listener, Action SecondListener = null)
        {
            Transform transform = InstantiateGameobject(type.ConvertToType());
            var       quickMenu = Wrappers.GetQuickMenu();

            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";
                var fontSize = EnableButton.GetComponentsInChildren <Text>()[0].fontSize;

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

                EnableButton.GetComponentInChildren <Image>().color  = backgroundColor;
                DisableButton.GetComponentInChildren <Image>().color = backgroundColor;

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

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

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

                DisableButton.SetActive(true);
                EnableButton.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;

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

            case ButtonType.Half:
                transform.localScale += new Vector3(0, 0.2f, 0);
                transform.GetComponentInChildren <Text>().text      = text;
                transform.GetComponentInChildren <UiTooltip>().text = tooltip;
                transform.GetComponentInChildren <Text>().color     = textColor;
                transform.GetComponentInChildren <Image>().color    = backgroundColor;

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

            return(transform.gameObject);
        }