/// <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); }
public override GameObject CreateObject(Transform parent) { Button button = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => x.name == "PracticeButton"), parent, false); button.name = "BSMLIconButton"; button.interactable = true; Object.Destroy(button.GetComponent <HoverHint>()); GameObject.Destroy(button.GetComponent <LocalizedHoverHint>()); button.gameObject.AddComponent <ExternalComponents>().components.Add(button.GetComponentsInChildren <LayoutGroup>().First(x => x.name == "Content")); Transform contentTransform = button.transform.Find("Content"); GameObject.Destroy(contentTransform.Find("Text").gameObject); Image iconImage = new GameObject("Icon").AddComponent <ImageView>(); iconImage.material = Utilities.ImageResources.NoGlowMat; iconImage.rectTransform.SetParent(contentTransform, false); iconImage.rectTransform.sizeDelta = new Vector2(20f, 20f); iconImage.sprite = Utilities.ImageResources.BlankSprite; iconImage.preserveAspect = true; if (iconImage != null) { ButtonIconImage btnIcon = button.gameObject.AddComponent <ButtonIconImage>(); btnIcon.image = iconImage; } return(button.gameObject); }
public override GameObject CreateObject(Transform parent) { if (buttonTemplate == null) { buttonTemplate = Resources.FindObjectsOfTypeAll <Button>().Last(x => x.name == "UpButton"); } Button button = Object.Instantiate(buttonTemplate, parent, false); button.gameObject.SetActive(false); button.name = "BSMLPageButton"; button.interactable = true; button.gameObject.AddComponent <PageButton>(); LayoutElement layoutElement = button.gameObject.AddComponent <LayoutElement>(); layoutElement.preferredWidth = -1; layoutElement.preferredHeight = -1; layoutElement.flexibleHeight = 0; layoutElement.flexibleWidth = 0; ContentSizeFitter sizeFitter = button.gameObject.AddComponent <ContentSizeFitter>(); sizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; sizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; RectTransform buttonTransform = button.transform.GetChild(0) as RectTransform; buttonTransform.anchorMin = new Vector2(0, 0); buttonTransform.anchorMax = new Vector2(1, 1); buttonTransform.sizeDelta = new Vector2(0, 0); (button.transform as RectTransform).pivot = new Vector2(.5f, .5f); /*RectTransform glow = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll<GameObject>().Last(x => (x.name == "GlowContainer")), button.transform).transform as RectTransform; * glow.gameObject.name = "BSMLPageButtonGlowContainer"; * glow.SetParent(buttonTransform); * glow.anchorMin = new Vector2(0, 0); * glow.anchorMax = new Vector2(1, 1); * glow.sizeDelta = new Vector2(0, 0); * glow.anchoredPosition = new Vector2(0, 0); * * Glowable glowable = button.gameObject.AddComponent<Glowable>(); * glowable.image = button.gameObject.GetComponentsInChildren<Image>(true).Where(x => x.gameObject.name == "Glow").FirstOrDefault(); * glowable.SetGlow("none");*/ ButtonIconImage btnIcon = button.gameObject.AddComponent <ButtonIconImage>(); btnIcon.image = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Icon").FirstOrDefault(); button.gameObject.SetActive(true); return(button.gameObject); }
public override GameObject CreateObject(Transform parent) { Button button = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "SoloFreePlayButton")), parent, false); button.name = "BSMLBigButton"; button.interactable = true; Object.Destroy(button.GetComponent <HoverHint>()); Object.Destroy(button.GetComponent <LocalizedHoverHint>()); Polyglot.LocalizedTextMeshProUGUI localizer = button.GetComponentInChildren <Polyglot.LocalizedTextMeshProUGUI>(); if (localizer != null) { Object.Destroy(localizer); } button.gameObject.AddComponent <ExternalComponents>().components.Add(button.GetComponentInChildren <TextMeshProUGUI>()); Image strokeImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Stroke").FirstOrDefault(); if (strokeImage != null) { Strokable strokable = button.gameObject.AddComponent <Strokable>(); strokable.image = strokeImage; strokable.SetType(StrokeType.Regular); } Image iconImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Icon").FirstOrDefault(); if (iconImage != null) { ButtonIconImage btnIcon = button.gameObject.AddComponent <ButtonIconImage>(); btnIcon.image = iconImage; } Image artworkImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "BGArtwork").FirstOrDefault(); if (artworkImage != null) { ButtonArtworkImage btnArt = button.gameObject.AddComponent <ButtonArtworkImage>(); btnArt.image = artworkImage; } return(button.gameObject); }
public override GameObject CreateObject(Transform parent) { if (buttonWithIconTemplate == null) { buttonWithIconTemplate = Resources.FindObjectsOfTypeAll <Button>().Last(x => x.name == "PracticeButton"); } Button button = Object.Instantiate(buttonWithIconTemplate, parent, false); button.name = "BSMLIconButton"; button.interactable = true; Object.Destroy(button.GetComponent <HoverHint>()); Object.Destroy(button.GetComponent <LocalizedHoverHint>()); button.gameObject.AddComponent <ExternalComponents>().components.Add(button.GetComponentsInChildren <LayoutGroup>().First(x => x.name == "Content")); Transform contentTransform = button.transform.Find("Content"); Object.Destroy(contentTransform.Find("Text").gameObject); Image iconImage = new GameObject("Icon").AddComponent <ImageView>(); iconImage.material = Utilities.ImageResources.NoGlowMat; iconImage.rectTransform.SetParent(contentTransform, false); iconImage.rectTransform.sizeDelta = new Vector2(20f, 20f); iconImage.sprite = Utilities.ImageResources.BlankSprite; iconImage.preserveAspect = true; if (iconImage != null) { ButtonIconImage btnIcon = button.gameObject.AddComponent <ButtonIconImage>(); btnIcon.image = iconImage; } Object.Destroy(button.transform.Find("Content").GetComponent <LayoutElement>()); ContentSizeFitter buttonSizeFitter = button.gameObject.AddComponent <ContentSizeFitter>(); buttonSizeFitter.verticalFit = ContentSizeFitter.FitMode.PreferredSize; buttonSizeFitter.horizontalFit = ContentSizeFitter.FitMode.PreferredSize; return(button.gameObject); }
public override GameObject CreateObject(Transform parent) { Button button = MonoBehaviour.Instantiate(Resources.FindObjectsOfTypeAll <Button>().Last(x => (x.name == "PracticeButton" && x.transform.parent.name == "PlayButtons")), parent, false); button.name = "BSMLIconButton"; button.interactable = true; Object.Destroy(button.GetComponent <HoverHint>()); Object.Destroy(button.GetComponent <LocalizedHoverHint>()); button.gameObject.AddComponent <ExternalComponents>().components.Add(button.GetComponentsInChildren <HorizontalLayoutGroup>().First(x => x.name == "Content")); Image glowImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Glow").FirstOrDefault(); if (glowImage != null) { Glowable glowable = button.gameObject.AddComponent <Glowable>(); glowable.image = glowImage; glowable.SetGlow("none"); } Image strokeImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Stroke").FirstOrDefault(); if (strokeImage != null) { Strokable strokable = button.gameObject.AddComponent <Strokable>(); strokable.image = strokeImage; strokable.SetType(StrokeType.Regular); } Image iconImage = button.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Icon").FirstOrDefault(); if (iconImage != null) { ButtonIconImage btnIcon = button.gameObject.AddComponent <ButtonIconImage>(); btnIcon.image = iconImage; } return(button.gameObject); }
public static Button CreatePageButton(String name, RectTransform parent, String buttonTemplate, Vector2 anchoredPosition, Vector2 sizeDelta, UnityAction onClick, Sprite icon) { Logger.Debug("CreatePageButton({0}, {1}, {2}, {3}, {4}", name, parent, buttonTemplate, anchoredPosition, sizeDelta); Button btn = CreateBaseButton(name, parent, buttonTemplate); (btn.transform as RectTransform).anchorMin = new Vector2(0.5f, 0.5f); (btn.transform as RectTransform).anchorMax = new Vector2(0.5f, 0.5f); (btn.transform as RectTransform).anchoredPosition = anchoredPosition; (btn.transform as RectTransform).sizeDelta = sizeDelta; (btn.transform as RectTransform).pivot = new Vector2(0.5f, 0.5f); ButtonIconImage btnIcon = btn.gameObject.AddComponent <ButtonIconImage>(); btnIcon.image = btn.gameObject.GetComponentsInChildren <Image>(true).Where(x => x.gameObject.name == "Icon").FirstOrDefault(); btnIcon.image.sprite = icon; btn.onClick.RemoveAllListeners(); if (onClick != null) { btn.onClick.AddListener(onClick); } return(btn); }