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

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