暫無描述
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

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