BoneInspectorPanel.cs 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using UnityEditor.UIElements;
  3. using UnityEngine;
  4. using UnityEngine.UIElements;
  5. namespace UnityEditor.U2D.Animation
  6. {
  7. internal class BoneInspectorPanel : VisualElement
  8. {
  9. public class BoneInspectorPanelFactory : UxmlFactory<BoneInspectorPanel, BoneInspectorPanelUxmlTraits> {}
  10. public class BoneInspectorPanelUxmlTraits : UxmlTraits {}
  11. public event Action<BoneCache, int> onBoneDepthChanged = (bone, depth) => {};
  12. public event Action<BoneCache, string> onBoneNameChanged = (bone, name) => {};
  13. private TextField m_BoneNameField;
  14. private IntegerField m_BoneDepthField;
  15. public string boneName
  16. {
  17. get { return m_BoneNameField.value; }
  18. set { m_BoneNameField.value = value; }
  19. }
  20. public BoneCache target { get; set; }
  21. public int boneDepth
  22. {
  23. get { return m_BoneDepthField.value; }
  24. set { m_BoneDepthField.value = value; }
  25. }
  26. public BoneInspectorPanel()
  27. {
  28. styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/BoneInspectorPanelStyle.uss"));
  29. RegisterCallback<MouseDownEvent>((e) => { e.StopPropagation(); });
  30. RegisterCallback<MouseUpEvent>((e) => { e.StopPropagation(); });
  31. }
  32. public void BindElements()
  33. {
  34. m_BoneNameField = this.Q<TextField>("BoneNameField");
  35. m_BoneDepthField = this.Q<IntegerField>("BoneDepthField");
  36. m_BoneNameField.RegisterCallback<FocusOutEvent>(BoneNameFocusChanged);
  37. m_BoneDepthField.RegisterCallback<FocusOutEvent>(BoneDepthFocusChanged);
  38. }
  39. private void BoneNameFocusChanged(FocusOutEvent evt)
  40. {
  41. onBoneNameChanged(target, boneName);
  42. }
  43. private void BoneDepthFocusChanged(FocusOutEvent evt)
  44. {
  45. onBoneDepthChanged(target, boneDepth);
  46. }
  47. public void HidePanel()
  48. {
  49. // We are hidding the panel, sent any unchanged value
  50. this.SetHiddenFromLayout(true);
  51. onBoneNameChanged(target, boneName);
  52. onBoneDepthChanged(target, boneDepth);
  53. }
  54. public static BoneInspectorPanel GenerateFromUXML()
  55. {
  56. var visualTree = ResourceLoader.Load<VisualTreeAsset>("SkinningModule/BoneInspectorPanel.uxml");
  57. var clone = visualTree.CloneTree().Q<BoneInspectorPanel>("BoneInspectorPanel");
  58. clone.BindElements();
  59. return clone;
  60. }
  61. }
  62. }