-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathNode.cs
More file actions
54 lines (48 loc) · 2.14 KB
/
Node.cs
File metadata and controls
54 lines (48 loc) · 2.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
///-----------------------------------------------------------------
/// Class: Node
/// Description: Data class for the Node which implements the IComparable interface
/// Author: Lee
/// GitHub: https://github.com/ivuecode
///-----------------------------------------------------------------
using System;
using UnityEngine;
using System.Collections.Generic;
public enum NodeType { Open, Blocked };
public class Node : IComparable<Node>
{
public int xIndex = -1; // x and y index in the graph array
public int yIndex = -1; // x and y index in the graph array
public float priority; // Priority used to set place in queue
public Vector3 position; // (x,y,z) position in 3d space
public Node previous = null; // Referebce to preceding null in the current graph search
public NodeType nodeType = NodeType.Open;
public List<Node> neighbors = new List<Node>(); // List of neighbor Nodes
public float distanceTraveled = Mathf.Infinity; // Total distance traveled from the start Node
/// <summary>
/// Node constructor
/// </summary>
public Node(int x, int y, NodeType type)
{
xIndex = x;
yIndex = y;
nodeType = type;
}
/// <summary>
/// Required by IComparable, method to compare this node with another Node based on priority
/// </summary>
public int CompareTo(Node other)
{
if (priority < other.priority) return -1;
else if (priority > other.priority) return 1;
else return 0;
}
/// <summary>
/// Reset the state of this node
/// </summary>
public void Reset()
{
previous = null;
priority = 0;
distanceTraveled = Mathf.Infinity;
}
}