public void Remove() { NavMesh.RemoveLinkInternal(id); }
public void Remove() { NavMesh.RemoveNavMeshDataInternal(id); }
public static bool SamplePosition(Vector3 sourcePosition, out NavMeshHit hit, float maxDistance, int areaMask) { return(NavMesh.INTERNAL_CALL_SamplePosition(ref sourcePosition, out hit, maxDistance, areaMask)); }
public static NavMeshTriangulation CalculateTriangulation() { return((NavMeshTriangulation)NavMesh.TriangulateInternal()); }
public static bool FindClosestEdge(Vector3 sourcePosition, out NavMeshHit hit, int areaMask) { return(NavMesh.INTERNAL_CALL_FindClosestEdge(ref sourcePosition, out hit, areaMask)); }
internal static bool CalculatePathInternal(Vector3 sourcePosition, Vector3 targetPosition, int areaMask, NavMeshPath path) { return(NavMesh.INTERNAL_CALL_CalculatePathInternal(ref sourcePosition, ref targetPosition, areaMask, path)); }
public static bool CalculatePath(Vector3 sourcePosition, Vector3 targetPosition, int areaMask, NavMeshPath path) { path.ClearCorners(); return(NavMesh.CalculatePathInternal(sourcePosition, targetPosition, areaMask, path)); }
public static bool Raycast(Vector3 sourcePosition, Vector3 targetPosition, out NavMeshHit hit, int areaMask) { return(NavMesh.INTERNAL_CALL_Raycast(ref sourcePosition, ref targetPosition, out hit, areaMask)); }
List <NavMeshBuildSource> CollectSources() { var sources = new List <NavMeshBuildSource>(); var markups = new List <NavMeshBuildMarkup>(); List <NavMeshModifier> modifiers; if (m_CollectObjects == CollectObjects.Children) { modifiers = new List <NavMeshModifier>(GetComponentsInChildren <NavMeshModifier>()); modifiers.RemoveAll(x => !x.isActiveAndEnabled); } else { modifiers = NavMeshModifier.activeModifiers; } foreach (var m in modifiers) { if ((m_LayerMask & (1 << m.gameObject.layer)) == 0) { continue; } if (!m.AffectsAgentType(m_AgentTypeID)) { continue; } var markup = new NavMeshBuildMarkup(); markup.root = m.transform; markup.overrideArea = m.overrideArea; markup.area = m.area; markup.ignoreFromBuild = m.ignoreFromBuild; markups.Add(markup); } #if UNITY_EDITOR if (!EditorApplication.isPlaying) { if (m_CollectObjects == CollectObjects.All) { UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage( null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources); } else if (m_CollectObjects == CollectObjects.Children) { UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage( transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources); } else if (m_CollectObjects == CollectObjects.Volume) { Matrix4x4 localToWorld = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); var worldBounds = GetWorldBounds(localToWorld, new Bounds(m_Center, m_Size)); UnityEditor.AI.NavMeshBuilder.CollectSourcesInStage( worldBounds, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, gameObject.scene, sources); } } else #endif { if (m_CollectObjects == CollectObjects.All) { NavMeshBuilder.CollectSources(null, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources); } else if (m_CollectObjects == CollectObjects.Children) { NavMeshBuilder.CollectSources(transform, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources); } else if (m_CollectObjects == CollectObjects.Volume) { Matrix4x4 localToWorld = Matrix4x4.TRS(transform.position, transform.rotation, Vector3.one); var worldBounds = GetWorldBounds(localToWorld, new Bounds(m_Center, m_Size)); NavMeshBuilder.CollectSources(worldBounds, m_LayerMask, m_UseGeometry, m_DefaultArea, markups, sources); } } // --- --- --- Terrain trees --- --- --- Terrain terrain = Terrain.activeTerrain; TerrainData terrainData = terrain.terrainData; Vector3 size = Terrain.activeTerrain.terrainData.size; Vector3 terrainPos = terrain.GetPosition(); //Debug.Log("terrainPos = " + terrainPos); int treesArea = NavMesh.GetAreaFromName("Not Walkable"); if (treesArea < 0) { Debug.LogError("Unrecognized area name! The default area will be used instead."); treesArea = 0; } TreePrototype[] treePrototypes = terrainData.treePrototypes; TreeInstance[] treeInstances = terrainData.treeInstances; for (int i = 0; i < treeInstances.Length; i++) { //treeInstances[i] is the current ACTUAL tree we're going over. //the tree prototype is the "template" used by this tree. TreePrototype prototype = treePrototypes[treeInstances[i].prototypeIndex]; GameObject prefab = prototype.prefab; NavMeshObstacle obstacle = prefab.GetComponent <NavMeshObstacle>(); if (obstacle == null) { continue; } //Debug.Log("treeInstances[" + i + "] info:\n" + treeInstances[i].position + " " + treeInstances[i].rotation + " " + treeInstances[i].widthScale + " " + treeInstances[i].heightScale); Vector3 worldTreePos = terrainPos + Vector3.Scale(treeInstances[i].position, size) + obstacle.center; Quaternion worldTreeRot = Quaternion.Euler(0, treeInstances[i].rotation * Mathf.Rad2Deg, 0); Vector3 worldTreeScale = new Vector3(treeInstances[i].widthScale, treeInstances[i].heightScale, treeInstances[i].widthScale); //Debug.Log("CREATED MATRIX FOR TRS:\nworldTreePos = " + worldTreePos + "\nworldTreeRot = " + worldTreeRot + "\nworldTreeScale = " + worldTreeScale); NavMeshBuildSource src = new NavMeshBuildSource(); src.transform = Matrix4x4.TRS(worldTreePos, worldTreeRot, worldTreeScale); switch (obstacle.shape) { case NavMeshObstacleShape.Capsule: src.shape = NavMeshBuildSourceShape.Capsule; //Unity 2019.2.0f1: BUG!! navMeshObstacle.height returns exactly HALF of the actual height of the obstacle. //Use the size property instead. src.size = obstacle.size; break; case NavMeshObstacleShape.Box: src.shape = NavMeshBuildSourceShape.Box; src.size = obstacle.size; break; default: Debug.LogError("Unsupported type of " + typeof(NavMeshObstacleShape).Name + " for the building of the " + typeof(NavMeshSurface).Name + "! (" + obstacle.shape + ")"); break; } src.size = Vector3.Scale(src.size, prefab.transform.localScale); //Debug.Log("src.size = " + src.size); src.area = treesArea; sources.Add(src); } // --- --- --- End of Terrain trees --- --- --- if (m_IgnoreNavMeshAgent) { sources.RemoveAll((x) => (x.component != null && x.component.gameObject.GetComponent <NavMeshAgent>() != null)); } if (m_IgnoreNavMeshObstacle) { sources.RemoveAll((x) => (x.component != null && x.component.gameObject.GetComponent <NavMeshObstacle>() != null)); } AppendModifierVolumes(ref sources); return(sources); }