A game about forced loneliness, made by TACStudios
1using System.Collections;
2using System.Collections.Generic;
3
4namespace UnityEditor.ShaderGraph
5{
6 [GenerationAPI]
7 internal class DefineCollection : IEnumerable<DefineCollection.Item>
8 {
9 public class Item : IConditional
10 {
11 public KeywordDescriptor descriptor { get; }
12 public FieldCondition[] fieldConditions { get; }
13 public string value => descriptor.ToDefineString(index);
14 // KeywordType.Boolean, index 0: disable, 1: enable
15 // KeywordType.Enum, index into enum entries
16 public int index { get; }
17
18 public Item(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
19 {
20 this.descriptor = descriptor;
21 this.fieldConditions = fieldConditions;
22 this.index = index;
23 }
24 }
25
26 readonly List<Item> m_Items;
27
28 public DefineCollection()
29 {
30 m_Items = new List<Item>();
31 }
32
33 public DefineCollection(DefineCollection defines)
34 {
35 m_Items = new List<Item>();
36
37 foreach (DefineCollection.Item item in defines)
38 {
39 m_Items.Add(item);
40 }
41 }
42
43 public DefineCollection Add(DefineCollection defines)
44 {
45 foreach (DefineCollection.Item item in defines)
46 {
47 m_Items.Add(item);
48 }
49
50 return this;
51 }
52
53 public DefineCollection Add(KeywordDescriptor descriptor, int index)
54 {
55 m_Items.Add(new Item(descriptor, index, null));
56 return this;
57 }
58
59 public DefineCollection Add(KeywordDescriptor descriptor, int index, FieldCondition fieldCondition)
60 {
61 m_Items.Add(new Item(descriptor, index, new FieldCondition[] { fieldCondition }));
62 return this;
63 }
64
65 public DefineCollection Add(KeywordDescriptor descriptor, int index, FieldCondition[] fieldConditions)
66 {
67 m_Items.Add(new Item(descriptor, index, fieldConditions));
68 return this;
69 }
70
71 public IEnumerator<Item> GetEnumerator()
72 {
73 return m_Items.GetEnumerator();
74 }
75
76 IEnumerator IEnumerable.GetEnumerator()
77 {
78 return GetEnumerator();
79 }
80 }
81}