-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWayPointPath.cs
More file actions
57 lines (48 loc) · 1.05 KB
/
WayPointPath.cs
File metadata and controls
57 lines (48 loc) · 1.05 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
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
public class WayPointPath : MonoBehaviour
{
public static Dictionary<string, WayPointPath> paths = new Dictionary<string, WayPointPath>();
public static WayPointPath Get (string pathName)
{
WayPointPath wayPointPath;
paths.TryGetValue(pathName, out wayPointPath);
return wayPointPath;
}
public string pathName;
public WayPoint head;
public Color pathColor = Color.cyan;
public WayPoint[] wayPoints {
get {
List<WayPoint> nodes = new List<WayPoint>();
WayPoint node = head;
while (node) {
nodes.Add(node);
node = node.next;
}
return nodes.ToArray();
}
}
public Vector3[] path {
get {
return System.Array.ConvertAll(wayPoints, x => x.transform.position);
}
}
void OnEnable ()
{
if (!paths.ContainsKey(pathName)) {
paths.Add(pathName, this);
}
}
void OnDisable ()
{
paths.Remove(pathName);
}
public void OnDrawGizmosSelected ()
{
if (head && head.next) { // path.Length >= 2
iTween.DrawPath(path, pathColor);
}
}
}