VFXTypeUtility.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using UnityEngine;
  5. namespace UnityEditor.VFX
  6. {
  7. static class VFXTypeUtility
  8. {
  9. public static int GetComponentCount(VFXSlot slot)
  10. {
  11. var slotType = slot.refSlot.property.type;
  12. if (slotType == typeof(float) || slotType == typeof(uint) || slotType == typeof(int))
  13. return 1;
  14. else if (slotType == typeof(Vector2))
  15. return 2;
  16. else if (slotType == typeof(Vector3))
  17. return 3;
  18. else if (slotType == typeof(Vector4) || slotType == typeof(Color))
  19. return 4;
  20. return 0;
  21. }
  22. public static int GetMaxComponentCount(IEnumerable<VFXSlot> slots)
  23. {
  24. int maxNbComponents = 0;
  25. foreach (var slot in slots)
  26. {
  27. int slotNbComponents = GetComponentCount(slot);
  28. maxNbComponents = Math.Max(slotNbComponents, maxNbComponents);
  29. }
  30. return maxNbComponents;
  31. }
  32. public static int GetComponentCountDirect(VFXSlot slot)
  33. {
  34. var slotType = slot.property.type;
  35. if (slotType == typeof(float) || slotType == typeof(uint) || slotType == typeof(int))
  36. return 1;
  37. else if (slotType == typeof(Vector2))
  38. return 2;
  39. else if (slotType == typeof(Vector3))
  40. return 3;
  41. else if (slotType == typeof(Vector4) || slotType == typeof(Color))
  42. return 4;
  43. return 0;
  44. }
  45. public static int GetMaxComponentCountDirect(IEnumerable<VFXSlot> slots)
  46. {
  47. int maxNbComponents = 0;
  48. foreach (var slot in slots)
  49. {
  50. int slotNbComponents = GetComponentCountDirect(slot);
  51. maxNbComponents = Math.Max(slotNbComponents, maxNbComponents);
  52. }
  53. return maxNbComponents;
  54. }
  55. public static Type GetFloatTypeFromComponentCount(int count)
  56. {
  57. switch (count)
  58. {
  59. case 1: return typeof(float);
  60. case 2: return typeof(Vector2);
  61. case 3: return typeof(Vector3);
  62. case 4: return typeof(Vector4);
  63. default: return null;
  64. }
  65. }
  66. }
  67. }