using System; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.U2D.Sprites.SpriteEditorTool { [UxmlElement] internal partial class SpriteOutlineToolOverlayPanel : VisualElement { static readonly string kGenerateSingle = L10n.Tr("Generate"); static readonly string kGenerateAll = L10n.Tr("Generate All"); static readonly string kForceGenerate = L10n.Tr("Force Generate All"); FloatField m_OutlineDetailField; IntegerField m_AlphaToleranceField; Slider m_OutlineDetailSlider; SliderInt m_AlphaToleranceSlider; Toggle m_SnapToggle; Toggle m_OptimizeOutline; Toggle m_ForceGenerate; Button m_GenerateButton; Button m_CopyButton; Button m_PasteButton; public event Action onGenerateOutline = _ => { }; public event Action onAlphaToleranceChanged = _ => { }; public event Action onOutlineDetailChanged = _ => { }; public event Action onCopy = () => { }; public event Action onPaste = () => { }; public event Action onPasteAll = () => { }; public event Action onPasteAlternate = () => { }; public event Action onPasteAlternateAll = () => { }; public bool snapOn { get { return m_SnapToggle.value; } set { m_SnapToggle.SetValueWithoutNotify(value); } } public float outlineDetail { get { return m_OutlineDetailField.value; } set { m_OutlineDetailField.SetValueWithoutNotify(value); m_OutlineDetailSlider.SetValueWithoutNotify(value); } } public int alphaTolerance { get { return m_AlphaToleranceField.value; } set { m_AlphaToleranceField.SetValueWithoutNotify(value); m_AlphaToleranceSlider.SetValueWithoutNotify(value); } } public bool optimizeOutline { get => m_OptimizeOutline.value; set => m_OptimizeOutline.SetValueWithoutNotify(value); } public SpriteOutlineToolOverlayPanel() { styleSheets.Add(AssetDatabase.LoadAssetAtPath("Packages/com.unity.2d.sprite/Editor/UI/SpriteEditor/SpriteOutlineToolOverlayPanelStyle.uss")); RegisterCallback((e) => { e.StopPropagation(); }); RegisterCallback((e) => { e.StopPropagation(); }); } public void SetPanelMode(bool hasSelection) { if (hasSelection) { m_GenerateButton.text = kGenerateSingle; m_CopyButton.SetEnabled(true); m_PasteButton.SetEnabled(true); m_ForceGenerate.SetEnabled(false); } else { UpdateGenerateAllButtonText(); m_CopyButton.SetEnabled(false); m_PasteButton.SetEnabled(false); m_ForceGenerate.SetEnabled(true); } } void UpdateGenerateAllButtonText() { m_GenerateButton.text = m_ForceGenerate.value ? kForceGenerate : kGenerateAll; } void GenerateOutline() { onGenerateOutline(m_ForceGenerate.value); } void OnCopy() { onCopy(); } void OnPaste() { onPaste(); } void OnPasteAll() { onPasteAll(); } void OnPasteAlternate() { onPasteAlternate(); } void OnPasteAlternateAll() { onPasteAlternateAll(); } void OnForceGenerateChanged(ChangeEvent _) { UpdateGenerateAllButtonText(); } private void BindElements(string alternateLabelText) { m_GenerateButton = this.Q