void OnEnable() { // Construct and add navmesh m_NavMesh = new NavMeshData(); m_Instance = NavMesh.AddNavMeshData(m_NavMesh); if (m_Tracked == null) { m_Tracked = transform; } UpdateNavMesh(false); }
private void OnEnable() { NavMeshBuildSettings settingsByIndex = NavMesh.GetSettingsByIndex(this.NavMeshAgentTypeIndex); this.agentTypeId = ((NavMeshBuildSettings) ref settingsByIndex).get_agentTypeID(); this.NavMeshData = new NavMeshData(this.agentTypeId); this.sources = new List <NavMeshBuildSource>(); this.terrainBakes = new List <AsyncTerrainNavMeshBake>(); this.defaultArea = NavMesh.GetAreaFromName(this.DefaultAreaName); this.InvokeRepeating(new Action(this.FinishBuildingNavmesh), 0.0f, 1f); }
// Must be called before any NavMeshAgent components are instantiated public void Init() { // Create the NavMesh data that is used by the builder. This is a member // variable because if we ever want to update the NavMesh again later, we // need to pass the same data to the same builder. m_navMeshData = new NavMeshData(); NavMesh.AddNavMeshData(m_navMeshData); // Generate an initial, empty NavMesh. Required by NavMeshAgents that may // be present in the scene. UpdateNavMesh(false); }
public void PrepareNavmesh() { //prepare navmesh WG_TerrainBuilder builderComponent = builder.gameObject.GetComponent <WG_TerrainBuilder>(); NavMeshData data = builderComponent.GetNavmeshData(); if (data != null) { SaveNavmeshAsset(data); localNavMesh = data; } }
public AsyncOperation UpdateNavMesh(NavMeshData data) { var sources = CollectSources(); // Use unscaled bounds - this differs in behaviour from e.g. collider components. // But is similar to reflection probe - and since navmesh data has no scaling support - it is the right choice here. var sourcesBounds = new Bounds(m_Center, Abs(m_Size)); sourcesBounds = CalculateWorldBounds(sources); return(NavMeshBuilder.UpdateNavMeshDataAsync(data, GetBuildSettings(), sources, sourcesBounds)); }
//流砂時の移動 public void Default(GameObject enemy) { NavMesh.RemoveAllNavMeshData(); meshes = new List <MeshFilter>(); LoadMesh(stage); data = new NavMeshData(); NavMesh.AddNavMeshData(data); if (enemy != null) { enemy.SetActive(true); } }
private void Awake() { reflectEventsManager = FindObjectOfType <ReflectEventsManager>(); _navMeshData = new NavMeshData(); _NMDinstance = NavMesh.AddNavMeshData(_navMeshData); if (reflectEventsManager == null) { enabled = false; } }
private void Awake() { NavMeshDatas = new NavMeshData[Surfaces.Length]; for (int i = 0; i < Surfaces.Length; i++) { NavMeshDatas[i] = new NavMeshData(); NavMesh.AddNavMeshData(NavMeshDatas[i]); } BuildNavMesh(false); StartCoroutine(CheckPlayerMovement()); }
IEnumerator Start() { TheNavMeshData = new NavMeshData(); NavMesh.AddNavMeshData(TheNavMeshData); UpdateNavMesh(false); //Updates nav mesh asynchronously while (true) { UpdateNavMesh(true); yield return(Operation); } }
public void GeanerateNavMeshData() { List <NavMeshBuildSource> sourceList = new List <NavMeshBuildSource>(); List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>(); NavMeshBuilder.CollectSources(new Bounds(Vector3.zero, Vector3.one * 1000), 0 | (1 << 9), NavMeshCollectGeometry.RenderMeshes, 0, markups, sourceList); NavMeshBuildSettings nmbs = NavMesh.CreateSettings(); nmbs.agentTypeID = Spawner.nma[0].agentTypeID; NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(nmbs, sourceList, new Bounds(transform.position, Vector3.one * 1000), Vector3.zero, Quaternion.identity); currentNavMeshs.Add(NavMesh.AddNavMeshData(nmd)); }
void BakeNavMesh() { navMeshData = new NavMeshData(0); NavMeshSourceTag.Collect(ref sources); var defaultBuildSettings = NavMesh.GetSettingsByID(0); var bounds = new Bounds(center, size); NavMeshBuilder.UpdateNavMeshData(navMeshData, defaultBuildSettings, sources, bounds); navMeshInstance = NavMesh.AddNavMeshData(navMeshData); //NavMeshBuilder.BuildNavMeshData(defaultBuildSettings, sources, bounds, this.gameObject.transform.position, this.gameObject.transform.rotation); }
// Use this for initialization void Start() { zedSpatialMapping = GetComponent <ZEDSpatialMappingManager>(); #if UNITY_5_6_OR_NEWER navMesh = new NavMeshData(); NavMesh.AddNavMeshData(navMesh); //Initialize a position of the bound bounds = new Bounds(transform.position, new Vector3(30, 30, 30)); materialTransparent = Resources.Load("Materials/Mat_ZED_Transparent_NavMesh") as Material; #endif }
void SaveCombinedAsset() { // Create an asset describing all surfaces. var targetPath = GetAndEnsureTargetPath(this); var combinedAssetData = new List <NavMeshData>(); // Collect valid navmesh data. foreach (var s in NavMeshSurface.activeSurfaces) { if (s.bakedNavMeshData != null) { combinedAssetData.Add(s.bakedNavMeshData); } } // Clear the legacy navmesh data reference on the scene if (NavMeshEditorHelpers.CurrentNavMeshAssetFormat() == NavMeshEditorHelpers.NavMeshDataFormat.Single) { NavMeshBuilder.ClearAllNavMeshes(); } // Store baked navmesh data in one asset. var combinedAssetPath = Path.Combine(targetPath, "NavMesh.asset"); if (combinedAssetData.Count == 0) { AssetDatabase.DeleteAsset(combinedAssetPath); } else { if (!File.Exists(combinedAssetPath)) { // NOTE: Creates empty dummy NavMeshData to represent the main asset, // this is done in order to show all the built meshes equally in the list. var dummy = new NavMeshData(); AssetDatabase.CreateAsset(dummy, combinedAssetPath); } // Only add the data that has not been added already. // Call to NavMeshSurface.Clear () also deletes the data from the asset. foreach (var data in combinedAssetData) { if (!AssetDatabase.Contains(data)) { AssetDatabase.AddObjectToAsset(data, combinedAssetPath); } } AssetDatabase.SaveAssets(); AssetDatabase.ImportAsset(combinedAssetPath); } }
void OnEnable() { // Construct and add navmesh m_NavMesh = new NavMeshData(); m_Instance = NavMesh.AddNavMeshData(m_NavMesh); if (m_Tracked == null) { m_Tracked = transform; } UpdateNavMesh(false); // Notify player to check this navmesh MetaScript.getPlayer().SendMessage("AddResMesh", this); }
public void generateNavMesh() { //https://community.gamedev.tv/t/modify-navmesh-dynamically/25849/3 List <NavMeshBuildSource> buildSources = new List <NavMeshBuildSource>(); NavMeshBuilder.CollectSources(transform, navMeshLayers, NavMeshCollectGeometry.RenderMeshes, 0, new List <NavMeshBuildMarkup>(), buildSources); NavMeshData navData = NavMeshBuilder.BuildNavMeshData(navSettings, buildSources, new Bounds(Vector3.zero, new Vector3(10000, 10000, 10000)), Vector3.down, Quaternion.Euler(Vector3.up)); navMeshDataInstance = NavMesh.AddNavMeshData(navData); //Debug.Log(buildSources.Count); //Debug.Log("Map Built"); }
/// <summary> /// 初始化寻路数据 /// </summary> public void InitNavMesh() { navMeshSources = new Dictionary <Vector3Int, NavMeshBuildSource>(); navMeshData = new NavMeshData(); navMeshBuildSettings = NavMesh.GetSettingsByIndex(0); navMeshBuildSettings.agentClimb = 1.5f; navMeshBuildSettings.agentSlope = 60; navMeshBuildSettings.agentHeight = 1.8f; navMeshInstance = NavMesh.AddNavMeshData(navMeshData); worldBounds = new Bounds(); }
private void OnEnable() { navMeshData = new NavMeshData(); navMeshDataInstance = NavMesh.AddNavMeshData(navMeshData); // 場当たりだけど、メッシュがセットされていなければ開始時にナビメッシュを作成しない // テストと実際の使用時の違いの吸収 if (targetMeshes.Count > 0) { StartCoroutine(updateNavMesh()); } StartCoroutine(createNavMesh()); }
private void AddComponent(ISerializedFile file, Object comp) { if (comp.ClassID == ClassIDType.NavMeshSettings) { NavMeshSettings settings = (NavMeshSettings)comp; NavMeshData data = settings.NavMeshData.FindObject(file); if (data != null) { m_navMeshData = data; } } m_cexportIDs.Add(comp, comp.PathID.ToString()); }
private void OnEnable() { this._navMesh = new NavMeshData(); this._instance = NavMesh.AddNavMeshData(this._navMesh); if (Object.op_Equality((Object)this._tracked, (Object)null)) { this._tracked = ((Component)this).get_transform(); } if (this._enumerator == null) { this._enumerator = this.LoadNavMesh(); } this.StartCoroutine(this._enumerator); }
public IEnumerator GenerateNavMesh() { Reset(); navMeshData = new NavMeshData(); navMeshDataInstance = NavMesh.AddNavMeshData(navMeshData); navMeshTargets = navMeshTargetParent.GetComponentsInChildren <INavMeshTarget>().ToList(); foreach (var navMeshTarget in navMeshTargets) { navMeshTarget.UpdateNavMeshTargetData(); } return(UpdateNavMeshData()); }
void InitNavMesh() { if (!enableNavMesh) { return; } navMeshBuildSettings = NavMesh.GetSettingsByIndex(0); navMeshBuildSettings.agentClimb = 18f; navMeshBuildSettings.agentSlope = 80; navMeshBuildSettings.agentHeight = 18; navMeshBuildSettings.agentRadius = 8; navMeshSources = Misc.GetList <NavMeshBuildSource> (lowMemoryMode, 2048); navMeshData = new NavMeshData(); navMeshInstance = NavMesh.AddNavMeshData(navMeshData); worldBounds = new Bounds(); }
// Start is called before the first frame update void Start() { mg = GetComponent <MapGenerator>(); mg.Generate(); List <NavMeshBuildSource> sourceList = new List <NavMeshBuildSource>(); List <NavMeshBuildMarkup> markups = new List <NavMeshBuildMarkup>(); NavMeshBuilder.CollectSources(new Bounds(Vector3.zero, Vector3.one * 1000), 0 | (1 << 9), NavMeshCollectGeometry.RenderMeshes, 0, markups, sourceList); NavMeshData nmd = NavMeshBuilder.BuildNavMeshData(NavMesh.CreateSettings(), sourceList, new Bounds(transform.position, Vector3.one * 1000), Vector3.zero, Quaternion.identity); if (!nmd) { print("OH NO"); return; } NavMesh.AddNavMeshData(nmd); }
public static void BuildNavMesh(Transform root, Bounds bounds) { // Use the standard settings from the editor (I think) NavMeshBuildSettings settings = NavMesh.GetSettingsByID(0); // gather all the physics colliders which are children of this transform (or you can do this by volume) List <NavMeshBuildSource> results = new List <NavMeshBuildSource>(); NavMeshBuilder.CollectSources(root, 255, NavMeshCollectGeometry.RenderMeshes, 0, new List <NavMeshBuildMarkup>(), results); // Build the actual navmesh NavMeshData data = NavMeshBuilder.BuildNavMeshData(settings, results, bounds, Vector3.zero, Quaternion.identity); instances.Add(NavMesh.AddNavMeshData(data)); //success = NavMeshBuilder.UpdateNavMeshData(data, settings, results, bounds); }
void UpdateNavMesh() { bakePos = transform.position; Vector3 gravityUp = (transform.position - planet.position).normalized; dataInstance.Remove(); Bounds localBound = new Bounds(Vector3.zero, new Vector3(1, 1, 1) * boundSize);// new Bounds(transform.position, boundSize *new Vector3(1, 1, 1)); bound = new Bounds(transform.position, new Vector3(1, 1, 1) * boundSize); NavMeshData navMeshData = NavMeshBuilder.BuildNavMeshData(buildSettings , buildSources , localBound , transform.position , Quaternion.FromToRotation(Vector3.up, gravityUp)); dataInstance = NavMesh.AddNavMeshData(navMeshData); }
public IEnumerator UpdatingAndAddingNavMesh() { var navmeshData = new NavMeshData(); var oper = surface.UpdateNavMesh(navmeshData); Assert.IsFalse(HasNavMeshAtOrigin()); do { yield return(null); } while (!oper.isDone); surface.RemoveData(); surface.navMeshData = navmeshData; surface.AddData(); Assert.IsTrue(HasNavMeshAtOrigin()); }
// Use this for initialization void Start() { #if UNITY_5_6_OR_NEWER navMesh = new NavMeshData(); NavMesh.AddNavMeshData(navMesh); //Initialize a position for the bounds. bounds = new Bounds(transform.position, new Vector3(30, 30, 30)); materialTransparent = Resources.Load("Materials/Mat_ZED_Transparent_NavMesh") as Material; //The material applied to the display object. #endif if (zedManagerSpatialMapping) { zedManagerSpatialMapping.GetSpatialMapping.OnMeshReady += MeshIsOver; zedManagerSpatialMapping.GetSpatialMapping.OnMeshStarted += NewNavMesh; } }
void CalculateMesh(int width, Vector3 position) { var bounds = new Bounds(position * 15, new Vector3(width * 15, 0.1f, width * 15)); var markups = new List <NavMeshBuildMarkup>(); var sources = new List <NavMeshBuildSource>(); UnityEngine.AI.NavMeshBuilder.CollectSources(bounds, ~0, NavMeshCollectGeometry.PhysicsColliders, 0, markups, sources); var settings = NavMesh.GetSettingsByID(0); // var debug = new NavMeshBuildDebugSettings(); // debug.flags = NavMeshBuildDebugFlags.All; // settings.debug = debug; m_NavMeshData = new NavMeshData(); UnityEngine.AI.NavMeshBuilder.UpdateNavMeshData(m_NavMeshData, settings, sources, bounds); instance = NavMesh.AddNavMeshData(m_NavMeshData); }
private void UpdateNavMesh(bool asyync = false) { _navMesh = new NavMeshData( ); _navInstance = NavMesh.AddNavMeshData(_navMesh); var settings = NavMesh.GetSettingsByID(0); NavMeshSourceTag.Collect(ref _sources); var bounds = BoundsHelper.QauntizeBounds(_center, size, factor); if (asyync) { _operation = NavMeshBuilder.UpdateNavMeshDataAsync(_navMesh, settings, _sources, bounds); } else { NavMeshBuilder.UpdateNavMeshData(_navMesh, settings, _sources, bounds); } }
void OnValidate() { if (UnshareNavMeshAsset()) { Debug.LogWarning("Duplicating NavMeshSurface does not duplicate the referenced navmesh data", this); m_NavMeshData = null; } var settings = NavMesh.GetSettingsByID(m_AgentTypeID); if (settings.agentTypeID != -1) { // When unchecking the override control, revert to automatic value. const float kMinVoxelSize = 0.01f; if (!m_OverrideVoxelSize) { m_VoxelSize = settings.agentRadius / 3.0f; } if (m_VoxelSize < kMinVoxelSize) { m_VoxelSize = kMinVoxelSize; } // When unchecking the override control, revert to default value. const int kMinTileSize = 16; const int kMaxTileSize = 1024; const int kDefaultTileSize = 256; if (!m_OverrideTileSize) { m_TileSize = kDefaultTileSize; } // Make sure tilesize is in sane range. if (m_TileSize < kMinTileSize) { m_TileSize = kMinTileSize; } if (m_TileSize > kMaxTileSize) { m_TileSize = kMaxTileSize; } } }
void SaveNavmeshAsset(NavMeshData data) { #if UNITY_EDITOR string assetName = "navmesh_" + data.GetInstanceID().ToString(); string assetPath = "Assets" + assetNavmeshPath + assetName + ".asset"; if (AssetDatabase.Contains(data) && AssetDatabase.GetAssetPath(data) == assetPath) { AssetDatabase.SaveAssets(); } else { if (AssetDatabase.Contains(data)) { data = Instantiate(data); } AssetDatabase.CreateAsset(data, assetPath); } #endif }