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.8KB

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