예제 #1
0
        public TemplateContainer CloneTree()
        {
            var tc = new TemplateContainer(name);

            CloneTree(tc);
            return(tc);
        }
예제 #2
0
        public TemplateContainer Instantiate()
        {
            TemplateContainer target = new TemplateContainer(name);

            try
            {
                CloneTree(target, s_TemporarySlotInsertionPoints, null);
            }
            finally
            {
                s_TemporarySlotInsertionPoints.Clear();
            }

            return(target);
        }
예제 #3
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);
                TemplateContainer templateContainer = (TemplateContainer)ve;

                templateContainer.templateId = this.m_Template.GetValueFromBag(bag, cc);
                VisualTreeAsset expr_2D         = cc.visualTreeAsset;
                VisualTreeAsset visualTreeAsset = (expr_2D != null) ? expr_2D.ResolveTemplate(templateContainer.templateId) : null;
                bool            flag            = visualTreeAsset == null;

                if (flag)
                {
                    templateContainer.Add(new Label(string.Format("Unknown Template: '{0}'", templateContainer.templateId)));
                }
                else
                {
                    TemplateAsset expr_70 = bag as TemplateAsset;
                    List <TemplateAsset.AttributeOverride> list = (expr_70 != null) ? expr_70.attributeOverrides : null;
                    List <TemplateAsset.AttributeOverride> attributeOverrides = cc.attributeOverrides;
                    List <TemplateAsset.AttributeOverride> list2 = null;
                    bool flag2 = list != null || attributeOverrides != null;
                    if (flag2)
                    {
                        list2 = new List <TemplateAsset.AttributeOverride>();
                        bool flag3 = attributeOverrides != null;
                        if (flag3)
                        {
                            list2.AddRange(attributeOverrides);
                        }
                        bool flag4 = list != null;
                        if (flag4)
                        {
                            list2.AddRange(list);
                        }
                    }
                    visualTreeAsset.CloneTree(ve, cc.slotInsertionPoints, list2);
                }
                bool flag5 = visualTreeAsset == null;

                if (flag5)
                {
                    Debug.LogErrorFormat("Could not resolve template with name '{0}'", new object[]
                    {
                        templateContainer.templateId
                    });
                }
            }
예제 #4
0
            /// <summary>
            /// Initialize <see cref="TemplateContainer"/> properties using values from the attribute bag.
            /// </summary>
            /// <param name="ve">The object to initialize.</param>
            /// <param name="bag">The attribute bag.</param>
            /// <param name="cc">The creation context; unused.</param>
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                TemplateContainer templateContainer = ((TemplateContainer)ve);

                templateContainer.templateId = m_Template.GetValueFromBag(bag, cc);
                VisualTreeAsset vea = cc.visualTreeAsset?.ResolveTemplate(templateContainer.templateId);

                if (vea == null)
                {
                    templateContainer.Add(new Label(string.Format("Unknown Template: '{0}'", templateContainer.templateId)));
                }
                else
                {
                    var bagOverrides     = (bag as TemplateAsset)?.attributeOverrides;
                    var contextOverrides = cc.attributeOverrides;

                    List <TemplateAsset.AttributeOverride> attributeOverrides = null;
                    if (bagOverrides != null || contextOverrides != null)
                    {
                        // We want to add contextOverrides first here, then bagOverrides, as we
                        // want parent instances to always override child instances.
                        attributeOverrides = new List <TemplateAsset.AttributeOverride>();
                        if (contextOverrides != null)
                        {
                            attributeOverrides.AddRange(contextOverrides);
                        }
                        if (bagOverrides != null)
                        {
                            attributeOverrides.AddRange(bagOverrides);
                        }
                    }

                    vea.CloneTree(ve, cc.slotInsertionPoints, attributeOverrides);
                }

                if (vea == null)
                {
                    Debug.LogErrorFormat("Could not resolve template with name '{0}'", templateContainer.templateId);
                }
            }