public override bool shouldExecute() { if (this.owner.hunger.value <= this.startFoodHuntAt) { // Find a table. if (this.isCook() && this.cookMeta.plateState != CellBehaviorTable.EnumPlateState.FULL) { return(false); } foreach (CellBehaviorTable table in this.owner.world.getAllBehaviors <CellBehaviorTable>(behavior => behavior.hasChair && !behavior.isOccupied())) { NavPath path = this.agent.calculatePath(table.chairPos); if (path != null) { path.endingLookDirection = Rotation.directionToRotation(table.center - table.chair.behavior.center); this.navPath = path; this.table = table; this.table.setOccupant(this.owner); return(true); } else { this.owner.emote.startEmote(new Emote("exclamation", 0.1f).setTooltip("Can't find a table")); } } } return(false); }
public override void preform() { // Update the path if the worker moves to a new cell if (this.target.position != this.navPath.endPoint.position) { this.navPath = this.agent.calculatePath(this.target.position); this.agent.setPath(this.navPath); if (this.navPath != null) { // The target can no longer be reached. With the // navPath field being null, the task will end // next frame. return; } } if (this.attackTimer > 0) { this.attackTimer -= Time.deltaTime; } if (Vector2.Distance(this.target.worldPos, this.owner.worldPos) < 1f && this.attackTimer <= 0) { // Attack // TODO this.attackTimer = this._attackRate; } }
private void MoveToNearestWeapon() { if (nearestLootable.Exists()) { NavPath.Move(ref agent, ref currentDestination, ref directionGuide, nearestLootable.transform.position); } }
private void OnEnable() { navPath = target as NavPath; m_PathPositionProp = serializedObject.FindProperty("pathPositions"); reorderableList = new ReorderableList(serializedObject, m_PathPositionProp, true, true, true, true); reorderableList.drawElementCallback = (Rect rect, int index, bool isActive, bool isFosused) => { EditorGUI.LabelField(new Rect(rect.x, rect.y, EditorGUIUtility.currentViewWidth - 50, EditorGUIUtility.singleLineHeight), (index + 1).ToString() + ". Checkpoint"); if (isFosused) { currPos = navPath.pathPositions[index]; editingID = index; } }; reorderableList.onAddCallback = (ReorderableList list) => { reorderableList.serializedProperty.InsertArrayElementAtIndex(reorderableList.serializedProperty.arraySize); }; reorderableList.onRemoveCallback = (ReorderableList list) => { if (EditorUtility.DisplayDialog("Delete Checkpoint?", "Are you sure you want remove checkpoint from database?", "Delete", "Cancel")) { if (navPath.pathPositions[list.index] != null) { ReorderableList.defaultBehaviours.DoRemoveButton(list); } } }; reorderableList.drawHeaderCallback = (Rect rect) => { EditorGUI.LabelField(rect, "NavPath Checkpoints"); editing = GUI.Toggle(new Rect(rect.x + 150, rect.y + 2, EditorGUIUtility.currentViewWidth - 200, EditorGUIUtility.singleLineHeight - 2), editing, "Edit", "Button"); }; }
private void MoveToNearestEnemy() { if (nearestEnemy.Exists()) { NavPath.Move(ref agent, ref currentDestination, ref directionGuide, nearestEnemy.transform.position); } }
private void Update() { if (!Pause.isPaused()) { if (this.moveHelper != null && this.moveHelper.hasPath()) { this.lr.enabled = true; NavPath path = this.moveHelper.path; List <Vector3> points = new List <Vector3>(); points.Add(this.transform.position - Vector3.forward); for (int i = path.targetIndex; i < path.pointCount; i++) { points.Add((Vector3)path.getPoint(i).worldPos + Vector3.forward * this.zValue); } this.lr.positionCount = points.Count; Vector3[] a = points.ToArray(); Array.Reverse(a); this.lr.SetPositions(a); } else { this.lr.enabled = false; } } }
public override void onTaskStop() { base.onTaskStop(); if (this.bed != null) { // Try to move away from the bed so it "looks free". // If there no walkable space, stay on the bed. Others will still be able to claim it. Position?freeSpot = this.getFreeSpot(this.owner.position); if (freeSpot == null) { freeSpot = this.getFreeSpot(this.owner.position + Rotation.UP); // Head of the bed. } if (freeSpot != null) { NavPath path = this.agent.calculatePath( (Position)freeSpot, false); if (path != null) { this.agent.setPath(path); } } this.bed.setOccupant(null); this.owner.setSleeping(false); } this.bed = null; this.owner.emote.cancelEmote(); }
public override void onTaskStop() { base.onTaskStop(); if (this.table != null) { this.table.setOccupant(null); // Try to move away from the chair so it "looks free". // If there no walkable space, stay on the chair. Others will still be able to claim it. Position?freeSpot = this.getFreeSpot(this.owner.position); if (freeSpot != null) { NavPath path = this.agent.calculatePath( (Position)freeSpot, false); if (path != null) { this.agent.setPath(path); } } //this.owner.animator.stopClip(); } this.table = null; this.owner.emote.cancelEmote(); }
private List <NavPath> Dijkstra(Node s) { Dictionary <long, QueueNode> touched = new Dictionary <long, QueueNode>(); HashSet <long> done = new HashSet <long>(); FastPriorityQueue <QueueNode> pq = new FastPriorityQueue <QueueNode>(map.Nodes.Count); List <NavPath> ret = Enumerable.Repeat(NavPath.NoPath, intersections.Count).ToList(); QueueNode start = new QueueNode(s.id); start.path = new NavPath(); touched[s.id] = start; pq.Enqueue(start, 0); while (pq.Count != 0) { QueueNode qn = pq.Dequeue(); float distance = qn.Priority; NavPath p = qn.path; Node n = map.Nodes[qn.id]; done.Add(n.id); ret[pathMapping[n.id]] = p; foreach (var edgeId in n.Edges) { Way edge = map.Ways[edgeId]; if (edge.GetNext(n.id) != -1) { Node next = map.Nodes[edge.GetNext(n.id)]; float newWeight = distance + edge.weight; if (!done.Contains(next.id)) { List <Vector3> points = new List <Vector3>(edge.waypoints); if (edge.isBack(n.id)) { points.Reverse(); } if (touched.ContainsKey(next.id)) { qn = touched[next.id]; if (qn.Priority > newWeight) { pq.UpdatePriority(qn, newWeight); qn.path = new NavPath(p.getPoints()); qn.path.Add(points); } } else { qn = new QueueNode(next.id); qn.path = new NavPath(p.getPoints()); qn.path.Add(points); touched[next.id] = qn; pq.Enqueue(qn, newWeight); } } } } } return(ret); }
public override void onTaskStop() { base.onTaskStop(); this.navPath = null; this.target = null; this.attackTimer = 0; }
static void Postfix(NavPath __instance, NavMeshAgent ____navMeshAgent) { if (!Main.enabled) { return; } //____navMeshAgent.obstacleAvoidanceType = ObstacleAvoidanceType.LowQualityObstacleAvoidance; }
public void SetPath(NavPath path, NavPath.FollowDirection pathDirection = NavPath.FollowDirection.Forward, NavPath.RepeatMode mode = NavPath.RepeatMode.Once) { Debug.Assert(path != null); this.path = path; this.direction = pathDirection; this.mode = mode; RestartPath(); }
public PathPlannerTests() { testShip = new Spaceship(0, "TestShip"); testPath = new NavPath(); TestGalaxyMapDataStreamProvider provider = new TestGalaxyMapDataStreamProvider(".//..//..//..//..//assets"); provider.Initialize(); GalaxyMapLoader loader = new GalaxyMapLoader(); map = loader.LoadGalaxyMap("GalaxyMap", provider); Debug.Assert((map.Count > 0), "No starsystem was loaded."); }
void Test() { map = new int[5, 5] { { 0, 0, 0, 0, 0 }, { 0, 1, 1, 1, 0 }, { 0, 1, 0, 0, 0 }, { 0, 1, 1, 0, 0 }, { 0, 0, 0, 0, 0 } }; nav = new AstarNavMesh(); nav.Init(map); path = nav.GetPath(startX, startY, endX, endY); }
WaitForSeconds followUpdate; //update of aim position private void Start() { state = States.Null; visibilityController = GetComponentInChildren <Visibility>(); thisTransform = transform; thisGrowController = GetComponent <GrowController>(); path = WorldBounds.singleton.GetRandomPath(); pathCount = path.positions.Count; index = Random.Range(0, pathCount); walkUpdate = new WaitForSeconds(updateTime); followUpdate = new WaitForSeconds(updateTime / 2f); ai = GetComponent <NavMeshAgent>(); anim = GetComponent <Animator>(); SetIdle(); }
public void StartPathCalculation() { mapChoiceEnabled = false; myPath = Dijstraka(myStart, myEnd); lenghtText.text = "Length: " + Math.Round(myPath.totalDistance, 2).ToString() + "m"; foreach (GameObject transition in parser.transitions) //deactivate all transitions { transition.SetActive(false); } foreach (GameObject state in parser.states) { state.SetActive(false); } myStart.gameObject.SetActive(true); myEnd.gameObject.SetActive(true); for (int node = 0; node < myPath.Nodes.Count - 1; node++) //search every combination of two nodes { string node1 = myPath.Nodes[node].ToString().Remove(myPath.Nodes[node].ToString().Length - 10); //shorten String because string would look like "S01 (NavNode)" string node2 = myPath.Nodes[node + 1].ToString().Remove(myPath.Nodes[node + 1].ToString().Length - 10); foreach (string[] transition in parser.transitionsConnectionList) //for every combination look inside transition list for the corresponding transition { if (transition[1] == node1 && transition[2] == node2) //get transition name { foreach (GameObject transitionObject in parser.transitions) //get corresponding GameObject { if (transitionObject.name == transition[0]) { transitionObject.SetActive(true); break; } } break; } } } }
public override bool shouldExecute() { foreach (EntityBase e in this.owner.world.entities.list) { if (e is EntityWorker) { if (e.depth == this.owner.depth && Vector2.Distance(e.worldPos, this.owner.worldPos) < this._workerSpotRange) { NavPath p = this.agent.calculatePath(e.position); if (p != null) { this.navPath = p; this.agent.setPath(p); this.target = (EntityWorker)e; return(true); } } } } return(false); }
private void Update() { if (!Pause.isPaused() && !PopupWindow.blockingInput() && Main.DEBUG) { Position pos = CameraController.instance.getMousePos(); if (Input.GetMouseButtonDown(0)) { if (Input.GetKey(KeyCode.LeftControl)) { foreach (EntityBase e in this.world.entities.list) { if (e is EntityWorker) { PathfindingAgent agent = ((EntityWorker)e).moveHelper; NavPath path = agent.calculatePath(pos); if (path != null) { agent.setPath(path); } } } } if (Input.GetKey(KeyCode.Delete)) { world.setCell(pos, null); world.liftFog(pos); } if (Input.GetKey(KeyCode.F)) { world.entities.spawn(pos, 10); } } } }
private void Move() { NavPath.Move(ref agent, ref currentDestination, ref directionGuide); }
public NavPath Dijstraka(NavNode start, NavNode end) { List <NavNode> allNodes = new List <NavNode>(); foreach (GameObject state in parser.states) //Add NavNode Object to m_Nodes List { allNodes.Add(state.GetComponent <NavNode>()); } if (start == null || end == null) //make sure start and end are defined { throw new ArgumentNullException(); } NavPath path = new NavPath(); if (start == end) //when start = end, than define path with only start-node { path.Nodes.Add(start); return(path); } List <NavNode> unvisited = new List <NavNode>(); Dictionary <NavNode, NavNode> previous = new Dictionary <NavNode, NavNode>(); //dictionary for optimal pathes Dictionary <NavNode, float> distances = new Dictionary <NavNode, float>(); //dictionary for distances for (int i = 0; i < allNodes.Count; i++) { NavNode node = allNodes[i]; unvisited.Add(node); //add all nodes to list of unvisited nodes distances.Add(node, float.MaxValue); //all distances start with value infinite } distances[start] = 0f; //distance of startnode = 0 while (unvisited.Count != 0) //do for all unvisited nodes { unvisited = unvisited.OrderBy(node => distances[node]).ToList(); //order unvisited nodes by distance from short ► long NavNode current = unvisited[0]; //node with shortest distance unvisited.Remove(current); //mark as visited if (current == end) //check if current node equals end-node { while (previous.ContainsKey(current)) //construction of path { path.Nodes.Insert(0, current); //add node to list of shortest path current = previous[current]; //get connected node } path.Nodes.Insert(0, current); //add start-node break; } for (int i = 0; i < current.Connections.Count; i++) //go through connections of current node { NavNode neighbor = current.Connections[i]; float length = Vector3.Distance(current.transform.position, neighbor.transform.position); //get distance between these nodes float alt = distances[current] + length; //alt = distance from start to connected neighbor if (alt < distances[neighbor]) //check if distance from start to neighbor start is shorter than the previous calculated distance { distances[neighbor] = alt; //set new distance in dictionary previous[neighbor] = current; //set neighbor for optimal path } } } path.Bake(); //calculate lenght return(path); }
public void setPath(NavPath path) { this.path = path; }
/// <summary> /// Stops the Worker. This will delete the path. /// </summary> public void stop() { this.path = null; }
void IWorldManager.ShipTakeoff(int spaceshipId, NavPath path, GameTime gameTime) { throw new NotImplementedException(); }
void ShipTakeoff(int spaceshipId, NavPath path, GameTime gameTime) { //TODO: vyslání lodi na cestu throw new NotImplementedException(); }
public WaitForPathToFinish(EntityWorker worker) { this.worker = worker; this.path = this.worker.moveHelper.path; }