Keine Beschreibung
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

BoneInspectorPanel.cs 4.9KB

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