static void MenuPerform_TriangulateObject() { var instance = EditorToolbarLoader.GetInstance <TriangulateObject>(); if (instance != null && instance.enabled) { EditorUtility.ShowNotification(instance.PerformAction().notification); ProBuilderAnalytics.SendActionEvent(instance, ProBuilderAnalytics.TriggerType.MenuOrShortcut); } }
/// <summary> /// Draw a menu button. Returns true if the button is active and settings are enabled, false if settings are not enabled. /// </summary> /// <param name="isHorizontal"></param> /// <param name="showOptions"></param> /// <param name="optionsRect"></param> /// <param name="layoutOptions"></param> /// <returns></returns> internal virtual bool DoButton(bool isHorizontal, bool showOptions, ref Rect optionsRect, params GUILayoutOption[] layoutOptions) { bool wasEnabled = GUI.enabled; bool buttonEnabled = (menuActionState & MenuActionState.Enabled) == MenuActionState.Enabled; GUI.enabled = buttonEnabled; GUI.backgroundColor = Color.white; if (iconMode) { if (GUILayout.Button(buttonEnabled || !disabledIcon ? icon : disabledIcon, ToolbarGroupUtility.GetStyle(group, isHorizontal), layoutOptions)) { if (showOptions && (optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled) { DoAlternateAction(); } else { ActionResult result = PerformAction(); EditorUtility.ShowNotification(result.notification); ProBuilderAnalytics.SendActionEvent(this, ProBuilderAnalytics.TriggerType.ProBuilderUI); } } if ((optionsMenuState & MenuActionState.VisibleAndEnabled) == MenuActionState.VisibleAndEnabled) { Rect r = GUILayoutUtility.GetLastRect(); r.x = r.x + r.width - 16; r.y += 0; r.width = 14; r.height = 14; GUI.Label(r, IconUtility.GetIcon("Toolbar/Options", IconSkin.Pro), GUIStyle.none); optionsRect = r; GUI.enabled = wasEnabled; return(buttonEnabled); } else { GUI.enabled = wasEnabled; return(false); } } else { // in text mode always use the vertical layout. isHorizontal = false; GUILayout.BeginHorizontal(MenuActionStyles.rowStyleVertical, layoutOptions); GUI.backgroundColor = ToolbarGroupUtility.GetColor(group); if (GUILayout.Button(menuTitle, MenuActionStyles.buttonStyleVertical)) { ActionResult res = PerformAction(); EditorUtility.ShowNotification(res.notification); ProBuilderAnalytics.SendActionEvent(this, ProBuilderAnalytics.TriggerType.ProBuilderUI); } MenuActionState altState = optionsMenuState; if ((altState & MenuActionState.Visible) == MenuActionState.Visible) { GUI.enabled = GUI.enabled && (altState & MenuActionState.Enabled) == MenuActionState.Enabled; if (DoAltButton(GUILayout.MaxWidth(21), GUILayout.MaxHeight(16))) { DoAlternateAction(); } } GUILayout.EndHorizontal(); GUI.backgroundColor = Color.white; GUI.enabled = wasEnabled; return(false); } }