private void DynamicNavigationMeshSystemOnNavigationMeshUpdated(object sender, EventArgs eventArgs) { NavigationMesh newNavigationMesh = dynamicNavigationMeshSystem.CurrentNavigationMesh; UpdateNavigationMesh(newNavigationMesh, dynamicNavigationMesh, null); dynamicNavigationMesh = newNavigationMesh; }
public static NavMeshTracker Create(GameObject owner, NavigationMesh mesh) { var output = owner.AddComponent <NavMeshTracker>(); output.mesh = mesh; return(output); }
public static IEnumerable <NavCellController> GetCellsInBounds(Bounds bounds, NavigationMesh mesh) { foreach (var element in NavMeshCell.GetCellsInBounds(mesh, bounds)) { yield return(element.controller); } }
void SetPathPoint() { Vector3 hitPos; Drawable hitDrawable; NavigationMesh navMesh = scene.GetComponent <NavigationMesh>(); if (Raycast(250.0f, out hitPos, out hitDrawable)) { Vector3 pathPos = navMesh.FindNearestPoint(hitPos, new Vector3(1.0f, 1.0f, 1.0f)); const int qualShift = 1; if (Input.GetQualifierDown(qualShift)) { // Teleport currentPath.Clear(); jackNode.LookAt(new Vector3(pathPos.X, jackNode.Position.Y, pathPos.Z), Vector3.UnitY, TransformSpace.World); jackNode.Position = (pathPos); } else { // Calculate path from Jack's current position to the end point endPos = pathPos; var result = navMesh.FindPath(jackNode.Position, endPos); currentPath = new List <Vector3>(result); } } }
void AddOrRemoveObject() { // Raycast and check if we hit a mushroom node. If yes, remove it, if no, create a new one Vector3 hitPos; Drawable hitDrawable; if (Raycast(250.0f, out hitPos, out hitDrawable)) { // The part of the navigation mesh we must update, which is the world bounding box of the associated // drawable component BoundingBox updateBox; Node hitNode = hitDrawable.Node; if (hitNode.Name == "Mushroom") { updateBox = hitDrawable.WorldBoundingBox; hitNode.Remove(); } else { Node newNode = CreateMushroom(hitPos); updateBox = newNode.GetComponent <StaticModel>().WorldBoundingBox; } // Rebuild part of the navigation mesh, then recalculate path if applicable NavigationMesh navMesh = scene.GetComponent <NavigationMesh>(); navMesh.Build(updateBox); if (currentPath.Count > 0) { navMesh.FindPath(currentPath, jackNode.Position, endPos); } } }
void SetPathPoint() { var input = GetSubsystem <Input>(); Vector3 hitPos; Drawable hitDrawable; NavigationMesh navMesh = scene.GetComponent <NavigationMesh>(); if (Raycast(250.0f, out hitPos, out hitDrawable)) { Vector3 pathPos = navMesh.FindNearestPoint(hitPos, new Vector3(1.0f, 1.0f, 1.0f)); if (input.GetQualifierDown(Constants.QUAL_SHIFT)) { // Teleport currentPath.Clear(); jackNode.LookAt(new Vector3(pathPos.X, jackNode.Position.Y, pathPos.Z), Vector3.UnitY, TransformSpace.TS_WORLD); jackNode.Position = (pathPos); } else { // Calculate path from Jack's current position to the end point endPos = pathPos; var result = navMesh.FindPath(currentPath, jackNode.Position, endPos); } } }
protected void generateNavigationMeshInstances(App.Navigation nav, Godot.Collections.Array nodes) { for (int i = 0; i < nodes.Count; i++) { if (nodes[i] is StaticBody staticBody) { var meshInstance = staticBody.GetNodeOrNull <MeshInstance>("MeshInstance"); if (meshInstance != null) { NavigationMesh navMesh = new NavigationMesh(); navMesh.CreateFromMesh(meshInstance.Mesh); nav.NavmeshAdd(navMesh, meshInstance.GetGlobalTransform()); var transform = meshInstance.Transform; var translation = meshInstance.Translation; var globalTransform = meshInstance.GlobalTransform; GD.Print("created navmesh for meshinstance"); } else { GD.Print("[navmesh] meshinstance skipped (no child named 'MeshInstance')"); } } else { GD.Print("[navmesh] meshinstance skipped (no staticbody)"); } } }
protected override void ReadDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (ele.TryPathTo("Unknown1", false, out subEle)) { Unknown1 = subEle.ToBytes(); } if (ele.TryPathTo("NavigationMesh", false, out subEle)) { NavigationMesh.ReadXML(subEle, master); } if (ele.TryPathTo("Location", false, out subEle)) { Location.ReadXML(subEle, master); } if (ele.TryPathTo("Grid/X", false, out subEle)) { GridX = subEle.ToInt16(); } if (ele.TryPathTo("Grid/Y", false, out subEle)) { GridY = subEle.ToInt16(); } if (ele.TryPathTo("Unknown2", false, out subEle)) { Unknown2 = subEle.ToBytes(); } }
public override void OnStart() { this.InitEntitySync(); /** * Prepare the Events and route them to the controllers */ Alt.OnClient <IPlayer, Dictionary <string, string> >("pedSyncer:client:firstSpawn", Events.OnFirstSpawn); Alt.OnClient <IPlayer, string>("pedSyncer:client:positions", Events.OnPositionUpdate); Alt.OnClient <IPlayer, ulong, string, string[]>("pedSyncer:client:task", Events.OnTaskUpdate); Alt.OnClient <IPlayer>("pedSyncer:client:ready", Events.OnPlayerConnect); AltEntitySync.OnEntityRemove += Events.OnEntityRemove; Console.WriteLine("Started"); /** * Load all files (navMeshes & StreetCrossing) */ NavigationMesh.getInstance(); StreetCrossingControl.getInstance(); //Start serverside ped movement calculation PedMovement.GetInstance(); //Create citizen vehicles PedVehicles.GetInstance().SpawnRandomCitizenVehicles(1000); //Create citizen peds who wanders - delete this line if you don't wanna have citizens Ped.CreateCitizenPeds(2000); //NodeJS Wrapper PedSyncerWrapper.RegisterWrapperFunctions(); }
private void ResetHoles(NavigationMesh navMesh, bool changesMade) { if (changesMade) { navMesh.ResetHoles(); } }
protected override Task <ResultStatus> DoCommandOverride(ICommandContext commandContext) { var intermediateDataId = ComputeAssetIntermediateDataId(); oldNavigationMesh = LoadIntermediateData(intermediateDataId); var navigationMeshBuilder = new NavigationMeshBuilder(oldNavigationMesh); navigationMeshBuilder.Logger = commandContext.Logger; foreach (var colliderData in staticColliderDatas) { navigationMeshBuilder.Add(colliderData); } var navigationSettings = gameSettingsAsset.GetOrCreate <NavigationSettings>(); var groupsLookup = navigationSettings.Groups.ToDictionary(x => x.Id, x => x); var groups = new List <NavigationMeshGroup>(); // Resolve groups foreach (var groupId in asset.SelectedGroups) { NavigationMeshGroup group; if (groupsLookup.TryGetValue(groupId, out group)) { groups.Add(group); } else { commandContext.Logger.Warning($"Group not defined in game settings {{{groupId}}}"); } } var result = navigationMeshBuilder.Build(asset.BuildSettings, groups, asset.IncludedCollisionGroups, boundingBoxes, CancellationToken.None); // Unload loaded collider shapes foreach (var pair in loadedColliderShapes) { contentManager.Unload(pair.Key); } foreach (var pair in loadedHeightfieldInitialDatas) { contentManager.Unload(pair.Key); } if (!result.Success) { return(Task.FromResult(ResultStatus.Failed)); } // Save complete navigation mesh + intermediate data to cache SaveIntermediateData(intermediateDataId, result.NavigationMesh); // Clear intermediate data and save to content database result.NavigationMesh.Cache = null; contentManager.Save(assetUrl, result.NavigationMesh); return(Task.FromResult(ResultStatus.Successful)); }
private void Awake() { mesh = gameObject.GetComponentInParent <NavigationMesh>(); if (mesh == null) { mesh = NavigationMesh.mainMesh; } }
public NavigationMeshInternal(NavigationMesh navigationMesh) { cellTileSize = navigationMesh.BuildSettings.TileSize * navigationMesh.BuildSettings.CellSize; Layers = new IntPtr[navigationMesh.NumLayers]; for (int i = 0; i < navigationMesh.NumLayers; i++) { Layers[i] = LoadLayer(navigationMesh.Layers[i]); } }
private void RemoveNavigationMesh(NavigationMesh navigationMesh) { if (debugVisuals.TryGetValue(navigationMesh, out NavigationMeshDebugVisual visual)) { visual.Dispose(); rootDebugEntity.RemoveChild(visual.DebugEntity); debugVisuals.Remove(navigationMesh); } }
public void Awake() { instance = this; polygons = new List<NavmeshPolygon>(); GameObject[] polygonGOs = GameObject.FindGameObjectsWithTag("NavmeshPolygon"); foreach (GameObject polygonGO in polygonGOs){ polygons.Add((NavmeshPolygon)polygonGO.GetComponent("NavmeshPolygon")); } enabled=false; }
protected override void WriteDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; ele.TryPathTo("NavigationMesh", true, out subEle); NavigationMesh.WriteXML(subEle, master); ele.TryPathTo("Unknown", true, out subEle); subEle.Value = Unknown.ToString(); }
private void Awake() { if (_instance != null && _instance != this) { Destroy(this.gameObject); } else { _instance = this; } }
/// <summary> /// Saves intermediate data used for building a navigation mesh /// </summary> /// <param name="objectId">The unique Id for this data in the object database</param> /// <param name="build">The build data to save</param> private void SaveIntermediateData(ObjectId objectId, NavigationMesh build) { var objectDatabase = ContentManager.FileProvider.ObjectDatabase; using (var stream = objectDatabase.OpenStream(objectId, VirtualFileMode.Create, VirtualFileAccess.Write)) { var writer = new BinarySerializationWriter(stream); writer.Serialize(ref build, ArchiveMode.Serialize); writer.Flush(); } }
public void Start() { mesh = gameObject.AddComponent <NavigationMesh>(); foreach (var collider in gameObject.GetComponentsInChildren <Collider>()) { AddTracker(collider.transform); } //colliders = gameObject.GetComponentsInChildren<Collider>(); }
void Start() { //CreateNavMesh(); navMesh = NavigationMesh.GetInstance; navAgent = new NavigationAgent(navMesh); navAgent.AgentSize = .3f; try { CreateAnimationController(); } catch (Exception e) { Console.WriteLine(e.Message); } }
public void WriteXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; ele.TryPathTo("Unknown", true, out subEle); subEle.Value = Unknown.ToHex(); ele.TryPathTo("NavigationMesh", true, out subEle); NavigationMesh.WriteXML(subEle, master); ele.TryPathTo("Triangle", true, out subEle); subEle.Value = Triangle.ToString(); }
public void WriteBinary(ESPWriter writer) { if (Unknown == null) { writer.Write(new byte[4]); } else { writer.Write(Unknown); } NavigationMesh.WriteBinary(writer); writer.Write(Triangle); }
public void ReadBinary(ESPReader reader) { try { Unknown = reader.ReadBytes(4); NavigationMesh.ReadBinary(reader); Triangle = reader.ReadUInt16(); } catch { return; } }
public void UpdateWalls() { for (int i = 0; i < WorldMesh.gridWidth; i++) { for (int j = 0; j < WorldMesh.gridHeight; j++) { if (WorldMesh.ReturnTile(i, j).myType == Tile.TileType.WALL) { NavigationMesh.SetOccupiedGrid(WorldMesh.ReturnTile(i, j)); } } } }
override public float Run() { if (newNavMesh) { SceneSettings sceneSettings = GameObject.FindWithTag(Tags.gameEngine).GetComponent <SceneSettings>(); NavigationMesh oldNavMesh = sceneSettings.navMesh; oldNavMesh.TurnOff(); newNavMesh.TurnOn(); sceneSettings.navMesh = newNavMesh; } return(0f); }
private void UnloadNavMesh(int navMeshInt) { NavigationMesh navMesh = Serializer.returnComponent <NavigationMesh> (navMeshInt); SceneSettings sceneSettings = GameObject.FindWithTag(Tags.gameEngine).GetComponent <SceneSettings>(); if (navMesh && navMesh.collider && sceneSettings) { NavigationMesh oldNavMesh = sceneSettings.navMesh; oldNavMesh.TurnOff(); navMesh.collider.GetComponent <NavigationMesh>().TurnOn(); sceneSettings.navMesh = navMesh; } }
private void AddNavigationMesh(NavigationMesh navigationMesh, NavigationMesh oldNavigationMesh, Scene targetScene) { var visual = CreateDebugVisual(navigationMesh, oldNavigationMesh); if (visual != null) { // Apply scene offset to debug visual visual.DebugEntity.Transform.Position = targetScene?.Offset ?? Vector3.Zero; visual.Scene = targetScene; debugVisuals.Add(navigationMesh, visual); rootDebugEntity.AddChild(visual.DebugEntity); } }
protected override void ReadDataXML(XElement ele, ElderScrollsPlugin master) { XElement subEle; if (ele.TryPathTo("NavigationMesh", false, out subEle)) { NavigationMesh.ReadXML(subEle, master); } if (ele.TryPathTo("Unknown", false, out subEle)) { Unknown = subEle.ToUInt32(); } }
public override void doInitialize() { base.doInitialize(); try { m_navMesh = m_manager.createMesh(m_MeshName); } catch (ResourceNotFoundException resEx) { } catch (ServiceNotFoundException serEx) { } }
protected override void ReadData(ESPReader reader) { using (MemoryStream stream = new MemoryStream(reader.ReadBytes(size))) using (ESPReader subReader = new ESPReader(stream, reader.Plugin)) { try { NavigationMesh.ReadBinary(subReader); Unknown = subReader.ReadUInt32(); } catch { return; } } }
public override void OnInspectorGUI() { NavigationMesh _target = (NavigationMesh)target; _target.disableRenderer = EditorGUILayout.ToggleLeft("Disable mesh renderer?", _target.disableRenderer); #if UNITY_5 _target.ignoreCollisions = EditorGUILayout.ToggleLeft("Ignore collisions?", _target.ignoreCollisions); #endif if (AdvGame.GetReferences() && AdvGame.GetReferences().settingsManager&& AdvGame.GetReferences().settingsManager.IsUnity2D()) { _target.moveAroundChars = EditorGUILayout.ToggleLeft("Attempt to move around characters when pathfinding?", _target.moveAroundChars); int numOptions = _target.polygonColliderHoles.Count; numOptions = EditorGUILayout.IntField("Number of holes:", _target.polygonColliderHoles.Count); if (numOptions < 0) { numOptions = 0; } if (numOptions < _target.polygonColliderHoles.Count) { _target.polygonColliderHoles.RemoveRange(numOptions, _target.polygonColliderHoles.Count - numOptions); } else if (numOptions > _target.polygonColliderHoles.Count) { if (numOptions > _target.polygonColliderHoles.Capacity) { _target.polygonColliderHoles.Capacity = numOptions; } for (int i = _target.polygonColliderHoles.Count; i < numOptions; i++) { _target.polygonColliderHoles.Add(null); } } for (int i = 0; i < _target.polygonColliderHoles.Count; i++) { _target.polygonColliderHoles [i] = (PolygonCollider2D)EditorGUILayout.ObjectField("Hole #" + i.ToString() + ":", _target.polygonColliderHoles [i], typeof(PolygonCollider2D), true); } } if (GUI.changed) { EditorUtility.SetDirty(_target); } }
private void UpdateNavigationMesh(NavigationMesh newNavigationMesh, NavigationMesh oldNavigationMesh, Scene targetScene) { if (oldNavigationMesh != null) { RemoveNavigationMesh(oldNavigationMesh); } if (newNavigationMesh != null) { AddNavigationMesh(newNavigationMesh, oldNavigationMesh, targetScene); } foreach (var group in groupDisplaySettings.Values) { group.ResetHighlighting(); } }
public NavigationMesh createMesh(ModelMeshPart mesh) { NavigationMesh navMesh = new NavigationMesh(mesh); m_navigationMeshes.Add(navMesh); return navMesh; }