예제 #1
0
        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)
        {
            List <IUxmlFactory> factoryList;

            if (!VisualElementFactoryRegistry.TryGetValue(fullTypeName, out factoryList))
            {
                Debug.LogErrorFormat("Element '{0}' has no registered factory method.", fullTypeName);
                return(new Label(string.Format("Unknown type: '{0}'", fullTypeName)));
            }

            IUxmlFactory factory = null;

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

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

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

            VisualElement res = factory.Create(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)));
            }

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

            return(res);
        }
        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);
        }