示例#1
0
        private void DynamicNavigationMeshSystemOnNavigationMeshUpdated(object sender, EventArgs eventArgs)
        {
            NavigationMesh newNavigationMesh = dynamicNavigationMeshSystem.CurrentNavigationMesh;

            UpdateNavigationMesh(newNavigationMesh, dynamicNavigationMesh, null);
            dynamicNavigationMesh = newNavigationMesh;
        }
示例#2
0
    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);
     }
 }
示例#4
0
        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);
                }
            }
        }
示例#5
0
        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);
                }
            }
        }
示例#6
0
        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);
                }
            }
        }
示例#7
0
 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)");
         }
     }
 }
示例#8
0
        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();
            }
        }
示例#9
0
        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();
     }
 }
示例#11
0
            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;
     }
 }
示例#13
0
 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]);
     }
 }
示例#14
0
 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;
 }
示例#16
0
        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();
        }
示例#17
0
 private void Awake()
 {
     if (_instance != null && _instance != this)
     {
         Destroy(this.gameObject);
     }
     else
     {
         _instance = this;
     }
 }
示例#18
0
            /// <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>();
    }
示例#20
0
 void Start()
 {
     //CreateNavMesh();
     navMesh            = NavigationMesh.GetInstance;
     navAgent           = new NavigationAgent(navMesh);
     navAgent.AgentSize = .3f;
     try
     {
         CreateAnimationController();
     }
     catch (Exception e) { Console.WriteLine(e.Message); }
 }
示例#21
0
        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();
        }
示例#22
0
 public void WriteBinary(ESPWriter writer)
 {
     if (Unknown == null)
     {
         writer.Write(new byte[4]);
     }
     else
     {
         writer.Write(Unknown);
     }
     NavigationMesh.WriteBinary(writer);
     writer.Write(Triangle);
 }
示例#23
0
 public void ReadBinary(ESPReader reader)
 {
     try
     {
         Unknown = reader.ReadBytes(4);
         NavigationMesh.ReadBinary(reader);
         Triangle = reader.ReadUInt16();
     }
     catch
     {
         return;
     }
 }
示例#24
0
 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));
             }
         }
     }
 }
示例#25
0
    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);
    }
示例#26
0
    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;
        }
    }
示例#27
0
        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);
            }
        }
示例#28
0
        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();
            }
        }
示例#29
0
        public override void doInitialize()
        {
            base.doInitialize();

            try
            {
                m_navMesh = m_manager.createMesh(m_MeshName);
            }
            catch (ResourceNotFoundException resEx)
            {
            }
            catch (ServiceNotFoundException serEx)
            {
            }
        }
示例#30
0
 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;
             }
         }
 }
示例#31
0
    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);
        }
    }
示例#32
0
        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();
            }
        }
示例#33
0
 public NavigationMesh createMesh(ModelMeshPart mesh)
 {
     NavigationMesh navMesh = new NavigationMesh(mesh);
     m_navigationMeshes.Add(navMesh);
     return navMesh;
 }