public VisualElement Create(CreationContext ctx) { Func <IUxmlAttributes, CreationContext, VisualElement> func; VisualElement result; if (!Factories.TryGetValue(this.fullTypeName, out func)) { Debug.LogErrorFormat("Visual Element Type '{0}' has no factory method.", new object[] { this.fullTypeName }); result = new Label(string.Format("Unknown type: '{0}'", this.fullTypeName)); } else if (func == null) { Debug.LogErrorFormat("Visual Element Type '{0}' has a null factory method.", new object[] { this.fullTypeName }); result = new Label(string.Format("Type with no factory method: '{0}'", this.fullTypeName)); } else { VisualElement visualElement = func(this, ctx); if (visualElement == null) { Debug.LogErrorFormat("The factory of Visual Element Type '{0}' has returned a null object", new object[] { this.fullTypeName }); result = new Label(string.Format("The factory of Visual Element Type '{0}' has returned a null object", this.fullTypeName)); } else { visualElement.name = this.name; if (this.classes != null) { for (int i = 0; i < this.classes.Length; i++) { visualElement.AddToClassList(this.classes[i]); } } if (this.stylesheets != null) { for (int j = 0; j < this.stylesheets.Count; j++) { visualElement.AddStyleSheetPath(this.stylesheets[j]); } } BaseTextElement baseTextElement = visualElement as BaseTextElement; if (baseTextElement != null && !string.IsNullOrEmpty(this.text)) { baseTextElement.text = this.text; } visualElement.pickingMode = this.pickingMode; result = visualElement; } } return(result); }
public VisualElement Create(CreationContext ctx) { Func <IUxmlAttributes, CreationContext, VisualElement> factory; if (!Factories.TryGetValue(fullTypeName, out factory)) { Debug.LogErrorFormat("Visual Element Type '{0}' has no factory method.", fullTypeName); return(new Label(string.Format("Unknown type: '{0}'", fullTypeName))); } if (factory == null) { Debug.LogErrorFormat("Visual Element Type '{0}' has a null factory method.", fullTypeName); return(new Label(string.Format("Type with no factory method: '{0}'", fullTypeName))); } VisualElement res = factory(this, ctx); if (res == null) { Debug.LogErrorFormat("The factory of Visual Element Type '{0}' has returned a null object", fullTypeName); return(new Label(string.Format("The factory of Visual Element Type '{0}' has returned a null object", fullTypeName))); } res.name = name; if (classes != null) { for (int i = 0; i < classes.Length; i++) { res.AddToClassList(classes[i]); } } if (stylesheets != null) { for (int i = 0; i < stylesheets.Count; i++) { res.AddStyleSheetPath(stylesheets[i]); } } var textEle = res as BaseTextElement; if (textEle != null && !string.IsNullOrEmpty(text)) { textEle.text = text; } res.pickingMode = pickingMode; return(res); }