暂无描述
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

DrawActionButtonWithMenu.cs 1.5KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using UnityEditor;
  3. using UnityEngine;
  4. namespace Unity.PlasticSCM.Editor.UI
  5. {
  6. internal static class DrawActionButtonWithMenu
  7. {
  8. internal static void For(string buttonText, Action buttonAction, GenericMenu actionMenu)
  9. {
  10. // Action button
  11. GUIContent buttonContent = new GUIContent(buttonText);
  12. GUIStyle buttonStyle = new GUIStyle(EditorStyles.miniButtonLeft);
  13. buttonStyle.stretchWidth = false;
  14. float width = MeasureMaxWidth.ForTexts(buttonStyle, buttonText);
  15. Rect rt = GUILayoutUtility.GetRect(
  16. buttonContent,
  17. buttonStyle,
  18. GUILayout.MinWidth(width),
  19. GUILayout.MaxWidth(width));
  20. if (GUI.Button(rt, buttonContent, buttonStyle))
  21. {
  22. buttonAction();
  23. }
  24. // Menu dropdown
  25. GUIStyle dropDownStyle = new GUIStyle(EditorStyles.miniButtonRight);
  26. GUIContent dropDownContent = new GUIContent(string.Empty, Images.GetDropDownIcon());
  27. Rect dropDownRect = GUILayoutUtility.GetRect(
  28. dropDownContent,
  29. dropDownStyle,
  30. GUILayout.MinWidth(DROPDOWN_BUTTON_WIDTH),
  31. GUILayout.MaxWidth(DROPDOWN_BUTTON_WIDTH));
  32. if (EditorGUI.DropdownButton(dropDownRect, dropDownContent, FocusType.Passive, dropDownStyle))
  33. {
  34. actionMenu.DropDown(dropDownRect);
  35. }
  36. }
  37. const int DROPDOWN_BUTTON_WIDTH = 16;
  38. }
  39. }