using System; using System.Collections.Generic; using System.Text; using UnityEngine; using UnityEngine.UIElements; namespace UnityEditor.Rendering.Universal { internal class RenderPipelineConverterVisualElement : VisualElement { const string k_Uxml = "Packages/com.unity.render-pipelines.universal/Editor/Converter/converter_widget_main.uxml"; const string k_Uss = "Packages/com.unity.render-pipelines.universal/Editor/Converter/converter_widget_main.uss"; static Lazy s_VisualTreeAsset = new Lazy(() => AssetDatabase.LoadAssetAtPath(k_Uxml)); static Lazy s_StyleSheet = new Lazy(() => AssetDatabase.LoadAssetAtPath(k_Uss)); ConverterInfo m_ConverterInfo; // TODO: Once attributes land on all the converters use m_ConverterInfo; public string displayName => converter.name; public string description => converter.info; public ConverterState state => m_ConverterInfo.state; public RenderPipelineConverter converter => m_ConverterInfo.converter as RenderPipelineConverter; public bool isActiveAndEnabled => converter.isEnabled && state.isActive; public bool requiresInitialization => !state.isInitialized && isActiveAndEnabled; VisualElement m_RootVisualElement; Label m_PendingLabel; Label m_WarningLabel; Label m_ErrorLabel; Label m_SuccessLabel; public Action showMoreInfo; // TODO Remove with the UX rework public Action converterSelected; public RenderPipelineConverterVisualElement(ConverterInfo converterInfo) { m_ConverterInfo = converterInfo; m_RootVisualElement = new VisualElement(); s_VisualTreeAsset.Value.CloneTree(m_RootVisualElement); m_RootVisualElement.styleSheets.Add(s_StyleSheet.Value); var converterEnabledToggle = m_RootVisualElement.Q("converterEnabled"); converterEnabledToggle.SetValueWithoutNotify(state.isActive); converterEnabledToggle.RegisterCallback((evt) => { state.isActive = !state.isActive; converterSelected?.Invoke(); UpdateConversionInfo(); evt.StopPropagation(); // This toggle needs to stop propagation since it is inside another clickable element }); var topElement = m_RootVisualElement.Q("converterTopVisualElement"); topElement.RegisterCallback((evt) => { showMoreInfo?.Invoke(); }); topElement.RegisterCallback(evt => { // Show the tooltip around the toggle only var rect = converterEnabledToggle.worldBound; rect.position += new Vector2(150, -30); // offset it a bit to not be ove the toggle evt.rect = rect; // position area that triggers it evt.StopPropagation(); }); var allLabel = m_RootVisualElement.Q