Пример #1
0
        /// <summary>
        /// Generic create sort button.
        /// </summary>
        /// <param name="rect"></param>
        /// <param name="templateButtonName"></param>
        /// <param name="buttonText"></param>
        /// <param name="iconName"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="action"></param>
        public static SongSortButton CreateSortButton(RectTransform parent, Button buttonTemplate, Sprite iconSprite, Sprite borderSprite, string buttonText, float fontSize, float x, float y, float w, float h, SongSortMode sortMode, System.Action <SongSortMode> onClickEvent)
        {
            SongSortButton sortButton = new SongSortButton();
            Button         newButton  = UIBuilder.CreateUIButton(parent, buttonTemplate);

            newButton.interactable = true;
            (newButton.transform as RectTransform).anchoredPosition = new Vector2(x, y);
            (newButton.transform as RectTransform).sizeDelta        = new Vector2(w, h);

            UIBuilder.SetButtonText(newButton, buttonText);
            UIBuilder.SetButtonIconEnabled(newButton, false);
            UIBuilder.SetButtonIcon(newButton, iconSprite);
            UIBuilder.SetButtonTextSize(newButton, fontSize);

            Image stroke = newButton.GetComponentsInChildren <Image>().First(btn => btn.name == "Stroke");

            stroke.sprite = borderSprite;
            //stroke.rectTransform.localScale = new Vector2(0.9f, 0.9f);

            newButton.GetComponentsInChildren <HorizontalLayoutGroup>().First(btn => btn.name == "Content").padding = new RectOffset(2, 2, 2, 2);

            newButton.onClick.RemoveAllListeners();
            newButton.onClick.AddListener(delegate()
            {
                onClickEvent(sortMode);
            });

            sortButton.Button   = newButton;
            sortButton.SortMode = sortMode;

            return(sortButton);
        }
Пример #2
0
        /// <summary>
        /// Very generic helper create button method.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="buttonTemplate"></param>
        /// <param name="buttonText"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <returns></returns>
        static public Button CreateButton(RectTransform parent, Button buttonTemplate, String buttonText, float fontSize, float x, float y, float w, float h)
        {
            Button newButton = UIBuilder.CreateUIButton(parent, buttonTemplate);

            newButton.interactable = true;
            (newButton.transform as RectTransform).anchoredPosition = new Vector2(x, y);
            (newButton.transform as RectTransform).sizeDelta        = new Vector2(w, h);

            UIBuilder.SetButtonText(newButton, buttonText);
            UIBuilder.SetButtonIconEnabled(newButton, false);
            UIBuilder.SetButtonTextSize(newButton, fontSize);

            return(newButton);
        }
Пример #3
0
        /// <summary>
        /// Create an icon button, simple.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="buttonTemplate"></param>
        /// <param name="iconSprite"></param>
        /// <returns></returns>
        public static Button CreateIconButton(RectTransform parent, Button buttonTemplate, Sprite iconSprite)
        {
            Button newButton = UIBuilder.CreateUIButton(parent, buttonTemplate);

            newButton.interactable = true;

            RectTransform textRect = newButton.GetComponentsInChildren <RectTransform>(true).FirstOrDefault(c => c.name == "Text");

            if (textRect != null)
            {
                UnityEngine.Object.Destroy(textRect.gameObject);
            }

            UIBuilder.SetButtonIcon(newButton, iconSprite);

            return(newButton);
        }
Пример #4
0
        /// <summary>
        /// Create an icon button, advanced.
        /// Currently has some weird logic in it just for the filter buttons.  Use simple method instead.
        /// </summary>
        /// <param name="parent"></param>
        /// <param name="buttonTemplate"></param>
        /// <param name="iconSprite"></param>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="w"></param>
        /// <param name="h"></param>
        /// <param name="iconWidth"></param>
        /// <param name="iconHeight"></param>
        /// <param name="iconRotation"></param>
        /// <returns></returns>
        public static Button CreateIconButton(RectTransform parent, Button buttonTemplate, Sprite iconSprite, Vector2 pos, Vector2 size, Vector2 iconSize, Vector2 iconScale, float iconRotation)
        {
            Button newButton = UIBuilder.CreateIconButton(parent, buttonTemplate, iconSprite);

            (newButton.transform as RectTransform).anchoredPosition = new Vector2(pos.x, pos.y);
            (newButton.transform as RectTransform).sizeDelta        = new Vector2(size.x, size.y);

            RectTransform iconTransform = newButton.GetComponentsInChildren <RectTransform>(true).First(c => c.name == "Icon");

            iconTransform.gameObject.SetActive(true);

            HorizontalLayoutGroup hgroup = iconTransform.parent.GetComponent <HorizontalLayoutGroup>();

            hgroup.padding = new RectOffset(1, 1, 0, 0);

            iconTransform.sizeDelta  = new Vector2(iconSize.x, iconSize.y);
            iconTransform.localScale = new Vector2(iconScale.x, iconScale.y);
            iconTransform.Rotate(0, 0, iconRotation);

            return(newButton);
        }