暫無描述
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.

IConditionalExtensions.cs 1.2KB

123456789101112131415161718192021222324252627282930313233343536
  1. using System.Linq;
  2. using UnityEditor.ShaderGraph.Internal;
  3. namespace UnityEditor.ShaderGraph
  4. {
  5. static class IConditionalExtensions
  6. {
  7. public static bool TestActive(this IConditional conditional, ActiveFields fields)
  8. {
  9. // Test FieldCondition against current active Fields
  10. bool TestFieldCondition(FieldCondition fieldCondition)
  11. {
  12. // Required active field is not active
  13. if (fieldCondition.condition == true && !fields.baseInstance.Contains(fieldCondition.field))
  14. return false;
  15. // Required non-active field is active
  16. else if (fieldCondition.condition == false && fields.baseInstance.Contains(fieldCondition.field))
  17. return false;
  18. return true;
  19. }
  20. // No FieldConditions
  21. if (conditional.fieldConditions == null)
  22. return true;
  23. // One or more FieldConditions failed
  24. if (conditional.fieldConditions.Where(x => !TestFieldCondition(x)).Any())
  25. return false;
  26. // All FieldConditions passed
  27. return true;
  28. }
  29. }
  30. }