first commit
This commit is contained in:
@@ -0,0 +1,54 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using Utils = UnityEngine.TestTools.Utils.Utils;
|
||||
#pragma warning disable CS0618 // UnityEditor.AI.NavMeshBuilder is necessary in this implementation
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
class CurrentNextOffMeshLinkDataSetUp : PrebuiltSceneSetup
|
||||
{
|
||||
protected override string GetSceneFile()
|
||||
{
|
||||
return "OffMeshLinkTest.unity";
|
||||
}
|
||||
|
||||
protected override void SceneSetup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var myScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
|
||||
SceneManager.SetActiveScene(myScene);
|
||||
|
||||
var plane1 = Utils.CreatePrimitive(PrimitiveType.Plane);
|
||||
GameObjectUtility.SetStaticEditorFlags(plane1, StaticEditorFlags.NavigationStatic);
|
||||
plane1.name = "Plane1";
|
||||
plane1.transform.position = Vector3.zero;
|
||||
|
||||
var plane2 = Utils.CreatePrimitive(PrimitiveType.Plane);
|
||||
GameObjectUtility.SetStaticEditorFlags(plane2, StaticEditorFlags.NavigationStatic);
|
||||
plane2.name = "Plane2";
|
||||
plane2.transform.position = new Vector3(0, 0, 15);
|
||||
|
||||
var offMeshLink = plane1.AddComponent<NavMeshLink>();
|
||||
offMeshLink.startTransform = plane1.transform;
|
||||
offMeshLink.endTransform = plane2.transform;
|
||||
|
||||
var cube = Utils.CreatePrimitive(PrimitiveType.Cube);
|
||||
cube.transform.position = new Vector3(0, 0, -4);
|
||||
cube.name = "Agent";
|
||||
cube.AddComponent<NavMeshAgent>();
|
||||
|
||||
EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), pathToTestScene);
|
||||
UnityEditor.AI.NavMeshBuilder.BuildNavMesh();
|
||||
EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), pathToTestScene);
|
||||
|
||||
EditorSceneManager.CloseScene(myScene, true);
|
||||
UnityEditor.AI.NavMeshBuilder.ClearAllNavMeshes();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5a0a2560470c5b542813d7c93f1b3261
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,58 @@
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
#endif
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
abstract class PrebuiltSceneSetup : IPrebuildSetup, IPostBuildCleanup
|
||||
{
|
||||
const string k_RootDir = "Assets";
|
||||
const string k_TestDir = "TmpScenes";
|
||||
string testDirectory { get; set; } = "";
|
||||
protected string pathToTestScene { get; private set; } = "";
|
||||
|
||||
protected abstract string GetSceneFile();
|
||||
protected abstract void SceneSetup();
|
||||
|
||||
public void Setup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
testDirectory = Path.Combine(k_RootDir, k_TestDir);
|
||||
pathToTestScene = Path.Combine(testDirectory, GetSceneFile());
|
||||
|
||||
AssetDatabase.Refresh();
|
||||
if (!AssetDatabase.IsValidFolder(testDirectory))
|
||||
testDirectory = AssetDatabase.GUIDToAssetPath(AssetDatabase.CreateFolder(k_RootDir, k_TestDir));
|
||||
AssetDatabase.Refresh();
|
||||
|
||||
SceneSetup();
|
||||
|
||||
var editorBuildSettingsScenes = new List<EditorBuildSettingsScene>(EditorBuildSettings.scenes)
|
||||
{
|
||||
new EditorBuildSettingsScene(pathToTestScene, true)
|
||||
};
|
||||
EditorBuildSettings.scenes = editorBuildSettingsScenes.ToArray();
|
||||
#endif
|
||||
}
|
||||
|
||||
public void Cleanup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
AssetDatabase.Refresh();
|
||||
testDirectory = Path.Combine(k_RootDir, k_TestDir);
|
||||
pathToTestScene = Path.Combine(testDirectory, GetSceneFile());
|
||||
var baseSceneGuidTxt = AssetDatabase.AssetPathToGUID(pathToTestScene);
|
||||
|
||||
if (AssetDatabase.IsValidFolder(testDirectory))
|
||||
AssetDatabase.DeleteAsset(testDirectory);
|
||||
|
||||
if (GUID.TryParse(baseSceneGuidTxt, out var sceneGuid))
|
||||
EditorBuildSettings.scenes = EditorBuildSettings.scenes.Where(scene => scene.guid != sceneGuid).ToArray();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 57568e502950ef142a879100dfa67153
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,50 @@
|
||||
#if UNITY_EDITOR
|
||||
using UnityEditor;
|
||||
using UnityEditor.SceneManagement;
|
||||
#endif
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
#pragma warning disable CS0618 // UnityEditor.AI.NavMeshBuilder is necessary in this implementation
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
class SimpleScene2PlanesNavigationSetup : PrebuiltSceneSetup
|
||||
{
|
||||
protected override string GetSceneFile()
|
||||
{
|
||||
return "OffMeshLinkTwoPlanesScene.unity";
|
||||
}
|
||||
|
||||
protected override void SceneSetup()
|
||||
{
|
||||
#if UNITY_EDITOR
|
||||
var myScene = EditorSceneManager.NewScene(NewSceneSetup.EmptyScene, NewSceneMode.Additive);
|
||||
SceneManager.SetActiveScene(myScene);
|
||||
|
||||
var plane1 = Utils.CreatePrimitive(PrimitiveType.Plane);
|
||||
plane1.transform.position = new Vector3(10f, 0f, 0f);
|
||||
plane1.name = "plane1";
|
||||
GameObjectUtility.SetStaticEditorFlags(plane1, StaticEditorFlags.NavigationStatic);
|
||||
|
||||
var plane2 = Utils.CreatePrimitive(PrimitiveType.Plane);
|
||||
plane2.transform.position = new Vector3(25f, 0f, 0f);
|
||||
plane2.name = "plane2";
|
||||
GameObjectUtility.SetStaticEditorFlags(plane2, StaticEditorFlags.NavigationStatic);
|
||||
|
||||
var capsule = Utils.CreatePrimitive(PrimitiveType.Capsule);
|
||||
capsule.name = "Agent";
|
||||
capsule.transform.position = new Vector3(6, 0, 0);
|
||||
capsule.AddComponent<NavMeshAgent>();
|
||||
|
||||
EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), pathToTestScene);
|
||||
UnityEditor.AI.NavMeshBuilder.BuildNavMesh();
|
||||
EditorSceneManager.SaveScene(SceneManager.GetActiveScene(), pathToTestScene);
|
||||
|
||||
EditorSceneManager.CloseScene(myScene, true);
|
||||
UnityEditor.AI.NavMeshBuilder.ClearAllNavMeshes();
|
||||
#endif
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f5110d4284121dd4481bffe2647ad892
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user