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
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class ShinyThings : MonoBehaviour
{
public WorldCursor Cursor;
//Attributes for Highlighting of Facts when Mouse-Over
private string selectableTag = "Selectable";
private Transform lastFactSelection;
//Attributes for simulating the drawing of a line
public LineRenderer lineRenderer;
private List<Vector3> linePositions = new List<Vector3>();
private bool lineRendererActivated;
//Visual helpers
// Start is called before the first frame update
void Start()
{
if(Cursor == null)Cursor = GetComponent<WorldCursor>();
}
// Update is called once per frame
void Update()
{
//SELECTION-HIGHLIGHTING-PART
//Check if a Fact was Hit
RaycastHit Hit = Cursor.Hit;
Transform selection = Hit.transform;
//Set the last Fact unselected
if (this.lastFactSelection != null)
{
//Invoke the EndHighlightEvent that will be handled in FactSpawner
CommunicationEvents.EndHighlightEvent.Invoke(this.lastFactSelection);
this.lastFactSelection = null;
}
//Set the Fact that was Hit as selected
if (selection.CompareTag(selectableTag))
{
//Invoke the HighlightEvent that will be handled in FactSpawner
this.lastFactSelection = selection;
CommunicationEvents.HighlightEvent.Invoke(selection);
}
//SELECTION-HIGHLIGHTING-PART-END
}
public void OnMouseOverFactEnd(Transform selection)
{
Renderer selectionRenderer;
if (selection != null)
{
selectionRenderer = selection.GetComponent<Renderer>();
if (selectionRenderer != null)
{
//Set the Material of the fact back to default
selectionRenderer.material = defaultMaterial;
}
}
}
public void OnMouseOverFact(Transform selection)
{
Renderer selectionRenderer;
selectionRenderer = selection.GetComponent<Renderer>();
if (selectionRenderer != null)
{
//Set the Material of the Fact, where the mouse is over, to a special one
selectionRenderer.material = highlightMaterial;
}
}
void DeactivateLineRenderer()
{
//Reset the first points
this.lineRenderer.SetPosition(0, Vector3.zero);
this.lineRenderer.SetPosition(1, Vector3.zero);
if (linePositions.Count > 0)
this.linePositions.Clear();
this.lineRendererActivated = false;
}
//Updates the second-point of the Line when First Point was selected in LineMode
void UpdateLineRenderer(Vector3 currentPosition)
{
if (this.ActiveToolMode == ToolMode.CreateLineMode)
{
if (this.lineRendererActivated)
{
this.linePositions[1] = currentPosition;
this.lineRenderer.SetPosition(1, this.linePositions[1]);
}
}
}
}