暫無描述
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

RigToolbar.cs 2.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475
  1. using System;
  2. using UnityEngine.UIElements;
  3. namespace UnityEditor.U2D.Animation
  4. {
  5. internal class RigToolbar : Toolbar
  6. {
  7. private const string k_UxmlPath = "SkinningModule/RigToolbar.uxml";
  8. private const string k_UssPath = "SkinningModule/RigToolbarStyle.uss";
  9. private const string k_ToolbarId = "RigToolbar";
  10. private const string k_CopyRigId = "CopyRig";
  11. private const string k_PasteRigId = "PasteRig";
  12. public class CustomUXMLFactor : UxmlFactory<RigToolbar, UxmlTraits> {}
  13. public event Action ActivateCopyTool = () => {};
  14. public event Action TogglePasteTool = () => {};
  15. public SkinningCache skinningCache { get; set; }
  16. private Button m_CopyBtn;
  17. private Button m_PasteBtn;
  18. public static RigToolbar GenerateFromUXML()
  19. {
  20. var clone = GetClone(k_UxmlPath, k_ToolbarId) as RigToolbar;
  21. clone.BindElements();
  22. clone.SetupShortcutUtility();
  23. clone.LocalizeTextInChildren();
  24. clone.AddShortcutsToToolTips();
  25. return clone;
  26. }
  27. public RigToolbar()
  28. {
  29. styleSheets.Add(ResourceLoader.Load<StyleSheet>(k_UssPath));
  30. }
  31. private void BindElements()
  32. {
  33. m_CopyBtn = this.Q<Button>(k_CopyRigId);
  34. m_CopyBtn.clickable.clicked += () => { ActivateCopyTool(); };
  35. m_PasteBtn = this.Q<Button>(k_PasteRigId);
  36. m_PasteBtn.clickable.clicked += () => { TogglePasteTool(); };
  37. }
  38. private void SetupShortcutUtility()
  39. {
  40. m_ShortcutUtility = new ShortcutUtility(ShortcutIds.pastePanelWeights);
  41. m_ShortcutUtility.OnShortcutChanged = () =>
  42. {
  43. RestoreButtonTooltips(k_UxmlPath, k_ToolbarId);
  44. AddShortcutsToToolTips();
  45. };
  46. }
  47. public void UpdatePasteButtonCheckedState()
  48. {
  49. SetButtonChecked(m_PasteBtn, skinningCache.GetTool(Tools.CopyPaste).isActive);
  50. }
  51. public void UpdatePasteButtonEnabledState()
  52. {
  53. var tool = skinningCache.GetTool(Tools.CopyPaste) as CopyTool;
  54. m_PasteBtn.SetEnabled(tool.hasValidCopiedData);
  55. }
  56. private void AddShortcutsToToolTips()
  57. {
  58. m_ShortcutUtility.AddShortcutToButtonTooltip(this, k_PasteRigId, ShortcutIds.pastePanelWeights);
  59. }
  60. }
  61. }