PastePanel.cs 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using UnityEngine;
  3. using UnityEngine.UIElements;
  4. namespace UnityEditor.U2D.Animation
  5. {
  6. internal class PastePanel : VisualElement
  7. {
  8. public class PastePanelFactory : UxmlFactory<PastePanel, PastePanelUxmlTraits> {}
  9. public class PastePanelUxmlTraits : UxmlTraits {}
  10. public event Action<bool, bool, bool, bool> onPasteActivated = (bones, mesh, flipX, flipY) => {};
  11. private Toggle m_BonesToggle;
  12. private Toggle m_MeshToggle;
  13. private Toggle m_FlipXToggle;
  14. private Toggle m_FlipYToggle;
  15. public bool bones
  16. {
  17. get { return m_BonesToggle.value; }
  18. set { m_BonesToggle.value = value; }
  19. }
  20. public bool mesh
  21. {
  22. get { return m_MeshToggle.value; }
  23. set { m_MeshToggle.value = value; }
  24. }
  25. public bool flipX
  26. {
  27. get { return m_FlipXToggle.value; }
  28. set { m_FlipXToggle.value = value; }
  29. }
  30. public bool flipY
  31. {
  32. get { return m_FlipYToggle.value; }
  33. set { m_FlipYToggle.value = value; }
  34. }
  35. public PastePanel()
  36. {
  37. styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/PastePanelStyle.uss"));
  38. if (EditorGUIUtility.isProSkin)
  39. AddToClassList("Dark");
  40. RegisterCallback<MouseDownEvent>((e) => { e.StopPropagation(); });
  41. RegisterCallback<MouseUpEvent>((e) => { e.StopPropagation(); });
  42. }
  43. public void BindElements()
  44. {
  45. m_BonesToggle = this.Q<Toggle>("BonesField");
  46. m_MeshToggle = this.Q<Toggle>("MeshField");
  47. m_FlipXToggle = this.Q<Toggle>("FlipXField");
  48. m_FlipYToggle = this.Q<Toggle>("FlipYField");
  49. var pasteButton = this.Q<Button>("PasteButton");
  50. pasteButton.clickable.clicked += OnPasteActivated;
  51. }
  52. public void OnPasteActivated()
  53. {
  54. onPasteActivated(bones, mesh, flipX, flipY);
  55. }
  56. public static PastePanel GenerateFromUXML()
  57. {
  58. var visualTree = ResourceLoader.Load<VisualTreeAsset>("SkinningModule/PastePanel.uxml");
  59. var clone = visualTree.CloneTree().Q<PastePanel>("PastePanel");
  60. clone.BindElements();
  61. return clone;
  62. }
  63. }
  64. }