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.

MeshToolbar.cs 4.2KB

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