Exemplo n.º 1
0
        /// <summary>
        /// Create basic icon button.
        /// </summary>
        /// <param name="name"></param>
        /// <param name="parent"></param>
        /// <param name="buttonTemplate"></param>
        /// <returns></returns>
        public static Button CreateIconButton(String name, RectTransform parent, String buttonTemplate, Sprite icon, String hint)
        {
            Button btn = CreateBaseButton(name, parent, buttonTemplate);

            BeatSaberUI.SetHoverHint(btn.transform as RectTransform, $"{name}_hoverHintText", hint);
            btn.gameObject.AddComponent <ExternalComponents>().components.Add(btn.GetComponentsInChildren <LayoutGroup>().First(x => x.name == "Content"));

            Transform contentTransform = btn.transform.Find("Content");

            GameObject.Destroy(contentTransform.Find("Text").gameObject);
            Image iconImage = new GameObject("Icon").AddComponent <ImageView>();

            iconImage.material = BeatSaberMarkupLanguage.Utilities.ImageResources.NoGlowMat;
            iconImage.rectTransform.SetParent(contentTransform, false);
            iconImage.rectTransform.sizeDelta = new Vector2(10f, 10f);
            iconImage.sprite         = icon;
            iconImage.preserveAspect = true;
            if (iconImage != null)
            {
                ButtonIconImage btnIcon = btn.gameObject.AddComponent <ButtonIconImage>();
                btnIcon.image = iconImage;
            }

            GameObject.Destroy(btn.transform.Find("Content").GetComponent <LayoutElement>());
            btn.GetComponentsInChildren <RectTransform>().First(x => x.name == "Underline").gameObject.SetActive(false);

            ContentSizeFitter buttonSizeFitter = btn.gameObject.AddComponent <ContentSizeFitter>();

            buttonSizeFitter.verticalFit   = ContentSizeFitter.FitMode.Unconstrained;
            buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.Unconstrained;

            btn.onClick.RemoveAllListeners();

            return(btn);
        }
Exemplo n.º 2
0
        public static RectTransform CreateStatIcon(string name, RectTransform template, Transform parent, Sprite icon, String hoverHintText = null)
        {
            RectTransform statIcon = UnityEngine.Object.Instantiate(template, parent, false);

            statIcon.name = name;
            (statIcon.transform as RectTransform).Translate(0, -0.1f, 0);
            BeatSaberUI.SetStatButtonIcon(statIcon, icon);
            BeatSaberUI.DestroyHoverHint(statIcon);

            if (!String.IsNullOrEmpty(hoverHintText))
            {
                BeatSaberUI.SetHoverHint(statIcon, $"{name}_hoverHintText", hoverHintText);
            }

            return(statIcon);
        }