CopyToolbar.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal class CopyToolbar : Toolbar
  7. {
  8. public class CopyToolbarFactory : UxmlFactory<CopyToolbar, CopyToolbarUxmlTraits> {}
  9. public class CopyToolbarUxmlTraits : UxmlTraits {}
  10. public event Action onDoCopy = () => {};
  11. public event Action onDoPaste = () => {};
  12. public CopyToolbar()
  13. {
  14. styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/CopyToolbarStyle.uss"));
  15. }
  16. public void DoCopy()
  17. {
  18. onDoCopy();
  19. }
  20. public void DoPaste()
  21. {
  22. onDoPaste();
  23. }
  24. public void BindElements()
  25. {
  26. var copyButton = this.Q<Button>("Copy");
  27. copyButton.clickable.clicked += DoCopy;
  28. var pasteButton = this.Q<Button>("Paste");
  29. pasteButton.clickable.clicked += DoPaste;
  30. }
  31. public static CopyToolbar GenerateFromUXML()
  32. {
  33. var visualTree = ResourceLoader.Load<VisualTreeAsset>("SkinningModule/CopyToolbar.uxml");
  34. var clone = visualTree.CloneTree().Q<CopyToolbar>("CopyToolbar");
  35. clone.BindElements();
  36. return clone;
  37. }
  38. }
  39. }