using System; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.U2D.Animation { internal class BoneInspectorPanel : VisualElement { public class BoneInspectorPanelFactory : UxmlFactory {} public class BoneInspectorPanelUxmlTraits : UxmlTraits {} public event Action onBoneDepthChanged = (bone, depth) => {}; public event Action onBoneNameChanged = (bone, name) => {}; private TextField m_BoneNameField; private IntegerField m_BoneDepthField; public string boneName { get { return m_BoneNameField.value; } set { m_BoneNameField.value = value; } } public BoneCache target { get; set; } public int boneDepth { get { return m_BoneDepthField.value; } set { m_BoneDepthField.value = value; } } public BoneInspectorPanel() { styleSheets.Add(ResourceLoader.Load("SkinningModule/BoneInspectorPanelStyle.uss")); RegisterCallback((e) => { e.StopPropagation(); }); RegisterCallback((e) => { e.StopPropagation(); }); } public void BindElements() { m_BoneNameField = this.Q("BoneNameField"); m_BoneDepthField = this.Q("BoneDepthField"); m_BoneNameField.RegisterCallback(BoneNameFocusChanged); m_BoneDepthField.RegisterCallback(BoneDepthFocusChanged); } private void BoneNameFocusChanged(FocusOutEvent evt) { onBoneNameChanged(target, boneName); } private void BoneDepthFocusChanged(FocusOutEvent evt) { onBoneDepthChanged(target, boneDepth); } public void HidePanel() { // We are hidding the panel, sent any unchanged value this.SetHiddenFromLayout(true); onBoneNameChanged(target, boneName); onBoneDepthChanged(target, boneDepth); } public static BoneInspectorPanel GenerateFromUXML() { var visualTree = ResourceLoader.Load("SkinningModule/BoneInspectorPanel.uxml"); var clone = visualTree.CloneTree().Q("BoneInspectorPanel"); clone.BindElements(); return clone; } } }