예제 #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);
        }