-
Notifications
You must be signed in to change notification settings - Fork 866
Expand file tree
/
Copy pathDefineCollection.cs
More file actions
75 lines (62 loc) · 2.14 KB
/
DefineCollection.cs
File metadata and controls
75 lines (62 loc) · 2.14 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
using System.Collections;
using System.Collections.Generic;
namespace UnityEditor.ShaderGraph
{
[GenerationAPI]
internal class DefineCollection : IEnumerable<DefineCollection.Item>
{
public class Item : IConditional
{
public KeywordDescriptor descriptor { get; }
public FieldCondition[] fieldConditions { get; }
public string value => descriptor.ToDefineString(index);
// KeywordType.Boolean, index 0: disable, 1: enable
// KeywordType.Enum, index into enum entries
public int index { get; }
public Item(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
{
this.descriptor = descriptor;
this.fieldConditions = fieldConditions;
this.index = index;
}
}
readonly List<Item> m_Items;
public DefineCollection()
{
m_Items = new List<Item>();
}
public DefineCollection(DefineCollection defines)
{
m_Items = new List<Item>();
m_Items.AddRange(defines);
}
public DefineCollection Add(DefineCollection defines)
{
m_Items.AddRange(defines);
return this;
}
public DefineCollection Add(KeywordDescriptor descriptor, int index)
{
m_Items.Add(new Item(descriptor, index, null));
return this;
}
public DefineCollection Add(KeywordDescriptor descriptor, int index, FieldCondition fieldCondition)
{
m_Items.Add(new Item(descriptor, index, new FieldCondition[] { fieldCondition }));
return this;
}
public DefineCollection Add(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
{
m_Items.Add(new Item(descriptor, index, fieldConditions));
return this;
}
public IEnumerator<Item> GetEnumerator()
{
return m_Items.GetEnumerator();
}
IEnumerator IEnumerable.GetEnumerator()
{
return GetEnumerator();
}
}
}