Skip to content
Snippets Groups Projects
Commit 4a1df0b9 authored by John Schihada's avatar John Schihada
Browse files

Created Facts will get highlighted when Mouse-Over-Event occurs

parent 84714536
No related branches found
No related tags found
No related merge requests found
......@@ -12,12 +12,18 @@ public class PointEvent : UnityEvent<RaycastHit,int>
public class HitEvent : UnityEvent<RaycastHit>
{
}
public class MouseOverFactEvent : UnityEvent<Transform>
{
}
public class ToolModeEvent : UnityEvent<ToolMode> {
}
public static HitEvent TriggerEvent = new HitEvent();
public static MouseOverFactEvent HighlightEvent = new MouseOverFactEvent();
public static MouseOverFactEvent EndHighlightEvent = new MouseOverFactEvent();
public static ToolModeEvent ToolModeChangedEvent = new ToolModeEvent();
public static PointEvent AddEvent = new PointEvent();
public static PointEvent RemoveEvent = new PointEvent();
......
......@@ -10,8 +10,14 @@ public class FactSpawner : MonoBehaviour
public string[] Facts = new String[100];
public GameObject[] GameObjectFacts = new GameObject[100];
//Variables for highlighting Facts where the cursor moves over
public Material defaultMaterial;
public Material highlightMaterial;
void Start()
{
CommunicationEvents.HighlightEvent.AddListener(OnMouseOverFact);
CommunicationEvents.EndHighlightEvent.AddListener(OnMouseOverFactEnd);
CommunicationEvents.TriggerEvent.AddListener(OnHit);
CommunicationEvents.ToolModeChangedEvent.AddListener(OnToolModeChanged);
CommunicationEvents.AddEvent.AddListener(SpawnFact);
......@@ -44,6 +50,8 @@ public void SpawnPoint(RaycastHit hit, int id)
string letter = ((Char)(64+id+1)).ToString();
point.GetComponentInChildren<TextMeshPro>().text = letter;
//If a new Point was spawned -> We are in MarkPointMode -> Then we want the collider to be disabled
//Hint: Thats why by now, if we mark a Point in an other mode than MarkPointMode, the
//Collider will be set disabled
point.GetComponentInChildren<SphereCollider>().enabled = false;
Facts[id] = letter;
GameObjectFacts[id] = point;
......@@ -57,6 +65,32 @@ public void DeletePoint(RaycastHit hit, int id)
Facts[id] = "";
}
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;
}
}
public void OnHit(RaycastHit hit)
{
......@@ -88,11 +122,11 @@ public void OnToolModeChanged(ToolMode ActiveToolMode) {
//but we don't want to have the ability to select Lines or Angles
foreach (GameObject GameObjectFact in this.GameObjectFacts)
{
if (GameObjectFact.tag == "Line" || GameObjectFact.tag == "Angle")
if (GameObjectFact.layer == LayerMask.NameToLayer("Line") || GameObjectFact.layer == LayerMask.NameToLayer("Angle"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = false;
}
else if (GameObjectFact.tag == "Point") {
else if (GameObjectFact.layer == LayerMask.NameToLayer("Point")) {
GameObjectFact.GetComponentInChildren<Collider>().enabled = true;
}
}
......@@ -102,11 +136,11 @@ public void OnToolModeChanged(ToolMode ActiveToolMode) {
//but we don't want to have the ability to select Points or Angles
foreach (GameObject GameObjectFact in this.GameObjectFacts)
{
if (GameObjectFact.tag == "Point" || GameObjectFact.tag == "Angle")
if (GameObjectFact.layer == LayerMask.NameToLayer("Point") || GameObjectFact.layer == LayerMask.NameToLayer("Angle"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = false;
}
else if (GameObjectFact.tag == "Line")
else if (GameObjectFact.layer == LayerMask.NameToLayer("Line"))
{
GameObjectFact.GetComponentInChildren<Collider>().enabled = true;
}
......
......@@ -12,6 +12,7 @@ public class ToolModeText : MonoBehaviour
// Start is called before the first frame update
void Start()
{
//Show the Text that the MarkPointMode is active on startup
gameObject.GetComponentInChildren<UnityEngine.UI.Text>().CrossFadeAlpha(0.0f, 0.0f, false);
gameObject.GetComponentInChildren<UnityEngine.UI.Text>().CrossFadeAlpha(1.0f, 0.9f, false);
this.timerActive = true;
......
......@@ -10,6 +10,9 @@ public class WorldCursor : MonoBehaviour
private Camera Cam;
private ToolMode ActiveToolMode{get; set;}
private string selectableTag = "Selectable";
private Transform lastFactSelection;
void Start()
{
Cam = Camera.main;
......@@ -31,6 +34,27 @@ void Update()
transform.up = Hit.normal;
transform.position += .01f * Hit.normal;
//SELECTION-HIGHLIGHTING-PART
//Check if a Fact was 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
CheckMouseButtons();
}
......
......@@ -14,7 +14,7 @@ GameObject:
- component: {fileID: 8087426936968725520}
m_Layer: 10
m_Name: Sphere
m_TagString: Point
m_TagString: Selectable
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
......
......@@ -1398,6 +1398,8 @@ MonoBehaviour:
- {fileID: 0}
- {fileID: 0}
- {fileID: 0}
defaultMaterial: {fileID: 2100000, guid: 8ae9adf4dc782964387385c1e8c0eb72, type: 2}
highlightMaterial: {fileID: 2100000, guid: c7daa82e15f0cf04d92d0f41ce84f9df, type: 2}
--- !u!1 &1675643434
GameObject:
m_ObjectHideFlags: 0
......
......@@ -5,7 +5,7 @@ TagManager:
serializedVersion: 2
tags:
- ToolModeDisplay
- Point
- Selectable
layers:
- Default
- TransparentFX
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment