예제 #1
0
 public VisualElement Create(IUxmlAttributes bag, CreationContext cc)
 {
     return(this.DoCreate(bag, cc));
 }
예제 #2
0
 protected abstract T DoCreate(IUxmlAttributes bag, CreationContext cc);
예제 #3
0
 private static VisualElement CreateToggle(IUxmlAttributes bag, CreationContext ctx)
 {
     return(new Toggle(null));
 }
예제 #4
0
 private static VisualElement CreateButton(IUxmlAttributes bag, CreationContext ctx)
 {
     return(new Button(null));
 }
예제 #5
0
 private static VisualElement CreateScrollerButton(IUxmlAttributes bag, CreationContext ctx)
 {
     return(new ScrollerButton(null, bag.GetPropertyLong("delay", 0L), bag.GetPropertyLong("interval", 0L)));
 }
예제 #6
0
 private static VisualElement CreateSlider(IUxmlAttributes bag, CreationContext ctx)
 {
     return(new Slider(bag.GetPropertyFloat("lowValue", 0f), bag.GetPropertyFloat("highValue", 0f), null, bag.GetPropertyEnum <Slider.Direction>("direction", Slider.Direction.Horizontal), 10f));
 }
예제 #7
0
 private static VisualElement CreateIMGUIContainer(IUxmlAttributes bag, CreationContext ctx)
 {
     return(new IMGUIContainer(null));
 }
        private VisualElement CloneSetupRecursively(VisualElementAsset root, Dictionary <int, List <VisualElementAsset> > idToChildren, CreationContext context)
        {
            VisualElement ve = root.Create(context);

            // context.target is the created templateContainer
            if (root.id == context.visualTreeAsset.contentContainerId)
            {
                if (context.target is TemplateContainer)
                {
                    ((TemplateContainer)context.target).SetContentContainer(ve);
                }
                else
                {
                    Debug.LogError("Trying to clone a VisualTreeAsset with a custom content container into a element which is not a template container");
                }
            }

            ve.name = root.name;

            // if the current element had a slot-name attribute, put it in the resulting slot mapping
            string slotName;

            if (context.slotInsertionPoints != null && TryGetSlotInsertionPoint(root.id, out slotName))
            {
                context.slotInsertionPoints.Add(slotName, ve);
            }

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

            if (root.ruleIndex != -1)
            {
                if (inlineSheet == null)
                {
                    Debug.LogWarning("VisualElementAsset has a RuleIndex but no inlineStyleSheet");
                }
                else
                {
                    StyleRule r          = inlineSheet.rules[root.ruleIndex];
                    var       stylesData = new VisualElementStylesData(false);
                    ve.SetInlineStyles(stylesData);
                    stylesData.ApplyRule(inlineSheet, Int32.MaxValue, r,
                                         StyleSheetCache.GetPropertyIDs(inlineSheet, root.ruleIndex));
                }
            }

            var templateAsset = root as TemplateAsset;
            List <VisualElementAsset> children;

            if (idToChildren.TryGetValue(root.id, out children))
            {
                foreach (VisualElementAsset childVea in children)
                {
                    // this will fill the slotInsertionPoints mapping
                    VisualElement childVe = CloneSetupRecursively(childVea, idToChildren, context);
                    if (childVe == null)
                    {
                        continue;
                    }

                    // if the parent is not a template asset, just add the child to whatever hierarchy we currently have
                    // if ve is a scrollView (with contentViewport as contentContainer), this will go to the right place
                    if (templateAsset == null)
                    {
                        ve.Add(childVe);
                        continue;
                    }

                    int index = templateAsset.slotUsages == null ? -1 : templateAsset.slotUsages.FindIndex(u => u.assetId == childVea.id);
                    if (index != -1)
                    {
                        VisualElement parentSlot;
                        string        key = templateAsset.slotUsages[index].slotName;
                        Assert.IsFalse(String.IsNullOrEmpty(key), "a lost name should not be null or empty, this probably points to an importer or serialization bug");
                        if (context.slotInsertionPoints == null || !context.slotInsertionPoints.TryGetValue(key, out parentSlot))
                        {
                            Debug.LogErrorFormat("Slot '{0}' was not found. Existing slots: {1}", key, context.slotInsertionPoints == null
                                ? String.Empty
                                : String.Join(", ", System.Linq.Enumerable.ToArray(context.slotInsertionPoints.Keys)));
                            ve.Add(childVe);
                        }
                        else
                        {
                            parentSlot.Add(childVe);
                        }
                    }
                    else
                    {
                        ve.Add(childVe);
                    }
                }
            }

            if (templateAsset != null && context.slotInsertionPoints != null)
            {
                context.slotInsertionPoints.Clear();
            }

            return(ve);
        }
예제 #9
0
            public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
            {
                base.Init(ve, bag, cc);

                ((ScrollerButton)ve).clickable = new Clickable(null, m_Delay.GetValueFromBag(bag), m_Interval.GetValueFromBag(bag));
            }
예제 #10
0
        private VisualElement CloneSetupRecursively(VisualElementAsset root, Dictionary <int, List <VisualElementAsset> > idToChildren, CreationContext context)
        {
            VisualElement visualElement = root.Create(context);

            if (root.id == context.visualTreeAsset.contentContainerId)
            {
                if (context.target is TemplateContainer)
                {
                    ((TemplateContainer)context.target).SetContentContainer(visualElement);
                }
                else
                {
                    Debug.LogError("Trying to clone a VisualTreeAsset with a custom content container into a element which is not a template container");
                }
            }
            visualElement.name = root.name;
            string key;

            if (context.slotInsertionPoints != null && this.TryGetSlotInsertionPoint(root.id, out key))
            {
                context.slotInsertionPoints.Add(key, visualElement);
            }
            if (root.classes != null)
            {
                for (int i = 0; i < root.classes.Length; i++)
                {
                    visualElement.AddToClassList(root.classes[i]);
                }
            }
            if (root.ruleIndex != -1)
            {
                if (this.inlineSheet == null)
                {
                    Debug.LogWarning("VisualElementAsset has a RuleIndex but no inlineStyleSheet");
                }
                else
                {
                    StyleRule rule = this.inlineSheet.rules[root.ruleIndex];
                    VisualElementStylesData visualElementStylesData = new VisualElementStylesData(false);
                    visualElement.SetInlineStyles(visualElementStylesData);
                    visualElementStylesData.ApplyRule(this.inlineSheet, int.MaxValue, rule, StyleSheetCache.GetPropertyIDs(this.inlineSheet, root.ruleIndex));
                }
            }
            TemplateAsset             templateAsset = root as TemplateAsset;
            List <VisualElementAsset> list;
            VisualElement             result;

            if (!idToChildren.TryGetValue(root.id, out list))
            {
                result = visualElement;
            }
            else
            {
                using (List <VisualElementAsset> .Enumerator enumerator = list.GetEnumerator())
                {
                    while (enumerator.MoveNext())
                    {
                        VisualElementAsset childVea       = enumerator.Current;
                        VisualElement      visualElement2 = this.CloneSetupRecursively(childVea, idToChildren, context);
                        if (visualElement2 != null)
                        {
                            if (templateAsset == null)
                            {
                                visualElement.Add(visualElement2);
                            }
                            else
                            {
                                int num = (templateAsset.slotUsages != null) ? templateAsset.slotUsages.FindIndex((VisualTreeAsset.SlotUsageEntry u) => u.assetId == childVea.id) : -1;
                                if (num != -1)
                                {
                                    string slotName = templateAsset.slotUsages[num].slotName;
                                    Assert.IsFalse(string.IsNullOrEmpty(slotName), "a lost name should not be null or empty, this probably points to an importer or serialization bug");
                                    VisualElement visualElement3;
                                    if (context.slotInsertionPoints == null || !context.slotInsertionPoints.TryGetValue(slotName, out visualElement3))
                                    {
                                        Debug.LogErrorFormat("Slot '{0}' was not found. Existing slots: {1}", new object[]
                                        {
                                            slotName,
                                            (context.slotInsertionPoints != null) ? string.Join(", ", context.slotInsertionPoints.Keys.ToArray <string>()) : string.Empty
                                        });
                                        visualElement.Add(visualElement2);
                                    }
                                    else
                                    {
                                        visualElement3.Add(visualElement2);
                                    }
                                }
                                else
                                {
                                    visualElement.Add(visualElement2);
                                }
                            }
                        }
                    }
                }
                if (templateAsset != null && context.slotInsertionPoints != null)
                {
                    context.slotInsertionPoints.Clear();
                }
                result = visualElement;
            }
            return(result);
        }
예제 #11
0
 public override void Init(VisualElement ve, IUxmlAttributes bag, CreationContext cc)
 {
     base.Init(ve, bag, cc);
     ((Toggle)ve).text = m_Label.GetValueFromBag(bag, cc);
     ((Toggle)ve).SetValueWithoutNotify(m_Value.GetValueFromBag(bag, cc));
 }