SpriteBoneInfluenceWindow.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. using System;
  2. using System.Collections.Generic;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.U2D.Animation
  6. {
  7. using PopupWindow = UnityEngine.UIElements.PopupWindow;
  8. internal interface ISpriteBoneInfluenceWindow
  9. {
  10. string headerText { get; set; }
  11. void SetHiddenFromLayout(bool hide);
  12. void OnSpriteSelectionChanged();
  13. void OnSkeletonChanged();
  14. void OnMeshChanged();
  15. bool visible { get; }
  16. void OnBoneSelectionChanged();
  17. event Action onAddBone;
  18. event Action onRemoveBone;
  19. event Action<IEnumerable<BoneCache>> onReordered;
  20. event Action<IEnumerable<BoneCache>> onSelectionChanged;
  21. void SetController(SpriteBoneInflueceToolController controller);
  22. }
  23. internal class SpriteBoneInfluenceWindow : VisualElement, ISpriteBoneInfluenceWindow
  24. {
  25. public class CustomUxmlFactory : UxmlFactory<SpriteBoneInfluenceWindow, UxmlTraits> {}
  26. private SpriteBoneInfluenceListWidget m_InfluencesList;
  27. private PopupWindow m_HeaderLabel;
  28. SpriteBoneInflueceToolController m_Controller;
  29. public event Action onAddBone = () => {};
  30. public event Action onRemoveBone = () => {};
  31. public event Action<IEnumerable<BoneCache>> onReordered = _ => {};
  32. public event Action<IEnumerable<BoneCache>> onSelectionChanged = _ => {};
  33. public string headerText
  34. {
  35. get { return m_HeaderLabel.text; }
  36. set { m_HeaderLabel.text = value; }
  37. }
  38. static internal SpriteBoneInfluenceWindow CreateFromUXML()
  39. {
  40. var visualTree = ResourceLoader.Load<VisualTreeAsset>("SkinningModule/SpriteBoneInfluenceWindow.uxml");
  41. var ve = visualTree.CloneTree().Q("SpriteBoneInfluenceWindow") as SpriteBoneInfluenceWindow;
  42. ve.BindElements();
  43. return ve;
  44. }
  45. internal void BindElements()
  46. {
  47. m_InfluencesList = this.Q<SpriteBoneInfluenceListWidget>();
  48. m_InfluencesList.onAddBone = () => onAddBone();
  49. m_InfluencesList.onRemoveBone = () => onRemoveBone();
  50. m_InfluencesList.onReordered = s => onReordered(s);
  51. m_InfluencesList.onSelectionChanged = (s) => onSelectionChanged(s);
  52. m_InfluencesList.GetController = InternalGetController;
  53. m_HeaderLabel = this.Q<PopupWindow>();
  54. this.styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/SpriteBoneInfluenceWindowStyle.uss"));
  55. }
  56. SpriteBoneInflueceToolController InternalGetController()
  57. {
  58. return m_Controller;
  59. }
  60. public void OnSpriteSelectionChanged()
  61. {
  62. Update();
  63. }
  64. public void OnMeshChanged()
  65. {
  66. Update();
  67. }
  68. public void OnSkeletonChanged()
  69. {
  70. m_InfluencesList.Update();
  71. }
  72. public void OnBoneSelectionChanged()
  73. {
  74. m_InfluencesList.OnBoneSelectionChanged();
  75. }
  76. private void Update()
  77. {
  78. m_InfluencesList.Update();
  79. m_InfluencesList.OnBoneSelectionChanged();
  80. }
  81. void ISpriteBoneInfluenceWindow.SetController(SpriteBoneInflueceToolController controller)
  82. {
  83. m_Controller = controller;
  84. }
  85. void ISpriteBoneInfluenceWindow.SetHiddenFromLayout(bool hide)
  86. {
  87. this.SetHiddenFromLayout(hide);
  88. }
  89. }
  90. }