説明なし
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

VolumeStack.cs 3.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. using System;
  2. using System.Collections.Generic;
  3. namespace UnityEngine.Rendering
  4. {
  5. /// <summary>
  6. /// Holds the state of a Volume blending update. A global stack is
  7. /// available by default in <see cref="VolumeManager"/> but you can also create your own using
  8. /// <see cref="VolumeManager.CreateStack"/> if you need to update the manager with specific
  9. /// settings and store the results for later use.
  10. /// </summary>
  11. public sealed class VolumeStack : IDisposable
  12. {
  13. // Holds the state of _all_ component types you can possibly add on volumes
  14. internal readonly Dictionary<Type, VolumeComponent> components = new();
  15. // Flat list of every volume parameter for faster per-frame stack reset.
  16. internal VolumeParameter[] parameters;
  17. // Flag indicating that some properties have received overrides, therefore they must be reset in the next update.
  18. internal bool requiresReset = true;
  19. // Flag indicating that default state has changed, therefore all properties in the stack must be reset in the next update.
  20. internal bool requiresResetForAllProperties = true;
  21. internal VolumeStack()
  22. {
  23. }
  24. internal void Clear()
  25. {
  26. foreach (var component in components)
  27. CoreUtils.Destroy(component.Value);
  28. components.Clear();
  29. parameters = null;
  30. }
  31. internal void Reload(Type[] componentTypes)
  32. {
  33. Clear();
  34. requiresReset = true;
  35. requiresResetForAllProperties = true;
  36. List<VolumeParameter> parametersList = new();
  37. foreach (var type in componentTypes)
  38. {
  39. var component = (VolumeComponent)ScriptableObject.CreateInstance(type);
  40. components.Add(type, component);
  41. parametersList.AddRange(component.parameters);
  42. }
  43. parameters = parametersList.ToArray();
  44. isValid = true;
  45. }
  46. /// <summary>
  47. /// Gets the current state of the <see cref="VolumeComponent"/> of type <typeparamref name="T"/>
  48. /// in the stack.
  49. /// </summary>
  50. /// <typeparam name="T">A type of <see cref="VolumeComponent"/>.</typeparam>
  51. /// <returns>The current state of the <see cref="VolumeComponent"/> of type <typeparamref name="T"/>
  52. /// in the stack.</returns>
  53. public T GetComponent<T>()
  54. where T : VolumeComponent
  55. {
  56. var comp = GetComponent(typeof(T));
  57. return (T)comp;
  58. }
  59. /// <summary>
  60. /// Gets the current state of the <see cref="VolumeComponent"/> of the specified type in the
  61. /// stack.
  62. /// </summary>
  63. /// <param name="type">The type of <see cref="VolumeComponent"/> to look for.</param>
  64. /// <returns>The current state of the <see cref="VolumeComponent"/> of the specified type,
  65. /// or <c>null</c> if the type is invalid.</returns>
  66. public VolumeComponent GetComponent(Type type)
  67. {
  68. components.TryGetValue(type, out var comp);
  69. return comp;
  70. }
  71. /// <summary>
  72. /// Cleans up the content of this stack. Once a <c>VolumeStack</c> is disposed, it shouldn't
  73. /// be used anymore.
  74. /// </summary>
  75. public void Dispose()
  76. {
  77. Clear();
  78. isValid = false;
  79. }
  80. /// <summary>
  81. /// Check if the stack is in valid state and can be used.
  82. /// </summary>
  83. public bool isValid { get; private set; }
  84. }
  85. }