first commit
This commit is contained in:
@@ -0,0 +1,46 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
[PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
class AddDynamicOffMeshLinkWorks : OffMeshLinkTestBase
|
||||
{
|
||||
const string k_SceneName = "OffMeshLinkTwoPlanesScene";
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator UnitySetUp()
|
||||
{
|
||||
yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return null;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[UnityPlatform(exclude = new[] { RuntimePlatform.OSXServer, RuntimePlatform.WindowsServer, RuntimePlatform.LinuxServer })] //MTT-4133 Fails on Dedicated Server
|
||||
public IEnumerator OffMeshLink_WhenAddedToGameObject_BecomesUsableImmediately()
|
||||
{
|
||||
CreateBiDirectionalLink(true);
|
||||
m_Agent.SetDestination(m_PlaneEnd.position);
|
||||
yield return null;
|
||||
|
||||
Assert.That(m_Agent.pathStatus, Is.EqualTo(NavMeshPathStatus.PathComplete), "DynamicOffMeshLink has not been created.");
|
||||
}
|
||||
|
||||
[UnityTearDown]
|
||||
public IEnumerator UnityTearDown()
|
||||
{
|
||||
yield return SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9f48814e34f5bd94eb57d5a64f7d6d5f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,61 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
using UnityEngine.TestTools.Utils;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
[PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
class AgentCustomLinkMovement : OffMeshLinkTestBase
|
||||
{
|
||||
const string k_SceneName = "OffMeshLinkTwoPlanesScene";
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator UnitySetUp()
|
||||
{
|
||||
yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return null;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[UnityPlatform(exclude = new[] { RuntimePlatform.OSXServer, RuntimePlatform.WindowsServer, RuntimePlatform.LinuxServer })] //MTT-4133 Fails on Dedicated Server
|
||||
public IEnumerator Agent_WithoutAutoTraverseOnOffMeshLink_DoesNotMoveByItself()
|
||||
{
|
||||
var link = CreateBiDirectionalLink(true);
|
||||
|
||||
m_Agent.autoTraverseOffMeshLink = false;
|
||||
m_Agent.baseOffset = 1.0f;
|
||||
m_Agent.transform.position = link.startTransform.position;
|
||||
var hasDestination = m_Agent.SetDestination(link.endTransform.position);
|
||||
|
||||
Assert.That(hasDestination, Is.True, "NavMeshAgent destination has not been set.");
|
||||
yield return null;
|
||||
|
||||
Assert.That(m_Agent.isOnOffMeshLink, Is.True, "NavMeshAgent is currently not positioned on NavMeshLink.");
|
||||
|
||||
// Move to gap between the NavMeshes connected by the NavMeshLink
|
||||
var midAirPosition = new Vector3(17.71f, 3.92f, -6.66f);
|
||||
m_Agent.transform.position = midAirPosition;
|
||||
yield return null;
|
||||
|
||||
// Ensure the agent stays at this position - as 'autoTraverseOffMeshLink' is false
|
||||
Assert.That(m_Agent.transform.position, Is.EqualTo(midAirPosition).Using(new Vector3EqualityComparer(0.01f)), "NavMeshAgent should be at midAirPosition.");
|
||||
}
|
||||
|
||||
[UnityTearDown]
|
||||
public IEnumerator UnityTearDown()
|
||||
{
|
||||
yield return SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ca27eb55b0331d042a94fe7f8899234c
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,66 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[Category("RegressionTest")]
|
||||
[PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
[PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
class AgentVelocityTestAfterOffMeshLink : OffMeshLinkTestBase
|
||||
{
|
||||
readonly string k_SceneName = "OffMeshLinkTwoPlanesScene";
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator UnitySetUp()
|
||||
{
|
||||
yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return null;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[UnityPlatform(exclude = new[] { RuntimePlatform.OSXServer, RuntimePlatform.WindowsServer, RuntimePlatform.LinuxServer })]
|
||||
public IEnumerator Agent_AfterTraversingOffMeshLink_HasVelocityAlignedWithTheLink()
|
||||
{
|
||||
var link = CreateBiDirectionalLink(true);
|
||||
m_Agent.transform.position = link.startTransform.position + new Vector3(3, 0, 3);
|
||||
m_Agent.SetDestination(link.endTransform.position + new Vector3(-3, 0, 3));
|
||||
yield return null;
|
||||
|
||||
while (!m_Agent.isOnOffMeshLink)
|
||||
yield return null;
|
||||
|
||||
while (m_Agent.isOnOffMeshLink)
|
||||
yield return null;
|
||||
|
||||
yield return 0;
|
||||
|
||||
var agentMoveDir = m_Agent.velocity;
|
||||
agentMoveDir.y = 0;
|
||||
agentMoveDir = agentMoveDir.normalized;
|
||||
|
||||
var linkDir = link.endTransform.position - link.startTransform.position;
|
||||
linkDir.y = 0;
|
||||
linkDir = linkDir.normalized;
|
||||
|
||||
// Get the angle in degrees between the direction vectors.
|
||||
var angle = Vector3.Angle(linkDir, agentMoveDir);
|
||||
|
||||
Assert.That(angle, Is.LessThan(5.0f), "Agent Velocity is not aligned with the off-mesh link.");
|
||||
}
|
||||
|
||||
[UnityTearDown]
|
||||
public IEnumerator UnityTearDown()
|
||||
{
|
||||
yield return SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 5ebd8eb82fbc3924e92211a0c85dfa02
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,88 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(CurrentNextOffMeshLinkDataSetUp))]
|
||||
[PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(CurrentNextOffMeshLinkDataSetUp))]
|
||||
class CurrentNextOffMeshLinkData
|
||||
{
|
||||
const string k_SceneName = "OffMeshLinkTest";
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator UnitySetUp()
|
||||
{
|
||||
yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return null;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[Explicit("Unstable test")]
|
||||
public IEnumerator Agent_TraversingOffMeshLink_ReportsCorrectCurrentAndNextLink()
|
||||
{
|
||||
var agent = GameObject.Find("Agent").GetComponent<NavMeshAgent>();
|
||||
var offMeshLink = GameObject.Find("Plane1").GetComponent<NavMeshLink>();
|
||||
var target = GameObject.Find("Plane2").transform;
|
||||
|
||||
Assert.That(offMeshLink, Is.Not.Null, "Didn't find Off-mesh link");
|
||||
Assert.That(agent, Is.Not.Null, "Didn't find NavMeshAgent");
|
||||
|
||||
var destinationSet = agent.SetDestination(target.position);
|
||||
agent.speed *= 10;
|
||||
Assert.That(destinationSet, Is.True, "NavMeshAgent's destination position is not set");
|
||||
|
||||
// Wait for path calculation
|
||||
yield return null;
|
||||
|
||||
// Before link
|
||||
while (!agent.isOnOffMeshLink)
|
||||
{
|
||||
Assert.That(agent.currentOffMeshLinkData.valid, Is.False, "Before link : agent.currentOffMeshLinkData is valid");
|
||||
|
||||
AssertValidOffMeshLinkData(agent.nextOffMeshLinkData, offMeshLink);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// On link
|
||||
while (agent.isOnOffMeshLink)
|
||||
{
|
||||
Assert.That(agent.nextOffMeshLinkData.valid, Is.False, "On link : agent.nextOffMeshLinkData is valid");
|
||||
|
||||
AssertValidOffMeshLinkData(agent.currentOffMeshLinkData, offMeshLink);
|
||||
yield return null;
|
||||
}
|
||||
|
||||
// After link
|
||||
Assert.That(agent.currentOffMeshLinkData.valid, Is.False, "After link : agent.currentOffMeshLinkData is valid");
|
||||
Assert.That(agent.nextOffMeshLinkData.valid, Is.False, "After link : agent.nextOffMeshLinkData is valid");
|
||||
}
|
||||
|
||||
[UnityTearDown]
|
||||
public IEnumerator UnityTearDown()
|
||||
{
|
||||
yield return SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
}
|
||||
|
||||
static void AssertValidOffMeshLinkData(OffMeshLinkData offMeshLinkData, NavMeshLink offMeshLink)
|
||||
{
|
||||
// Double check to avoid spamming success in log-file (decreasing tests performance)
|
||||
Assert.That(offMeshLinkData.valid, Is.True, "OffMeshLinkData should be valid.");
|
||||
Assert.That(offMeshLinkData.activated, Is.True, "OffMeshLinkData should be activated.");
|
||||
Assert.That(offMeshLinkData.linkType, Is.EqualTo(OffMeshLinkType.LinkTypeManual), "OffMeshLinkData's linkType should be Manual.");
|
||||
Assert.That(offMeshLinkData.owner, Is.EqualTo(offMeshLink), "OffMeshLinkData should reference the NavMeshLink in the scene as the owner object.");
|
||||
#pragma warning disable CS0618
|
||||
Assert.That(offMeshLinkData.offMeshLink, Is.Null, "OffMeshLinkData should not reference any legacy OffMeshLink in the scene.");
|
||||
#pragma warning restore CS0618
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 940906a00341424438da6b0e6ef377de
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,77 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
[PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
class OffMeshLinkGetSetNavMeshArea : OffMeshLinkTestBase
|
||||
{
|
||||
int m_AreaMask;
|
||||
NavMeshLink m_Link;
|
||||
readonly string k_SceneName = "OffMeshLinkTwoPlanesScene";
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator UnitySetUp()
|
||||
{
|
||||
yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return null;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
}
|
||||
|
||||
[UnityTest]
|
||||
[UnityPlatform(exclude = new[] { RuntimePlatform.OSXServer, RuntimePlatform.WindowsServer, RuntimePlatform.LinuxServer })]
|
||||
public IEnumerator OffMeshLink_WithCustomArea_AllowsThroughOnlyPathsWithMatchingMasks()
|
||||
{
|
||||
m_Link = CreateBiDirectionalLink(true);
|
||||
yield return null;
|
||||
|
||||
var defaultArea = NavMesh.GetAreaFromName("Walkable");
|
||||
var jumpArea = NavMesh.GetAreaFromName("Jump");
|
||||
|
||||
Assume.That(m_Link.area, Is.EqualTo(defaultArea), "Unexpected NavMesh area for NavMeshLink");
|
||||
|
||||
// Check we can pass 'default' with 'default' mask
|
||||
m_AreaMask = 1 << defaultArea;
|
||||
VerifyAreaPassing(true);
|
||||
|
||||
// Change oml area to 'jump'
|
||||
m_Link.area = jumpArea;
|
||||
Assume.That(m_Link.area, Is.EqualTo(jumpArea), "Unexpected NavMesh area for NavMeshLink");
|
||||
|
||||
// Check we cannot pass 'jump' with 'default' mask
|
||||
VerifyAreaPassing(false);
|
||||
|
||||
// Check we can pass 'jump' with 'default' + 'jump' mask
|
||||
m_AreaMask |= 1 << jumpArea;
|
||||
VerifyAreaPassing(true);
|
||||
}
|
||||
|
||||
void VerifyAreaPassing(bool expectToPass)
|
||||
{
|
||||
var path = new NavMeshPath();
|
||||
NavMesh.CalculatePath(m_PlaneStart.position, m_PlaneEnd.position, m_AreaMask, path);
|
||||
if (expectToPass)
|
||||
Assert.That(path.status, Is.EqualTo(NavMeshPathStatus.PathComplete),
|
||||
"Expected complete path; with NavMesh area mask " + m_AreaMask + " when NavMeshLink area is " + m_Link.area);
|
||||
else
|
||||
Assert.That(path.status, Is.EqualTo(NavMeshPathStatus.PathPartial),
|
||||
"Expected partial path; with NavMesh area mask " + m_AreaMask + " when NavMeshLink area is " + m_Link.area);
|
||||
}
|
||||
|
||||
[UnityTearDown]
|
||||
public IEnumerator UnityTearDown()
|
||||
{
|
||||
yield return SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: a8e30eff1e26b3b428d7ae3ce3158107
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,85 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using System.Collections;
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
using UnityEngine.SceneManagement;
|
||||
using UnityEngine.TestTools;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
[TestFixture]
|
||||
[PrebuildSetup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
[PostBuildCleanup("Unity.AI.Navigation.Tests." + nameof(SimpleScene2PlanesNavigationSetup))]
|
||||
class OffMeshLinkMultipleAddComponent
|
||||
{
|
||||
const string k_SceneName = "OffMeshLinkTwoPlanesScene";
|
||||
GameObject m_LinkGO;
|
||||
|
||||
[UnitySetUp]
|
||||
public IEnumerator UnitySetUp()
|
||||
{
|
||||
yield return SceneManager.LoadSceneAsync(k_SceneName, LoadSceneMode.Additive);
|
||||
yield return null;
|
||||
|
||||
SceneManager.SetActiveScene(SceneManager.GetSceneByName(k_SceneName));
|
||||
m_LinkGO = new GameObject("OffMeshLinkMultipleAddComponent");
|
||||
}
|
||||
|
||||
[Test]
|
||||
[UnityPlatform(exclude = new[] { RuntimePlatform.OSXServer, RuntimePlatform.WindowsServer, RuntimePlatform.LinuxServer })]
|
||||
public void OffMeshLink_WhenMultipleAddedToGameObject_AreAllUsable()
|
||||
{
|
||||
var a = GameObject.Find("plane1").GetComponent<Transform>();
|
||||
var b = GameObject.Find("plane2").GetComponent<Transform>();
|
||||
|
||||
Assert.That(a, Is.Not.Null, "Plane1 is missing.");
|
||||
Assert.That(b, Is.Not.Null, "Plane2 is missing.");
|
||||
|
||||
var pathAB = new NavMeshPath();
|
||||
var pathBA = new NavMeshPath();
|
||||
|
||||
var foundAB = NavMesh.CalculatePath(a.position, b.position, -1, pathAB);
|
||||
var foundBA = NavMesh.CalculatePath(b.position, a.position, -1, pathBA);
|
||||
Assert.That(foundAB, Is.True, "Found unexpected path A->B.");
|
||||
Assert.That(foundBA, Is.True, "Found unexpected path B->A.");
|
||||
|
||||
// Create setup where one GO has two OffMeshLinks with 'Bi Directional' set to false
|
||||
AddOneWayLink(a, b);
|
||||
AddOneWayLink(b, a);
|
||||
|
||||
// Tests that path a->b and b->a are valid and have same end-points (mirrored).
|
||||
foundAB = NavMesh.CalculatePath(a.position, b.position, -1, pathAB);
|
||||
foundBA = NavMesh.CalculatePath(b.position, a.position, -1, pathBA);
|
||||
Assert.That(foundAB, Is.True, "No path from A->B");
|
||||
Assert.That(foundBA, Is.True, "No path from B->A");
|
||||
|
||||
var d1 = Vector3.Distance(pathAB.corners[0], pathBA.corners[pathBA.corners.Length - 1]);
|
||||
var d2 = Vector3.Distance(pathAB.corners[pathAB.corners.Length - 1], pathBA.corners[0]);
|
||||
|
||||
Assert.That(d1, Is.EqualTo(0.0f).Within(1e-5f), "Endpoint mismatch: A start -> B end.");
|
||||
Assert.That(d2, Is.EqualTo(0.0f).Within(1e-5f), "Endpoint mismatch: B start -> A end.");
|
||||
}
|
||||
|
||||
void AddOneWayLink(Transform start, Transform end)
|
||||
{
|
||||
var offMeshLink = m_LinkGO.AddComponent<NavMeshLink>();
|
||||
Assert.That(offMeshLink, Is.Not.Null, "Failed to create NavMeshLink.");
|
||||
offMeshLink.bidirectional = false;
|
||||
offMeshLink.startTransform = start;
|
||||
offMeshLink.endTransform = end;
|
||||
|
||||
// we modified the endpoint references above - now explicitly update positions.
|
||||
offMeshLink.UpdateLink();
|
||||
}
|
||||
|
||||
[UnityTearDown]
|
||||
public IEnumerator UnityTearDown()
|
||||
{
|
||||
Object.DestroyImmediate(m_LinkGO);
|
||||
yield return SceneManager.UnloadSceneAsync(k_SceneName);
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 9956f614ad36a614788c97144e44730f
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,41 @@
|
||||
#if UNITY_EDITOR || UNITY_STANDALONE
|
||||
|
||||
using NUnit.Framework;
|
||||
using UnityEngine;
|
||||
using UnityEngine.AI;
|
||||
|
||||
namespace Unity.AI.Navigation.Tests
|
||||
{
|
||||
class OffMeshLinkTestBase
|
||||
{
|
||||
protected Transform m_PlaneStart;
|
||||
protected Transform m_PlaneEnd;
|
||||
protected NavMeshAgent m_Agent;
|
||||
|
||||
public NavMeshLink CreateBiDirectionalLink(bool autoUpdatePositions)
|
||||
{
|
||||
var planeStartGO = GameObject.Find("plane1");
|
||||
Assert.That(planeStartGO, Is.Not.Null, "Didn't find gameobject plane1");
|
||||
m_PlaneStart = planeStartGO.transform;
|
||||
var planeEndGO = GameObject.Find("plane2");
|
||||
Assert.That(planeEndGO, Is.Not.Null, "Didn't find gameobject plane2");
|
||||
m_PlaneEnd = planeEndGO.transform;
|
||||
var agentGo = GameObject.Find("Agent");
|
||||
Assert.That(agentGo, Is.Not.Null, "Didn't find gameobject Agent");
|
||||
m_Agent = agentGo.GetComponent<NavMeshAgent>();
|
||||
Assert.That(m_Agent, Is.Not.Null, "Didn't find component NavMeshAgent in gameobject Agent");
|
||||
|
||||
m_Agent.speed *= 10.0f;
|
||||
m_Agent.acceleration *= 10.0f;
|
||||
|
||||
var linkGO = new GameObject("link");
|
||||
var link = linkGO.AddComponent<NavMeshLink>();
|
||||
Assert.That(link, Is.Not.Null, "Unable to add NavMeshLink component.");
|
||||
link.startTransform = m_PlaneStart;
|
||||
link.endTransform = m_PlaneEnd;
|
||||
link.autoUpdate = autoUpdatePositions;
|
||||
return link;
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6066975671f8b09468b3412d411861c5
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 028144d6018e97b4eabdb685c9fc01a0
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
@@ -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:
|
||||
@@ -0,0 +1,21 @@
|
||||
{
|
||||
"name": "Unity.AI.Navigation.LegacyOffMeshLink.Tests",
|
||||
"rootNamespace": "",
|
||||
"references": [
|
||||
"GUID:8c4dd21966739024fbd72155091d199e",
|
||||
"GUID:27619889b8ba8c24980f49ee34dbb44a"
|
||||
],
|
||||
"includePlatforms": [],
|
||||
"excludePlatforms": [],
|
||||
"allowUnsafeCode": false,
|
||||
"overrideReferences": true,
|
||||
"precompiledReferences": [
|
||||
"nunit.framework.dll"
|
||||
],
|
||||
"autoReferenced": false,
|
||||
"defineConstraints": [
|
||||
"UNITY_INCLUDE_TESTS"
|
||||
],
|
||||
"versionDefines": [],
|
||||
"noEngineReferences": false
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 68d7ff144262c9148888e665efa8692c
|
||||
AssemblyDefinitionImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user