No Description
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

BoneInspectorPanel.cs 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  1. using System;
  2. using UnityEditor.U2D.Common;
  3. using UnityEditor.UIElements;
  4. using UnityEngine;
  5. using UnityEngine.UIElements;
  6. namespace UnityEditor.U2D.Animation
  7. {
  8. internal class BoneInspectorPanel : VisualElement
  9. {
  10. [Flags]
  11. internal enum PropertyReadOnly
  12. {
  13. None,
  14. Name = 1,
  15. Depth = 1 << 2,
  16. Position = 1 << 3,
  17. Rotation = 1 << 4,
  18. Color = 1 << 5
  19. }
  20. public class BoneInspectorPanelFactory : UxmlFactory<BoneInspectorPanel, BoneInspectorPanelUxmlTraits> {}
  21. public class BoneInspectorPanelUxmlTraits : UxmlTraits {}
  22. public event Action<BoneCache, int> onBoneDepthChanged = (bone, depth) => {};
  23. public event Action<BoneCache, Vector2> onBonePositionChanged = (bone, position) => {};
  24. public event Action<BoneCache, float> onBoneRotationChanged = (bone, rotation) => {};
  25. public event Action<BoneCache, string> onBoneNameChanged = (bone, name) => {};
  26. public event Action<BoneCache, Color32> onBoneColorChanged = (bone, color) => {};
  27. private TextField m_BoneNameField;
  28. private IntegerField m_BoneDepthField;
  29. private FloatField m_BoneRotationField;
  30. private Vector2Field m_BonePositionField;
  31. private ColorField m_BoneColorField;
  32. public string boneName
  33. {
  34. get { return m_BoneNameField.value; }
  35. set { m_BoneNameField.value = value; }
  36. }
  37. public BoneCache target { get; set; }
  38. public int boneDepth
  39. {
  40. get { return m_BoneDepthField.value; }
  41. set { m_BoneDepthField.value = value; }
  42. }
  43. public Vector2 bonePosition
  44. {
  45. get { return m_BonePositionField.value; }
  46. set { m_BonePositionField.SetValueWithoutNotify(value);}
  47. }
  48. public float boneRotation
  49. {
  50. get { return m_BoneRotationField.value; }
  51. set { m_BoneRotationField.SetValueWithoutNotify(value);}
  52. }
  53. public Color32 boneColor
  54. {
  55. get => m_BoneColorField.value;
  56. set { m_BoneColorField.SetValueWithoutNotify(value);}
  57. }
  58. public BoneInspectorPanel()
  59. {
  60. styleSheets.Add(ResourceLoader.Load<StyleSheet>("SkinningModule/BoneInspectorPanelStyle.uss"));
  61. RegisterCallback<MouseDownEvent>((e) => { e.StopPropagation(); });
  62. RegisterCallback<MouseUpEvent>((e) => { e.StopPropagation(); });
  63. }
  64. public void BindElements()
  65. {
  66. m_BoneNameField = this.Q<TextField>("BoneNameField");
  67. m_BoneDepthField = this.Q<IntegerField>("BoneDepthField");
  68. m_BoneRotationField = this.Q<FloatField>("BoneRotationField");
  69. m_BonePositionField = this.Q<Vector2Field>("BonePositionField");
  70. m_BoneColorField = this.Q<ColorField>("BoneColorField");
  71. m_BoneNameField.RegisterCallback<FocusOutEvent>(BoneNameFocusChanged);
  72. m_BoneDepthField.RegisterCallback<FocusOutEvent>(BoneDepthFocusChanged);
  73. m_BoneRotationField.RegisterValueChangedCallback(evt => onBoneRotationChanged(target, evt.newValue));
  74. m_BonePositionField.RegisterValueChangedCallback(evt => onBonePositionChanged(target, evt.newValue));
  75. m_BoneColorField.RegisterValueChangedCallback(evt => onBoneColorChanged(target, evt.newValue));
  76. }
  77. private void BoneNameFocusChanged(FocusOutEvent evt)
  78. {
  79. onBoneNameChanged(target, boneName);
  80. }
  81. private void BoneDepthFocusChanged(FocusOutEvent evt)
  82. {
  83. onBoneDepthChanged(target, boneDepth);
  84. }
  85. public void HidePanel()
  86. {
  87. // We are hidding the panel, sent any unchanged value
  88. this.SetHiddenFromLayout(true);
  89. onBoneNameChanged(target, boneName);
  90. onBoneDepthChanged(target, boneDepth);
  91. }
  92. public static BoneInspectorPanel GenerateFromUXML()
  93. {
  94. var visualTree = ResourceLoader.Load<VisualTreeAsset>("SkinningModule/BoneInspectorPanel.uxml");
  95. var clone = visualTree.CloneTree().Q<BoneInspectorPanel>("BoneInspectorPanel");
  96. clone.LocalizeTextInChildren();
  97. clone.BindElements();
  98. return clone;
  99. }
  100. public void SetReadOnly(PropertyReadOnly property)
  101. {
  102. m_BoneDepthField.SetEnabled(!property.HasFlag(PropertyReadOnly.Depth));
  103. m_BoneNameField.SetEnabled(!property.HasFlag(PropertyReadOnly.Name));
  104. m_BonePositionField.SetEnabled(!property.HasFlag(PropertyReadOnly.Position));
  105. m_BoneRotationField.SetEnabled(!property.HasFlag(PropertyReadOnly.Rotation));
  106. m_BoneColorField.SetEnabled(!property.HasFlag(PropertyReadOnly.Color));
  107. }
  108. }
  109. }