forked from FritzsHero/RoadArchitect
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNavigation.cs
56 lines (50 loc) · 1.75 KB
/
Navigation.cs
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
using UnityEngine;
namespace RoadArchitect
{
public static class Navigation
{
public static void UpdateConnectedNodes()
{
InitResetNavigationData();
Object[] allSplines = GameObject.FindObjectsOfType(typeof(SplineC));
//Store connected spline nodes on each other:
SplineN node;
foreach (SplineC spline in allSplines)
{
int nodeCount = spline.nodes.Count;
for (int i = 0; i < nodeCount; i++)
{
node = spline.nodes[i];
//Add next node if not last node:
if ((i + 1) < nodeCount)
{
node.connectedID.Add(spline.nodes[i + 1].id);
node.connectedNode.Add(spline.nodes[i + 1]);
}
//Add prev node if not first node:
if (i > 0)
{
node.connectedID.Add(spline.nodes[i - 1].id);
node.connectedNode.Add(spline.nodes[i - 1]);
}
}
}
}
public static void InitResetNavigationData()
{
Object[] allSplines = GameObject.FindObjectsOfType(typeof(SplineC));
int splineCount = 0;
int nodeCount = 0;
foreach (SplineC spline in allSplines)
{
splineCount += 1;
foreach (SplineN node in spline.nodes)
{
nodeCount += 1;
node.ResetNavigationData();
}
spline.ResetNavigationData();
}
}
}
}