您最多选择25个主题 主题必须以中文或者字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

90 行
3.6 KiB

using System;
using System.Collections.Generic;
using NUnit.Framework;
using UnityEditor;
using UnityEditor.Build.Reporting;
using UnityEditor.TestTools;
using UnityEngine;
using UnityEngine.TestTools;
namespace EditorTests.BuildTests
{
public class BuildPerceptionPlayer
{
List<EditorBuildSettingsScene> m_EditorBuildSettingsScenes = new List<EditorBuildSettingsScene>();
BuildSummary m_Summary;
string m_BuildPath = "Build/PerceptionBuild";
[SetUp]
public void SetUp()
{
TestsScenesPath();
}
[UnityPlatform(RuntimePlatform.WindowsEditor)]
[RequirePlatformSupport(BuildTarget.StandaloneWindows64)]
[Test]
public void BuildPlayerStandaloneWindows64()
{
BuildPlayer(BuildTargetGroup.Standalone, BuildTarget.StandaloneWindows64, m_BuildPath, BuildOptions.None, out _, out m_Summary);
Assert.AreEqual(BuildResult.Succeeded, m_Summary.result, " BuildTarget.StandaloneWindows64 failed to build");
}
[RequirePlatformSupport(BuildTarget.StandaloneLinux64)]
[Test]
public void BuildPlayerLinux()
{
BuildPlayer(BuildTargetGroup.Standalone, BuildTarget.StandaloneLinux64, m_BuildPath, BuildOptions.None, out _, out m_Summary);
Assert.AreEqual(BuildResult.Succeeded, m_Summary.result, "BuildTarget.StandaloneLinux64 failed to build");
}
[UnityPlatform(RuntimePlatform.OSXEditor)]
[RequirePlatformSupport(BuildTarget.StandaloneOSX)]
[Test]
public void BuildPlayerOSX()
{
BuildPlayer(BuildTargetGroup.Standalone, BuildTarget.StandaloneOSX, m_BuildPath, BuildOptions.None, out _, out m_Summary);
Assert.AreEqual(BuildResult.Succeeded, m_Summary.result, "BuildTarget.StandaloneLinux64 failed to build");
}
public void TestsScenesPath()
{
var allpaths = AssetDatabase.GetAllAssetPaths();
foreach (var targetPath in allpaths)
{
if (targetPath.Contains("com.unity.perception") &&
targetPath.Contains("Runtime") &&
targetPath.Contains("ScenarioTests") &&
targetPath.Contains("Scenes"))
{
if (targetPath.Contains("BaseScene.unity"))
{
Debug.Log("Scenes Path : " + targetPath);
m_EditorBuildSettingsScenes.Add(new EditorBuildSettingsScene(targetPath, true));
}
else if (targetPath.EndsWith(".unity"))
if (targetPath.EndsWith(".unity"))
{
Debug.Log("Scenes Path : " + targetPath);
m_EditorBuildSettingsScenes.Add(new EditorBuildSettingsScene(targetPath, true));
}
}
EditorBuildSettings.scenes = m_EditorBuildSettingsScenes.ToArray();
}
}
void BuildPlayer(BuildTargetGroup buildTargetGroup, BuildTarget buildTarget, string buildOutputPath, BuildOptions buildOptions,
out BuildReport buildReport, out BuildSummary buildSummary)
{
BuildPlayerOptions buildPlayerOptions = new BuildPlayerOptions();
buildPlayerOptions.locationPathName = buildOutputPath;
buildPlayerOptions.target = buildTarget;
buildPlayerOptions.options = buildOptions;
buildPlayerOptions.targetGroup = buildTargetGroup;
buildReport = BuildPipeline.BuildPlayer(buildPlayerOptions);
buildSummary = buildReport.summary;
}
}
}