-
Notifications
You must be signed in to change notification settings - Fork 1
/
RoadElementModel.cs
142 lines (113 loc) · 3.46 KB
/
RoadElementModel.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
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
134
135
136
137
138
139
140
141
142
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class RoadElementModel : PathPoint {
public GameObject previousElement;
private Color startcolor;
public GameObject PreviousElement
{
get { return previousElement; }
set { previousElement = value; }
}
public GameObject nextElement;
public GameObject NextElement
{
get { return nextElement; }
set { nextElement = value; }
}
private Color highlightColor = Color.green;
private Renderer ownRenderer = null;
public Color[] originalColors;
private void Start()
{
if (ownRenderer == null) { ownRenderer = GetComponentInChildren<Renderer>(); }
StoreOriginalColor();
}
// Update is called once per frame
void Update()
{
}
private void StoreOriginalColor()
{
if (ownRenderer != null)
{
Material[] materials = ownRenderer.materials;
originalColors = new Color[materials.Length];
for (int i = 0; i < materials.Length; ++i) { originalColors[i] = materials[i].color; }
}
}
private void OnMouseEnter()
{
//Debug.Log("Detected" + ownRenderer);
if (ownRenderer != null)
{
Material[] materials = ownRenderer.materials;
for (int i = 0; i < materials.Length; ++i) { materials[i].color = highlightColor; }
ownRenderer.materials = materials;
}
}
private void OnMouseExit()
{
//Debug.Log("UNDetected" + ownRenderer);
if (ownRenderer != null)
{
Material[] materials = ownRenderer.materials;
for (int i = 0; i < materials.Length; ++i) { materials[i].color = originalColors[i]; }
ownRenderer.materials = materials;
}
}
private void OnMouseDown()
{
//Debug.Log("Selected road element: " + this.gameObject.name+" ------ "+this.transform.parent.name);
}
override
public void FindMyNeighbours()
{
if(nextElement == null)
{
GameObject myNeighbourForward = ElementTable.MyClosestNeighbour(this.gameObject, this.transform.forward * 5);
NextElement = myNeighbourForward;
if (myNeighbourForward.tag.Equals("RoadModel"))
{
RoadElementModel component = myNeighbourForward.GetComponent<RoadElementModel>();
if(component.PreviousElement == null)
{
component.PreviousElement = this.gameObject;
}
component.FindMyNeighbours();
}
if (myNeighbourForward.tag.Equals("CrossRoad"))
{
CrossRoadModel component = myNeighbourForward.GetComponent<CrossRoadModel>();
if(component.ClosestRoad == null)
{
component.ClosestRoad = this.gameObject;
}
component.FindMyNeighbours();
}
}
if (previousElement == null)
{
GameObject myNeighbourBackward = ElementTable.MyClosestNeighbour(this.gameObject, (-1) * this.transform.forward * 5);
PreviousElement = myNeighbourBackward;
if (myNeighbourBackward.tag.Equals("RoadModel"))
{
RoadElementModel component = myNeighbourBackward.GetComponent<RoadElementModel>();
if (component.NextElement == null)
{
component.NextElement = this.gameObject;
}
component.FindMyNeighbours();
}
if (myNeighbourBackward.tag.Equals("CrossRoad"))
{
CrossRoadModel component = myNeighbourBackward.GetComponent<CrossRoadModel>();
if (component.ClosestRoad == null)
{
component.ClosestRoad = this.gameObject;
}
component.FindMyNeighbours();
}
}
}
}