Beispiel #1
0
#pragma warning restore CS0649

        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// On activation
        /// </summary>
        /// <param name="p_FirstActivation">Is the first activation ?</param>
        /// <param name="p_AddedToHierarchy">Activation type</param>
        /// <param name="p_ScreenSystemEnabling">Is screen system enabled</param>
        protected override void DidActivate(bool p_FirstActivation, bool p_AddedToHierarchy, bool p_ScreenSystemEnabling)
        {
            /// Forward event
            base.DidActivate(p_FirstActivation, p_AddedToHierarchy, p_ScreenSystemEnabling);

            /// Initial setup
            if (p_FirstActivation)
            {
                m_ButtonCreator = new BeatSaberMarkupLanguage.Tags.ButtonTag();

                foreach (var l_Plugin in Plugin.Instance.Plugins)
                {
                    var l_Button = AddButton(l_Plugin.Name, () => { l_Plugin.ShowUI(); });
                    m_PluginsButton.Add(l_Plugin, l_Button);
                }
            }

            /// Refresh button states
            foreach (KeyValuePair <Plugins.PluginBase, Button> l_Current in m_PluginsButton)
            {
                l_Current.Value.interactable = l_Current.Key.IsEnabled;
            }

            /// Show welcome message
            if (Config.FirstRun)
            {
                StartCoroutine(ShowTutorialMessage());
                Config.FirstRun = false;
            }
        }
Beispiel #2
0
        ////////////////////////////////////////////////////////////////////////////
        ////////////////////////////////////////////////////////////////////////////

        /// <summary>
        /// Create a 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 Create(UnityEngine.Transform p_Parent, string p_Text, Action p_Action, string p_HoverHint = null, float?p_PreferedWidth = null, float?p_PreferedHeight = null)
        {
            if (m_ButtonCreator == null)
            {
                m_ButtonCreator = new BeatSaberMarkupLanguage.Tags.ButtonTag();
            }

            var l_ButtonObject = m_ButtonCreator.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>());
        }