Boat Attack使用了Universal RP的许多新图形功能,可以用于探索 Universal RP 的使用方式和技巧。
您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

127 行
5.2 KiB

using NUnit.Framework;
using UnityEditor;
using UnityEditor.Rendering.Universal;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
using UnityEngine.TestTools;
class EditorTests
{
// When creating a new render pipeline asset it should not log any errors or throw exceptions.
[Test]
public void CreatePipelineAssetWithoutErrors()
{
// Test without any render pipeline assigned to GraphicsSettings.
var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
GraphicsSettings.renderPipelineAsset = null;
try
{
ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
LogAssert.NoUnexpectedReceived();
ScriptableObject.DestroyImmediate(asset);
ScriptableObject.DestroyImmediate(data);
}
// Makes sure the render pipeline is restored in case of a NullReference exception.
finally
{
GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
}
}
// When creating a new forward renderer asset it should not log any errors or throw exceptions.
[Test]
public void CreateForwardRendererAssetWithoutErrors()
{
// Test without any render pipeline assigned to GraphicsSettings.
var renderPipelineAsset = GraphicsSettings.renderPipelineAsset;
GraphicsSettings.renderPipelineAsset = null;
try
{
var asset = ScriptableObject.CreateInstance<ForwardRendererData>();
ResourceReloader.ReloadAllNullIn(asset, UniversalRenderPipelineAsset.packagePath);
LogAssert.NoUnexpectedReceived();
ScriptableObject.DestroyImmediate(asset);
}
// Makes sure the render pipeline is restored in case of a NullReference exception.
finally
{
GraphicsSettings.renderPipelineAsset = renderPipelineAsset;
}
}
// Validate that resources Guids are valid
[Test]
public void ValidateBuiltinResourceFiles()
{
string templatePath = AssetDatabase.GUIDToAssetPath(ResourceGuid.rendererTemplate);
Assert.IsFalse(string.IsNullOrEmpty(templatePath));
}
// When creating LWRP all required resources should be initialized.
[Test]
public void ValidateNewAssetResources()
{
ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
Assert.AreNotEqual(null, asset.defaultMaterial);
Assert.AreNotEqual(null, asset.defaultParticleMaterial);
Assert.AreNotEqual(null, asset.defaultLineMaterial);
Assert.AreNotEqual(null, asset.defaultTerrainMaterial);
Assert.AreNotEqual(null, asset.defaultShader);
// LWRP doesn't override the following materials
Assert.AreEqual(null, asset.defaultUIMaterial);
Assert.AreEqual(null, asset.defaultUIOverdrawMaterial);
Assert.AreEqual(null, asset.defaultUIETC1SupportedMaterial);
Assert.AreEqual(null, asset.default2DMaterial);
Assert.AreNotEqual(null, asset.m_EditorResourcesAsset, "Editor Resources should be initialized when creating a new pipeline.");
Assert.AreNotEqual(null, asset.m_RendererDataList, "A default renderer data should be created when creating a new pipeline.");
ScriptableObject.DestroyImmediate(asset);
ScriptableObject.DestroyImmediate(data);
}
// When changing LWRP settings, all settings should be valid.
[Test]
public void ValidateAssetSettings()
{
// Create a new asset and validate invalid settings
ForwardRendererData data = ScriptableObject.CreateInstance<ForwardRendererData>();
UniversalRenderPipelineAsset asset = UniversalRenderPipelineAsset.Create(data);
if (asset != null)
{
asset.shadowDistance = -1.0f;
Assert.GreaterOrEqual(asset.shadowDistance, 0.0f);
asset.renderScale = -1.0f;
Assert.GreaterOrEqual(asset.renderScale, UniversalRenderPipeline.minRenderScale);
asset.renderScale = 32.0f;
Assert.LessOrEqual(asset.renderScale, UniversalRenderPipeline.maxRenderScale);
asset.shadowNormalBias = -1.0f;
Assert.GreaterOrEqual(asset.shadowNormalBias, 0.0f);
asset.shadowNormalBias = 32.0f;
Assert.LessOrEqual(asset.shadowNormalBias, UniversalRenderPipeline.maxShadowBias);
asset.shadowDepthBias = -1.0f;
Assert.GreaterOrEqual(asset.shadowDepthBias, 0.0f);
asset.shadowDepthBias = 32.0f;
Assert.LessOrEqual(asset.shadowDepthBias, UniversalRenderPipeline.maxShadowBias);
asset.maxAdditionalLightsCount = -1;
Assert.GreaterOrEqual(asset.maxAdditionalLightsCount, 0);
asset.maxAdditionalLightsCount = 32;
Assert.LessOrEqual(asset.maxAdditionalLightsCount, UniversalRenderPipeline.maxPerObjectLights);
}
ScriptableObject.DestroyImmediate(asset);
ScriptableObject.DestroyImmediate(data);
}
}