Exemple #1
0
        internal static VisualElement Create(UIElementsSamples.SampleTreeItem item)
        {
            var panelContainer = new ScrollView();

            panelContainer.name = s_StylesExplorerName;
            panelContainer.AddToClassList(s_StylesExplorerClassName);

            var innerContainer = new VisualElement();

            panelContainer.Add(innerContainer);
            innerContainer.AddToClassList(s_ScrollViewContainerClassName);
            innerContainer.RegisterCallback <GeometryChangedEvent>(ContainerGeometryChange);
            ContainerSetColumnCount(innerContainer);

            var leftPanel  = CreatePanel();
            var rightPanel = CreatePanel();

            leftPanel.AddToClassList(s_StylePanelDarkClassName);
            rightPanel.AddToClassList(s_StylePanelLightClassName);

            leftPanel.AddStyleSheetPath(UIElementsEditorUtility.s_DefaultCommonDarkStyleSheetPath);
            rightPanel.AddStyleSheetPath(UIElementsEditorUtility.s_DefaultCommonLightStyleSheetPath);

            innerContainer.Add(leftPanel);
            innerContainer.Add(rightPanel);

            return(panelContainer);
        }
        internal static VisualElement Create(UIElementsSamples.SampleTreeItem item)
        {
            var snippet = new T() as ElementSnippet <T>;
            var tname   = typeof(T).Name;

            var container = new VisualElement();

            container.AddToClassList(s_DemoContainerClassName);

            var csTextAssetPath   = s_TextAssetsPath + "Code/" + tname + "_cs.asset";
            var ussTextAssetPath  = s_TextAssetsPath + "StyleSheets/" + tname + "_uss.asset";
            var uxmlTextAssetPath = s_TextAssetsPath + "UXML/" + tname + "_uxml.asset";

            var ussPath  = s_AssetsPath + "StyleSheets/" + tname + ".uss";
            var uxmlPath = s_AssetsPath + "UXML/" + tname + ".uxml";

            var csSnippet = CreateSnippetCode("C#", csTextAssetPath);

            var ussSnippet = CreateSnippetCode("USS", ussTextAssetPath);
            var styleSheet = EditorGUIUtility.Load(ussPath) as StyleSheet;

            container.styleSheets.Add(styleSheet);

            var uxmlSnippet = CreateSnippetCode("UXML", uxmlTextAssetPath);

            if (uxmlSnippet != null)
            {
                var visualTree = EditorGUIUtility.Load(uxmlPath) as VisualTreeAsset;
                visualTree.CloneTree(container);
            }

            snippet.Apply(container);

            var scrollView = new ScrollView();

            scrollView.AddToClassList(s_SnippetsContainer);
            scrollView.Add(csSnippet);
            scrollView.Add(ussSnippet);

            if (uxmlSnippet != null)
            {
                scrollView.Add(uxmlSnippet);
            }

            var panel = new VisualElement();

            panel.Add(container);
            panel.Add(scrollView);

            return(panel);
        }