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); }
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); }