Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

Toolbar.cs 2.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. using UnityEditor.U2D.Common;
  2. using UnityEngine.Assertions;
  3. using UnityEngine.U2D.Common;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.U2D.Animation
  6. {
  7. #if ENABLE_UXML_SERIALIZED_DATA
  8. [UxmlElement]
  9. #endif
  10. internal partial class Toolbar : VisualElement
  11. {
  12. private const string k_UssPath = "SkinningModule/ToolbarStyle.uss";
  13. #if ENABLE_UXML_TRAITS
  14. public class ToolbarFactory : UxmlFactory<Toolbar, ToolbarUxmlTraits> {}
  15. public class ToolbarUxmlTraits : UxmlTraits {}
  16. #endif
  17. protected ShortcutUtility m_ShortcutUtility;
  18. protected static Toolbar GetClone(string uxmlPath, string toolbarId)
  19. {
  20. var visualTree = ResourceLoader.Load<VisualTreeAsset>(uxmlPath);
  21. return visualTree.CloneTree().Q<Toolbar>(toolbarId);
  22. }
  23. public Toolbar()
  24. {
  25. AddToClassList("Toolbar");
  26. styleSheets.Add(ResourceLoader.Load<StyleSheet>(k_UssPath));
  27. if (EditorGUIUtility.isProSkin)
  28. AddToClassList("Dark");
  29. }
  30. public void SetButtonChecked(Button toCheck)
  31. {
  32. var buttons = this.Query<Button>();
  33. buttons.ForEach((button) => { button.SetChecked(button == toCheck); });
  34. }
  35. protected void SetButtonChecked(Button button, bool check)
  36. {
  37. if (button.IsChecked() != check)
  38. {
  39. if (check)
  40. {
  41. button.AddToClassList("Checked");
  42. button.Focus();
  43. }
  44. else
  45. button.RemoveFromClassList("Checked");
  46. button.SetChecked(check);
  47. }
  48. }
  49. public void CollapseToolBar(bool collapse)
  50. {
  51. if (collapse)
  52. AddToClassList("Collapse");
  53. else
  54. RemoveFromClassList("Collapse");
  55. }
  56. protected void RestoreButtonTooltips(string uxmlPath, string toolbarId)
  57. {
  58. var clone = GetClone(uxmlPath, toolbarId);
  59. var clonedButtons = clone.Query<Button>().ToList();
  60. var originalButtons = this.Query<Button>().ToList();
  61. Assert.AreEqual(originalButtons.Count, clonedButtons.Count);
  62. for (var i = 0; i < clonedButtons.Count; ++i)
  63. {
  64. originalButtons[i].tooltip = clonedButtons[i].tooltip;
  65. originalButtons[i].LocalizeTextInChildren();
  66. }
  67. }
  68. }
  69. }