-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathPathNode.cs
More file actions
133 lines (108 loc) · 2.89 KB
/
PathNode.cs
File metadata and controls
133 lines (108 loc) · 2.89 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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
#define DEBUG_WAYPOINT
#undef DEBUG_WAYPOINT
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
#if (DEBUG_WAYPOINT)
public class PathNode : MonoBehaviour, IPathNode<PathNode>
#else
public class PathNode : IPathNode<PathNode>
#endif
{
public List<PathNode> connections;
public GameObject innerObj = null;
public bool nodeEnabled = false;
public static int startNode = -1;
public static int endNode = -1;
public int xPos = -1;
public int yPos = -1;
public bool nodeValid = true;
public Vector3 position;
private static int nodeCounter = 0;
public int Id {
get;
set;
}
public HashSet<int> ConnectionSet = new HashSet<int>();
public bool Invalid
{
get { return (this == null); }
}
public List<PathNode> Connections
{
get { return connections; }
}
public Vector3 Position
{
get
{
return position;
}
set
{
position = value;
}
}
public void AddConnection(PathNode other)
{
if (!ConnectionSet.Contains(other.Id))
connections.Add(other);
}
#if (DEBUG_WAYPOINT)
public void Update()
{
if (!nodeEnabled)
return;
DrawHelper.DrawCube(transform.position, Vector3.one, Color.red );
if(connections == null)
return;
for(int i = 0; i < connections.Count; i++)
{
if(connections[i] == null)
continue;
Debug.DrawLine(transform.position, connections[i].Position, Color.red);
}
}
public void Awake()
{
if(connections == null)
{
connections = new List<PathNode>();
}
}
#else
public string name = string.Empty;
#endif
public PathNode()
{
if(connections == null)
{
connections = new List<PathNode>();
}
}
public static PathNode Spawn(Vector3 inPosition, bool nodeEnabled, string suffix)
{
#if (DEBUG_WAYPOINT)
GameObject obj = null;
obj = new GameObject("PathNode_" + nodeCounter + " " + suffix);
obj.name = "PathNode_" + nodeCounter + " " + inPosition.x + ", " + inPosition.z + " " + suffix + ", enabled = " + nodeEnabled;
obj.AddComponent<PathNode>();
obj.transform.position = inPosition;obj.AddComponent<PathNode>();
obj.GetComponent<PathNode>().innerObj = obj;
obj.GetComponent<PathNode>().nodeEnabled = nodeEnabled;
obj.GetComponent<PathNode>().nodeValid = true;
obj.GetComponent<PathNode>().Position = inPosition;
obj.GetComponent<PathNode>().Id = nodeCounter;
nodeCounter++;
return obj.GetComponent<PathNode>();
#else
PathNode newNode = new PathNode();
newNode.name = "PathNode_" + nodeCounter + " " + inPosition.x + ", " + inPosition.z + " " + suffix + ", enabled = " + nodeEnabled;
newNode.position = inPosition;
newNode.nodeEnabled = nodeEnabled;
newNode.nodeValid = true;
nodeCounter++;
return newNode;
#endif
}
}