EditorTests.cs 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. using NUnit.Framework;
  2. using UnityEditor;
  3. using UnityEngine;
  4. using UnityEngine.Rendering;
  5. using UnityEngine.Rendering.Universal;
  6. using UnityEditor.Rendering.Universal.Internal;
  7. using UnityEngine.TestTools;
  8. class EditorTests
  9. {
  10. // When creating a new render pipeline asset it should not log any errors or throw exceptions.
  11. [Test]
  12. public void CreatePipelineAssetWithoutErrors()
  13. {
  14. // Test without any render pipeline assigned to GraphicsSettings.
  15. var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
  16. GraphicsSettings.renderPipelineAsset = null;
  17. try
  18. {
  19. ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
  20. UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
  21. LogAssert.NoUnexpectedReceived();
  22. ScriptableObject.DestroyImmediate(asset);
  23. ScriptableObject.DestroyImmediate(data);
  24. }
  25. // Makes sure the render pipeline is restored in case of a NullReference exception.
  26. finally
  27. {
  28. GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
  29. }
  30. }
  31. // When creating a new forward renderer asset it should not log any errors or throw exceptions.
  32. [Test]
  33. public void CreateForwardRendererAssetWithoutErrors()
  34. {
  35. // Test without any render pipeline assigned to GraphicsSettings.
  36. var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
  37. GraphicsSettings.renderPipelineAsset = null;
  38. try
  39. {
  40. var asset = ScriptableObject.CreateInstance<ForwardRendererData>();
  41. ResourceReloader.ReloadAllNullIn(asset, UniversalRenderPipelineAsset.packagePath);
  42. LogAssert.NoUnexpectedReceived();
  43. ScriptableObject.DestroyImmediate(asset);
  44. }
  45. // Makes sure the render pipeline is restored in case of a NullReference exception.
  46. finally
  47. {
  48. GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
  49. }
  50. }
  51. // Validate that resources Guids are valid
  52. [Test]
  53. public void ValidateBuiltinResourceFiles()
  54. {
  55. string templatePath = AssetDatabase.GUIDToAssetPath(ResourceGuid.rendererTemplate);
  56. Assert.IsFalse(string.IsNullOrEmpty(templatePath));
  57. }
  58. // When creating LWRP all required resources should be initialized.
  59. [Test]
  60. public void ValidateNewAssetResources()
  61. {
  62. ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
  63. UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
  64. Assert.AreNotEqual(null, asset.defaultMaterial);
  65. Assert.AreNotEqual(null, asset.defaultParticleMaterial);
  66. Assert.AreNotEqual(null, asset.defaultLineMaterial);
  67. Assert.AreNotEqual(null, asset.defaultTerrainMaterial);
  68. Assert.AreNotEqual(null, asset.defaultShader);
  69. // LWRP doesn't override the following materials
  70. Assert.AreEqual(null, asset.defaultUIMaterial);
  71. Assert.AreEqual(null, asset.defaultUIOverdrawMaterial);
  72. Assert.AreEqual(null, asset.defaultUIETC1SupportedMaterial);
  73. Assert.AreEqual(null, asset.default2DMaterial);
  74. Assert.AreNotEqual(null, asset.m_EditorResourcesAsset, "Editor Resources should be initialized when creating a new pipeline.");
  75. Assert.AreNotEqual(null, asset.m_RendererDataList, "A default renderer data should be created when creating a new pipeline.");
  76. ScriptableObject.DestroyImmediate(asset);
  77. ScriptableObject.DestroyImmediate(data);
  78. }
  79. // When changing LWRP settings, all settings should be valid.
  80. [Test]
  81. public void ValidateAssetSettings()
  82. {
  83. // Create a new asset and validate invalid settings
  84. ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
  85. UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
  86. if (asset != null)
  87. {
  88. asset.shadowDistance = -1.0f;
  89. Assert.GreaterOrEqual(asset.shadowDistance, 0.0f);
  90. asset.renderScale = -1.0f;
  91. Assert.GreaterOrEqual(asset.renderScale, UniversalRenderPipeline.minRenderScale);
  92. asset.renderScale = 32.0f;
  93. Assert.LessOrEqual(asset.renderScale, UniversalRenderPipeline.maxRenderScale);
  94. asset.shadowNormalBias = -1.0f;
  95. Assert.GreaterOrEqual(asset.shadowNormalBias, 0.0f);
  96. asset.shadowNormalBias = 32.0f;
  97. Assert.LessOrEqual(asset.shadowNormalBias, UniversalRenderPipeline.maxShadowBias);
  98. asset.shadowDepthBias = -1.0f;
  99. Assert.GreaterOrEqual(asset.shadowDepthBias, 0.0f);
  100. asset.shadowDepthBias = 32.0f;
  101. Assert.LessOrEqual(asset.shadowDepthBias, UniversalRenderPipeline.maxShadowBias);
  102. asset.maxAdditionalLightsCount = -1;
  103. Assert.GreaterOrEqual(asset.maxAdditionalLightsCount, 0);
  104. asset.maxAdditionalLightsCount = 32;
  105. Assert.LessOrEqual(asset.maxAdditionalLightsCount, UniversalRenderPipeline.maxPerObjectLights);
  106. }
  107. ScriptableObject.DestroyImmediate(asset);
  108. ScriptableObject.DestroyImmediate(data);
  109. }
  110. }