Beispiel #1
0
        internal static VisualElement Create(VisualElementAsset asset, CreationContext ctx)
        {
            List <IUxmlFactory> factoryList;

            if (!VisualElementFactoryRegistry.TryGetValue(asset.fullTypeName, out factoryList))
            {
                if (asset.fullTypeName.StartsWith("UnityEngine.Experimental.UIElements.") || asset.fullTypeName.StartsWith("UnityEditor.Experimental.UIElements."))
                {
                    string experimentalTypeName = asset.fullTypeName.Replace(".Experimental.UIElements", ".UIElements");
                    if (!VisualElementFactoryRegistry.TryGetValue(experimentalTypeName, out factoryList))
                    {
                        Debug.LogErrorFormat("Element '{0}' has no registered factory method.", asset.fullTypeName);
                        return(new Label(string.Format("Unknown type: '{0}'", asset.fullTypeName)));
                    }
                }
                else if (asset.fullTypeName == UxmlRootElementFactory.k_ElementName)
                {
                    // Support UXML without namespace for backward compatibility.
                    VisualElementFactoryRegistry.TryGetValue(typeof(UxmlRootElementFactory).Namespace + "." + asset.fullTypeName, out factoryList);
                }
                else
                {
                    Debug.LogErrorFormat("Element '{0}' has no registered factory method.", asset.fullTypeName);
                    return(new Label(string.Format("Unknown type: '{0}'", asset.fullTypeName)));
                }
            }

            IUxmlFactory factory = null;

            foreach (IUxmlFactory f in factoryList)
            {
                if (f.AcceptsAttributeBag(asset, ctx))
                {
                    factory = f;
                    break;
                }
            }

            if (factory == null)
            {
                Debug.LogErrorFormat("Element '{0}' has a no factory that accept the set of XML attributes specified.", asset.fullTypeName);
                return(new Label(string.Format("Type with no factory: '{0}'", asset.fullTypeName)));
            }

            VisualElement res = factory.Create(asset, ctx);

            if (res != null)
            {
                AssignClassListFromAssetToElement(asset, res);
                AssignStyleSheetFromAssetToElement(asset, res);
            }

            return(res);
        }
Beispiel #2
0
 private static void RegisterEngineFactories()
 {
     IUxmlFactory[] array = new IUxmlFactory[]
     {
         new UxmlRootElementFactory(),
         new UxmlTemplateFactory(),
         new UxmlStyleFactory(),
         new UxmlAttributeOverridesFactory(),
         new Button.UxmlFactory(),
         new VisualElement.UxmlFactory(),
         new IMGUIContainer.UxmlFactory(),
         new Image.UxmlFactory(),
         new Label.UxmlFactory(),
         new RepeatButton.UxmlFactory(),
         new ScrollView.UxmlFactory(),
         new Scroller.UxmlFactory(),
         new Slider.UxmlFactory(),
         new SliderInt.UxmlFactory(),
         new MinMaxSlider.UxmlFactory(),
         new Toggle.UxmlFactory(),
         new TextField.UxmlFactory(),
         new TemplateContainer.UxmlFactory(),
         new Box.UxmlFactory(),
         new HelpBox.UxmlFactory(),
         new PopupWindow.UxmlFactory(),
         new ListView.UxmlFactory(),
         new TwoPaneSplitView.UxmlFactory(),
         new TreeView.UxmlFactory(),
         new Foldout.UxmlFactory(),
         new BindableElement.UxmlFactory()
     };
     IUxmlFactory[] array2 = array;
     for (int i = 0; i < array2.Length; i++)
     {
         IUxmlFactory factory = array2[i];
         VisualElementFactoryRegistry.RegisterFactory(factory);
     }
 }
Beispiel #3
0
        internal static VisualElement Create(VisualElementAsset asset, CreationContext ctx)
        {
            List <IUxmlFactory> factoryList;

            if (!VisualElementFactoryRegistry.TryGetValue(asset.fullTypeName, out factoryList))
            {
                if (asset.fullTypeName.StartsWith("UnityEngine.Experimental.UIElements.") || asset.fullTypeName.StartsWith("UnityEditor.Experimental.UIElements."))
                {
                    string experimentalTypeName = asset.fullTypeName.Replace(".Experimental.UIElements", ".UIElements");
                    if (!VisualElementFactoryRegistry.TryGetValue(experimentalTypeName, out factoryList))
                    {
                        Debug.LogErrorFormat("Element '{0}' has no registered factory method.", asset.fullTypeName);
                        return(new Label(string.Format("Unknown type: '{0}'", asset.fullTypeName)));
                    }
                }
                else
                {
                    Debug.LogErrorFormat("Element '{0}' has no registered factory method.", asset.fullTypeName);
                    return(new Label(string.Format("Unknown type: '{0}'", asset.fullTypeName)));
                }
            }

            IUxmlFactory factory = null;

            foreach (IUxmlFactory f in factoryList)
            {
                if (f.AcceptsAttributeBag(asset, ctx))
                {
                    factory = f;
                    break;
                }
            }

            if (factory == null)
            {
                Debug.LogErrorFormat("Element '{0}' has a no factory that accept the set of XML attributes specified.", asset.fullTypeName);
                return(new Label(string.Format("Type with no factory: '{0}'", asset.fullTypeName)));
            }

            if (factory is UxmlRootElementFactory)
            {
                return(null);
            }

            VisualElement res = factory.Create(asset, ctx);

            if (res == null)
            {
                Debug.LogErrorFormat("The factory of Visual Element Type '{0}' has returned a null object", asset.fullTypeName);
                return(new Label(string.Format("The factory of Visual Element Type '{0}' has returned a null object", asset.fullTypeName)));
            }

            if (asset.classes != null)
            {
                for (int i = 0; i < asset.classes.Length; i++)
                {
                    res.AddToClassList(asset.classes[i]);
                }
            }

            if (asset.stylesheetPaths != null)
            {
                for (int i = 0; i < asset.stylesheetPaths.Count; i++)
                {
                    res.AddStyleSheetPath(asset.stylesheetPaths[i]);
                }
            }

            if (asset.stylesheets != null)
            {
                for (int i = 0; i < asset.stylesheets.Count; ++i)
                {
                    res.styleSheets.Add(asset.stylesheets[i]);
                }
            }

            return(res);
        }