설명 없음
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

IncludeCollection.cs 4.2KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. using System;
  2. using System.Collections;
  3. using System.Collections.Generic;
  4. using UnityEngine;
  5. namespace UnityEditor.ShaderGraph
  6. {
  7. [GenerationAPI]
  8. [Serializable]
  9. internal class IncludeCollection : IEnumerable<IncludeDescriptor>
  10. {
  11. [SerializeField]
  12. List<IncludeDescriptor> includes;
  13. public IncludeCollection()
  14. {
  15. includes = new List<IncludeDescriptor>();
  16. }
  17. public IncludeCollection Add(IncludeCollection includes)
  18. {
  19. if (includes != null)
  20. {
  21. foreach (var include in includes)
  22. {
  23. AddInternal(include.guid, include.path, include.location, include.fieldConditions, include.shouldIncludeWithPragmas);
  24. }
  25. }
  26. return this;
  27. }
  28. public IncludeCollection Add(string includePath, IncludeLocation location)
  29. {
  30. var guid = AssetDatabase.AssetPathToGUID(includePath);
  31. return AddInternal(guid, includePath, location);
  32. }
  33. public IncludeCollection Add(string includePath, IncludeLocation location, bool shouldIncludeWithPragmas)
  34. {
  35. var guid = AssetDatabase.AssetPathToGUID(includePath);
  36. return AddInternal(guid, includePath, location, null, shouldIncludeWithPragmas);
  37. }
  38. public IncludeCollection Add(string includePath, IncludeLocation location, FieldCondition fieldCondition)
  39. {
  40. var guid = AssetDatabase.AssetPathToGUID(includePath);
  41. return AddInternal(guid, includePath, location, new FieldCondition[] { fieldCondition });
  42. }
  43. public IncludeCollection Add(string includePath, IncludeLocation location, FieldCondition fieldCondition, bool shouldIncludeWithPragmas)
  44. {
  45. var guid = AssetDatabase.AssetPathToGUID(includePath);
  46. return AddInternal(guid, includePath, location, new FieldCondition[] { fieldCondition }, shouldIncludeWithPragmas);
  47. }
  48. public IncludeCollection Add(string includePath, IncludeLocation location, FieldCondition[] fieldConditions)
  49. {
  50. var guid = AssetDatabase.AssetPathToGUID(includePath);
  51. return AddInternal(guid, includePath, location, fieldConditions);
  52. }
  53. public IncludeCollection Add(string includePath, IncludeLocation location, FieldCondition[] fieldConditions, bool shouldIncludeWithPragmas)
  54. {
  55. var guid = AssetDatabase.AssetPathToGUID(includePath);
  56. return AddInternal(guid, includePath, location, fieldConditions, shouldIncludeWithPragmas);
  57. }
  58. public IncludeCollection AddInternal(string includeGUID, string includePath, IncludeLocation location, FieldCondition[] fieldConditions = null, bool shouldIncludeWithPragmas = false)
  59. {
  60. if (string.IsNullOrEmpty(includeGUID))
  61. {
  62. // either the file doesn't exist, or this is a placeholder
  63. // de-duplicate by path
  64. int existing = includes.FindIndex(i => i.path == includePath);
  65. if (existing < 0)
  66. includes.Add(new IncludeDescriptor(null, includePath, location, fieldConditions, shouldIncludeWithPragmas));
  67. return this;
  68. }
  69. else
  70. {
  71. // de-duplicate by GUID
  72. int existing = includes.FindIndex(i => i.guid == includeGUID);
  73. if (existing < 0)
  74. {
  75. // no duplicates, just add it
  76. includes.Add(new IncludeDescriptor(includeGUID, includePath, location, fieldConditions, shouldIncludeWithPragmas));
  77. }
  78. else
  79. {
  80. // duplicate file -- we could double check they are the same...
  81. // they might have different field conditions that require merging, for example.
  82. // But for now we'll just assume they are the same and drop the new one
  83. }
  84. }
  85. return this;
  86. }
  87. public IEnumerator<IncludeDescriptor> GetEnumerator()
  88. {
  89. return includes.GetEnumerator();
  90. }
  91. IEnumerator IEnumerable.GetEnumerator()
  92. {
  93. return GetEnumerator();
  94. }
  95. }
  96. }