MeshToolbar.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal class MeshToolbar : Toolbar
  7. {
  8. public class MeshToolbarFactory : UxmlFactory<MeshToolbar, MeshToolbarUxmlTraits> {}
  9. public class MeshToolbarUxmlTraits : UxmlTraits {}
  10. public event Action<Tools> SetMeshTool = (mode) => {};
  11. public SkinningCache skinningCache { get; set; }
  12. public MeshToolbar()
  13. {
  14. styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/MeshToolbarStyle.uss"));
  15. }
  16. public void BindElements()
  17. {
  18. var button = this.Q<Button>("SelectGeometry");
  19. button.clickable.clicked += () => { SetMeshTool(Tools.EditGeometry); };
  20. button = this.Q<Button>("CreateVertex");
  21. button.clickable.clicked += () => { SetMeshTool(Tools.CreateVertex); };
  22. button = this.Q<Button>("CreateEdge");
  23. button.clickable.clicked += () => { SetMeshTool(Tools.CreateEdge); };
  24. button = this.Q<Button>("SplitEdge");
  25. button.clickable.clicked += () => { SetMeshTool(Tools.SplitEdge); };
  26. button = this.Q<Button>("GenerateGeometry");
  27. button.clickable.clicked += () => { SetMeshTool(Tools.GenerateGeometry); };
  28. }
  29. public void UpdateToggleState()
  30. {
  31. //TODO: Make UI not be aware of BaseTool, Cache, etc. Use Tool enum
  32. var button = this.Q<Button>("SelectGeometry");
  33. SetButtonChecked(button, skinningCache.GetTool(Tools.EditGeometry).isActive);
  34. button = this.Q<Button>("CreateVertex");
  35. SetButtonChecked(button, skinningCache.GetTool(Tools.CreateVertex).isActive);
  36. button = this.Q<Button>("CreateEdge");
  37. SetButtonChecked(button, skinningCache.GetTool(Tools.CreateEdge).isActive);
  38. button = this.Q<Button>("SplitEdge");
  39. SetButtonChecked(button, skinningCache.GetTool(Tools.SplitEdge).isActive);
  40. button = this.Q<Button>("GenerateGeometry");
  41. SetButtonChecked(button, skinningCache.GetTool(Tools.GenerateGeometry).isActive);
  42. }
  43. public static MeshToolbar GenerateFromUXML()
  44. {
  45. var visualTree = ResourceLoader.Load<VisualTreeAsset>("SkinningModule/MeshToolbar.uxml");
  46. var clone = visualTree.CloneTree().Q<MeshToolbar>("MeshToolbar");
  47. clone.BindElements();
  48. return clone;
  49. }
  50. }
  51. }