You need to sign in or sign up before continuing.
Newer
Older
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
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using static CommunicationEvents;
public class FactManager : MonoBehaviour
{
// Start is called before the first frame update
void Start()
{
CommunicationEvents.ToolModeChangedEvent.AddListener(OnToolModeChanged);
}
// Update is called once per frame
void Update()
{
//Je nachdem ob erster oder der zweite Punkt angeklickt wurde behandeln
//Wenn erster Punkt einen Point-Collider erwischt hat:
//Linie aktivieren und Cursor folgen
//Wenn erster Punkt keinen Point-Collider erwischt hat:
//Nichts tun -> Evtl Hint einblenden
//Wenn zweiter Punkt einen Point-Collider erwischt hat:
//Event senden um GameObject-Line zu erzeugen
//Wenn zweiter Punkt keinen Point-Collider erwischt hat:
//Linie deaktivieren -> Evtl Hint einblenden
//LayerMask for Points
int layerMask = 1 << LayerMask.NameToLayer("Point"); //only hit Point
//Wenn bereits der erste Punkt markiert wurde
if (this.lineRendererActivated) //instead: bool variable....
{
//If a second Point was Hit
if (Physics.Raycast(ray, out Hit, 30f, layerMask))
{
//Event for Creating the Line
Vector3 point1 = this.linePositions[0];
Vector3 point2 = Hit.transform.gameObject.transform.position;
this.DeactivateLineRenderer();
CommunicationEvents.AddLineEvent.Invoke(point1, point2);
break;
}
//If no Point was hit
else
{
//TODO: Hint that only a line can be drawn between already existing points
this.DeactivateLineRenderer();
}
}
//Wenn der erste Punkt noch nicht markiert wurde
else
{
//Check if a Point was hit
if (Physics.Raycast(ray, out Hit, 30f, layerMask))
{
//Set LineRenderer activated
this.lineRendererActivated = true;
//Add the position of the hit Point for the start of the Line
Vector3 temp = Hit.transform.gameObject.transform.position;
//temp += Vector3.up;
linePositions.Add(temp);
//The second point is the same point at the moment
linePositions.Add(temp);
this.lineRenderer.SetPosition(0, linePositions[0]);
this.lineRenderer.SetPosition(1, linePositions[1]);
}
else
{
//TODO: Hint that only a line can be drawn between already existing points
}
}
}
public int GetFirstEmptyID()
{
for (int i = 0; i < Facts.Length; ++i)
{
if (Facts[i] == "")
return i;
}
return Facts.Length - 1;
}
public void OnToolModeChanged(ToolMode ActiveToolMode)
{
switch (ActiveToolMode)
{
case ToolMode.MarkPointMode:
//If MarkPointMode is activated we want to have the ability to mark the point
//everywhere, independent of already existing facts
foreach (GameObject GameObjectFact in GameObjectFacts)
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = false;
}
break;
case ToolMode.CreateLineMode:
//If CreateLineMode is activated we want to have the ability to select points for the Line
//but we don't want to have the ability to select Lines or Angles
foreach (GameObject GameObjectFact in GameObjectFacts)
{
if (GameObjectFact.layer == LayerMask.NameToLayer("Line") || GameObjectFact.layer == LayerMask.NameToLayer("Angle"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = false;
}
else if (GameObjectFact.layer == LayerMask.NameToLayer("Point"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = true;
}
}
break;
case ToolMode.CreateAngleMode:
//If CreateAngleMode is activated we want to have the ability to select Lines for the Angle
//but we don't want to have the ability to select Points or Angles
foreach (GameObject GameObjectFact in GameObjectFacts)
{
if (GameObjectFact.layer == LayerMask.NameToLayer("Point") || GameObjectFact.layer == LayerMask.NameToLayer("Angle"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = false;
}
else if (GameObjectFact.layer == LayerMask.NameToLayer("Line"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = true;
}
}
break;
case ToolMode.DeleteMode:
//If DeleteMode is activated we want to have the ability to delete every Fact
//independent of the concrete type of fact
foreach (GameObject GameObjectFact in GameObjectFacts)
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = true;
}
break;
case ToolMode.ExtraMode:
foreach (GameObject GameObjectFact in GameObjectFacts)
{
}
break;
}
}
public void OnHit(RaycastHit hit)
{
Debug.Log(CommunicationEvents.ActiveToolMode);
if (hit.transform.gameObject.layer == LayerMask.NameToLayer("Point"))
{
//hit existing point, so delete it
if (CommunicationEvents.ActiveToolMode == ToolMode.ExtraMode)
{
var menu = GameObject.Instantiate(SmartMenu);
menu.GetComponent<Canvas>().worldCamera = Camera.main;
menu.transform.SetParent(hit.transform);
menu.transform.localPosition = Vector3.up - Camera.main.transform.forward;
}
else
{
char letter = hit.transform.gameObject.GetComponentInChildren<TextMeshPro>().text.ToCharArray()[0];
int id = letter - 65;
CommunicationEvents.RemoveEvent.Invoke(id);
}
}
else
{
CommunicationEvents.AddPointEvent.Invoke(hit, GetFirstEmptyID());
}
}
}