VFXTypeDefinition.cs 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using UnityEngine;
  6. using Object = UnityEngine.Object;
  7. namespace UnityEditor.VFX.UI
  8. {
  9. static class VFXTypeDefinition
  10. {
  11. public static readonly Type[] potentialTypes = new Type[]
  12. {
  13. typeof(bool),
  14. typeof(int),
  15. typeof(uint),
  16. typeof(float),
  17. typeof(Vector2),
  18. typeof(Vector3),
  19. typeof(Vector4),
  20. typeof(Color),
  21. typeof(Texture2D),
  22. typeof(Texture2DArray),
  23. typeof(Texture3D),
  24. typeof(Cubemap),
  25. typeof(CubemapArray),
  26. typeof(Mesh),
  27. typeof(Vector),
  28. typeof(Position),
  29. typeof(FlipBook),
  30. typeof(AnimationCurve),
  31. typeof(Object)
  32. };
  33. private static readonly string[] cssClasses = null;
  34. static VFXTypeDefinition()
  35. {
  36. cssClasses = new string[potentialTypes.Length + 1];
  37. for (int i = 0; i < potentialTypes.Length; ++i)
  38. {
  39. cssClasses[i] = "type" + potentialTypes[i].Name.ToLower();
  40. }
  41. cssClasses[potentialTypes.Length] = "typeStruct";
  42. }
  43. public static string GetTypeCSSClass(Type type)
  44. {
  45. if (type == null)
  46. {
  47. return "typeUnknown";
  48. }
  49. int index = MatchType(type);
  50. if (index >= 0)
  51. {
  52. return cssClasses[index];
  53. }
  54. return "";
  55. }
  56. public static string[] GetTypeCSSClasses()
  57. {
  58. return cssClasses;
  59. }
  60. static int MatchType(Type type)
  61. {
  62. for (int i = 0; i < potentialTypes.Length; ++i)
  63. {
  64. if (potentialTypes[i].IsAssignableFrom(type))
  65. return i;
  66. }
  67. if (type.IsValueType && !type.IsPrimitive && !type.IsEnum)
  68. {
  69. return potentialTypes.Length - 1;
  70. }
  71. return -1;
  72. }
  73. }
  74. }