Нет описания
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

DefineCollection.cs 2.3KB

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