using System; using System.Collections; using System.Collections.Generic; using UnityEditor; using UnityEditor.UIElements; using UnityEngine; using UnityEngine.UIElements; [assembly: UxmlNamespacePrefix("UnityEditor.AddressableAssets.GUIElements", "AddressablesGUI")] namespace UnityEditor.AddressableAssets.GUIElements { internal class Ribbon : VisualElement { static class Content { // Technically Rbbon is a UI controll that could be more agnostic of this specific implementation for the Memory Profiler. // While this content may be reused in other places of the Memory Profiler and therefore makes sense to be located on TextContent, // keeping a Content class here makes it easier to keep things separated and helps when copying it out into other tools. public static readonly string OpenManualTooltip = GUIUtility.OpenManualTooltip; } static class Styles { public static readonly string HelpIconButtonClass = GUIUtility.HelpIconButtonClass; public static readonly string MenuIconButtonClass = GUIUtility.MenuIconButtonClass; } Align m_Alignment; public Align Alignment { get { return m_Alignment; } private set { switch (value) { case Align.Auto: case Align.FlexStart: m_Alignment = value; SetLeftAligned(); break; case Align.Center: m_Alignment = value; SetCenterAligned(); break; case Align.FlexEnd: case Align.Stretch: default: Debug.LogError("Ribbons can only be left of center aligned"); break; } } } public bool ShowHelpButton { get; private set; } public bool ShowMenuButton { get; private set; } public int InitialOption { get; private set; } public int m_CurrentOption = 0; public int CurrentOption { get { return m_CurrentOption; } set { m_CurrentOption = value; RefreshButtonToggleStates(); } } public override VisualElement contentContainer { get { return m_Content; } } public event Action Clicked = delegate { }; public event Action HelpClicked = delegate { }; public event Action MenuClicked = delegate { }; VisualElement m_Root; VisualElement m_Content; VisualElement m_Container; List m_Buttons = new List(); VisualElement m_OptionsAndInfos; Button m_Menu; Button m_Help; const string k_ContainerClassCenterAligned = "ribbon__container--centered"; const string k_ClassCenterAligned = "ribbon--centered"; const string k_ContainerClassLeftAligned = "ribbon__container--left-aligned"; const string k_ClassLeftAligned = "ribbon--left-aligned"; public Ribbon() { VisualTreeAsset ribbonViewTree = AssetDatabase.LoadAssetAtPath(GUIUtility.RibbonUxmlPath, typeof(VisualTreeAsset)) as VisualTreeAsset; m_Root = ribbonViewTree.Clone(); // clear out the style sheets defined in the template uxml file so they can be applied from here in the order of: 1. theming, 2. base m_Root.styleSheets.Clear(); var themeStyle = AssetDatabase.LoadAssetAtPath(EditorGUIUtility.isProSkin ? GUIUtility.RibbonDarkUssPath : GUIUtility.RibbonLightUssPath, typeof(StyleSheet)) as StyleSheet; m_Root.styleSheets.Add(themeStyle); var ribbonStyle = AssetDatabase.LoadAssetAtPath(GUIUtility.RibbonUssPath, typeof(StyleSheet)) as StyleSheet; m_Root.styleSheets.Add(ribbonStyle); hierarchy.Add(m_Root); style.flexShrink = 0; m_Container = m_Root.Q("ribbon__container"); m_Content = m_Root.Q("ribbon__buttons"); m_OptionsAndInfos = m_Root.Q("options-and-info"); m_Menu = m_OptionsAndInfos.Q