summaryrefslogtreecommitdiff
path: root/GameCode/TerrainTile.cs
blob: 932ff378e57b665927230829ad388ab0e943c299 (plain)
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
using UnityEngine;

public class TerrainTile : MonoBehaviour
{
	public Waypoint last;

	[SerializeField]
	private Waypoint left;

	[SerializeField]
	private Waypoint top;

	[SerializeField]
	private Waypoint right;

	public Waypoint south;

	public Waypoint west;

	public Waypoint north;

	public Waypoint east;

	public void SetCardinalDirections()
	{
		if (base.transform.eulerAngles.y == 0f)
		{
			south = last;
			west = left;
			north = top;
			east = right;
		}
		else if (base.transform.eulerAngles.y == 90f)
		{
			south = right;
			west = last;
			north = left;
			east = top;
		}
		else if (base.transform.eulerAngles.y == 180f)
		{
			south = top;
			west = right;
			north = last;
			east = left;
		}
		else if (base.transform.eulerAngles.y == 270f)
		{
			south = left;
			west = top;
			north = right;
			east = last;
		}
		else
		{
			Debug.LogError(base.name + " not at a proper rotation. Current rotation: " + base.transform.eulerAngles.y);
		}
	}

	public void ConnectToTile(TerrainTile next)
	{
		if (base.transform.eulerAngles.y == 0f)
		{
			last.SetNextWaypoint(next.north);
			next.north.AddPreviousWaypoint(last);
		}
		else if (base.transform.eulerAngles.y == 90f)
		{
			last.SetNextWaypoint(next.east);
			next.east.AddPreviousWaypoint(last);
		}
		else if (base.transform.eulerAngles.y == 180f)
		{
			last.SetNextWaypoint(next.south);
			next.south.AddPreviousWaypoint(last);
		}
		else if (base.transform.eulerAngles.y == 270f)
		{
			last.SetNextWaypoint(next.west);
			next.west.AddPreviousWaypoint(last);
		}
		else
		{
			Debug.LogError(base.name + " not at a proper rotation");
		}
	}
}