Brak opisu
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.

ReloadAttribute.cs 3.0KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. using System;
  2. namespace UnityEngine.Rendering
  3. {
  4. /// <summary>
  5. /// Attribute specifying information to reload with <see cref="ResourceReloader"/>. This is only
  6. /// used in the editor and doesn't have any effect at runtime.
  7. /// </summary>
  8. /// <seealso cref="ResourceReloader"/>
  9. /// <seealso cref="ReloadGroupAttribute"/>
  10. [AttributeUsage(AttributeTargets.Field)]
  11. public sealed class ReloadAttribute : Attribute
  12. {
  13. /// <summary>
  14. /// Lookup method for a resource.
  15. /// </summary>
  16. public enum Package
  17. {
  18. /// <summary>
  19. /// Used for builtin resources when the resource isn't part of the package (i.e. builtin
  20. /// shaders).
  21. /// </summary>
  22. Builtin,
  23. /// <summary>
  24. /// Used for resources inside the package.
  25. /// </summary>
  26. Root,
  27. /// <summary>
  28. /// Used for builtin extra resources when the resource isn't part of the package (i.e. builtin
  29. /// extra Sprite).
  30. /// </summary>
  31. BuiltinExtra,
  32. };
  33. #if UNITY_EDITOR
  34. /// <summary>
  35. /// The lookup method.
  36. /// </summary>
  37. public readonly Package package;
  38. /// <summary>
  39. /// Search paths.
  40. /// </summary>
  41. public readonly string[] paths;
  42. #endif
  43. /// <summary>
  44. /// Creates a new <see cref="ReloadAttribute"/> for an array by specifying each resource
  45. /// path individually.
  46. /// </summary>
  47. /// <param name="paths">Search paths</param>
  48. /// <param name="package">The lookup method</param>
  49. public ReloadAttribute(string[] paths, Package package = Package.Root)
  50. {
  51. #if UNITY_EDITOR
  52. this.paths = paths;
  53. this.package = package;
  54. #endif
  55. }
  56. /// <summary>
  57. /// Creates a new <see cref="ReloadAttribute"/> for a single resource.
  58. /// </summary>
  59. /// <param name="path">Search path</param>
  60. /// <param name="package">The lookup method</param>
  61. public ReloadAttribute(string path, Package package = Package.Root)
  62. : this(new[] { path }, package)
  63. { }
  64. /// <summary>
  65. /// Creates a new <see cref="ReloadAttribute"/> for an array using automatic path name
  66. /// numbering.
  67. /// </summary>
  68. /// <param name="pathFormat">The format used for the path</param>
  69. /// <param name="rangeMin">The array start index (inclusive)</param>
  70. /// <param name="rangeMax">The array end index (exclusive)</param>
  71. /// <param name="package">The lookup method</param>
  72. public ReloadAttribute(string pathFormat, int rangeMin, int rangeMax,
  73. Package package = Package.Root)
  74. {
  75. #if UNITY_EDITOR
  76. this.package = package;
  77. paths = new string[rangeMax - rangeMin];
  78. for (int index = rangeMin, i = 0; index < rangeMax; ++index, ++i)
  79. paths[i] = string.Format(pathFormat, index);
  80. #endif
  81. }
  82. }
  83. }