Brak opisu
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.

MeshToolbar.cs 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal class MeshToolbar : Toolbar
  7. {
  8. private const string k_UxmlPath = "SkinningModule/MeshToolbar.uxml";
  9. private const string k_ToolbarId = "MeshToolbar";
  10. private const string k_SelectGeometryId = "SelectGeometry";
  11. private const string k_CreateVertexId = "CreateVertex";
  12. private const string k_CreateEdgeId = "CreateEdge";
  13. private const string k_SplitEdgeId = "SplitEdge";
  14. private const string k_GenerateGeometryId = "GenerateGeometry";
  15. public class MeshToolbarFactory : UxmlFactory<MeshToolbar, MeshToolbarUxmlTraits> {}
  16. public class MeshToolbarUxmlTraits : UxmlTraits {}
  17. public event Action<Tools> SetMeshTool = (mode) => {};
  18. public SkinningCache skinningCache { get; set; }
  19. public static MeshToolbar GenerateFromUXML()
  20. {
  21. var clone = GetClone(k_UxmlPath, k_ToolbarId) as MeshToolbar;
  22. clone.BindElements();
  23. clone.SetupShortcutUtility();
  24. clone.LocalizeTextInChildren();
  25. clone.AddShortcutsToToolTips();
  26. return clone;
  27. }
  28. public MeshToolbar()
  29. {
  30. styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/MeshToolbarStyle.uss"));
  31. }
  32. private void BindElements()
  33. {
  34. var button = this.Q<Button>(k_SelectGeometryId);
  35. button.clickable.clicked += () => { SetMeshTool(Tools.EditGeometry); };
  36. button = this.Q<Button>(k_CreateVertexId);
  37. button.clickable.clicked += () => { SetMeshTool(Tools.CreateVertex); };
  38. button = this.Q<Button>(k_CreateEdgeId);
  39. button.clickable.clicked += () => { SetMeshTool(Tools.CreateEdge); };
  40. button = this.Q<Button>(k_SplitEdgeId);
  41. button.clickable.clicked += () => { SetMeshTool(Tools.SplitEdge); };
  42. button = this.Q<Button>(k_GenerateGeometryId);
  43. button.clickable.clicked += () => { SetMeshTool(Tools.GenerateGeometry); };
  44. }
  45. private void SetupShortcutUtility()
  46. {
  47. m_ShortcutUtility = new ShortcutUtility(ShortcutIds.editGeometry,
  48. ShortcutIds.createVertex,
  49. ShortcutIds.createEdge,
  50. ShortcutIds.splitEdge,
  51. ShortcutIds.autoGeometry);
  52. m_ShortcutUtility.OnShortcutChanged = () =>
  53. {
  54. RestoreButtonTooltips(k_UxmlPath, k_ToolbarId);
  55. AddShortcutsToToolTips();
  56. };
  57. }
  58. public void UpdateToggleState()
  59. {
  60. //TODO: Make UI not be aware of BaseTool, Cache, etc. Use Tool enum
  61. var button = this.Q<Button>(k_SelectGeometryId);
  62. SetButtonChecked(button, skinningCache.GetTool(Tools.EditGeometry).isActive);
  63. button = this.Q<Button>(k_CreateVertexId);
  64. SetButtonChecked(button, skinningCache.GetTool(Tools.CreateVertex).isActive);
  65. button = this.Q<Button>(k_CreateEdgeId);
  66. SetButtonChecked(button, skinningCache.GetTool(Tools.CreateEdge).isActive);
  67. button = this.Q<Button>(k_SplitEdgeId);
  68. SetButtonChecked(button, skinningCache.GetTool(Tools.SplitEdge).isActive);
  69. button = this.Q<Button>(k_GenerateGeometryId);
  70. SetButtonChecked(button, skinningCache.GetTool(Tools.GenerateGeometry).isActive);
  71. }
  72. private void AddShortcutsToToolTips()
  73. {
  74. m_ShortcutUtility.AddShortcutToButtonTooltip(this, k_SelectGeometryId, ShortcutIds.editGeometry);
  75. m_ShortcutUtility.AddShortcutToButtonTooltip(this, k_CreateVertexId, ShortcutIds.createVertex);
  76. m_ShortcutUtility.AddShortcutToButtonTooltip(this, k_CreateEdgeId, ShortcutIds.createEdge);
  77. m_ShortcutUtility.AddShortcutToButtonTooltip(this, k_SplitEdgeId, ShortcutIds.splitEdge);
  78. m_ShortcutUtility.AddShortcutToButtonTooltip(this, k_GenerateGeometryId, ShortcutIds.autoGeometry);
  79. }
  80. }
  81. }