Ejemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Create a toggle setting
        /// </summary>
        /// <param name="p_Parent">Parent transform</param>
        /// <param name="p_Text">Toggle caption</param>
        /// <param name="p_Action">Toggle callback</param>
        /// <param name="p_HoverHint">Hover hint text</param>
        public static BSMLToggleSetting Create(UnityEngine.Transform p_Parent, string p_Text, bool p_Enabled, Action <bool> p_Action, string p_HoverHint = null)
        {
            if (m_ToggleSettingCreator == null)
            {
                m_ToggleSettingCreator = new BSMLToggleSettingTag();
            }

            var l_ToggleObject = m_ToggleSettingCreator.CreateObject(p_Parent);

            l_ToggleObject.gameObject.SetActive(false);

            var l_Toggle = l_ToggleObject.GetComponent <BSMLToggleSetting>();

            l_Toggle.Text  = p_Text;
            l_Toggle.Value = p_Enabled;
            l_Toggle.toggle.onValueChanged.AddListener((x) => { p_Action(x); });

            if (!string.IsNullOrEmpty(p_HoverHint))
            {
                HMUI.HoverHint l_HoverHint = l_ToggleObject.GetComponent <HMUI.HoverHint>() ?? l_ToggleObject.AddComponent <HMUI.HoverHint>();
                l_HoverHint.text = p_HoverHint;
                l_HoverHint.SetField("_hoverHintController", UnityEngine.Resources.FindObjectsOfTypeAll <HMUI.HoverHintController>().First());
            }

            l_ToggleObject.gameObject.SetActive(true);
            return(l_Toggle);
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Create a primary button
        /// </summary>
        /// <param name="p_Parent">Parent transform</param>
        /// <param name="p_Text">Button caption</param>
        /// <param name="p_Action">Button callback</param>
        /// <param name="p_HoverHint">Hover hint text</param>
        /// <param name="p_PreferedWidth">Prefered width</param>
        /// <param name="p_PreferedHeight">Prefered height</param>
        public static UnityEngine.UI.Button CreatePrimary(UnityEngine.Transform p_Parent, string p_Text, Action p_Action, string p_HoverHint = null, float?p_PreferedWidth = null, float?p_PreferedHeight = null)
        {
            if (m_PrimaryButtonCreator == null)
            {
                m_PrimaryButtonCreator = new Internal.BSMLPrimaryButtonTag();
            }

            var l_ButtonObject = m_PrimaryButtonCreator.CreateObject(p_Parent);

            l_ButtonObject.SetActive(false);

            l_ButtonObject.GetComponentInChildren <TextMeshProUGUI>().text = p_Text;

            var l_Button = l_ButtonObject.GetComponent <UnityEngine.UI.Button>();

            l_Button.onClick.RemoveAllListeners();
            l_Button.onClick.AddListener(() => p_Action());

            if (p_PreferedWidth.HasValue)
            {
                l_ButtonObject.GetComponent <UnityEngine.UI.LayoutElement>().preferredWidth = p_PreferedWidth.Value;
            }
            if (p_PreferedHeight.HasValue)
            {
                l_ButtonObject.GetComponent <UnityEngine.UI.LayoutElement>().preferredHeight = p_PreferedHeight.Value;
            }

            if (!string.IsNullOrEmpty(p_HoverHint))
            {
                HMUI.HoverHint l_HoverHint = l_ButtonObject.GetComponent <HMUI.HoverHint>() ?? l_ButtonObject.AddComponent <HMUI.HoverHint>();
                l_HoverHint.text = p_HoverHint;
                l_HoverHint.SetField("_hoverHintController", UnityEngine.Resources.FindObjectsOfTypeAll <HMUI.HoverHintController>().First());
            }

            l_ButtonObject.SetActive(true);
            return(l_ButtonObject.GetComponent <UnityEngine.UI.Button>());
        }