forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTemplateContainer.cs
More file actions
79 lines (64 loc) · 3.07 KB
/
TemplateContainer.cs
File metadata and controls
79 lines (64 loc) · 3.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using System;
using System.Collections.Generic;
namespace UnityEngine.UIElements
{
public class TemplateContainer : BindableElement
{
public new class UxmlFactory : UxmlFactory<TemplateContainer, UxmlTraits> {}
public new class UxmlTraits : BindableElement.UxmlTraits
{
UxmlStringAttributeDescription m_Template = new UxmlStringAttributeDescription { name = "template", use = UxmlAttributeDescription.Use.Required };
public override IEnumerable<UxmlChildElementDescription> uxmlChildElementsDescription
{
get { yield break; }
}
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 Element: '{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(templateContainer, cc.slotInsertionPoints, attributeOverrides);
}
if (vea == null)
Debug.LogErrorFormat("Could not resolve template with name '{0}'", templateContainer.templateId);
}
}
public string templateId { get; private set; }
private VisualElement m_ContentContainer;
public TemplateContainer() : this(null) {}
public TemplateContainer(string templateId)
{
this.templateId = templateId;
m_ContentContainer = this;
}
public override VisualElement contentContainer
{
get { return m_ContentContainer; }
}
internal void SetContentContainer(VisualElement content)
{
m_ContentContainer = content;
}
}
}