diff --git a/Assets/InteractionEngine/CommunicationEvents.cs b/Assets/InteractionEngine/CommunicationEvents.cs index 02c54cf94d2929336948e2653c8f02308336a3c7..1827a7d83d6c2945b6dd0e2354fab13288e5b185 100644 --- a/Assets/InteractionEngine/CommunicationEvents.cs +++ b/Assets/InteractionEngine/CommunicationEvents.cs @@ -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(); diff --git a/Assets/InteractionEngine/FactSpawner.cs b/Assets/InteractionEngine/FactSpawner.cs index 6f6227fc207345971953df1de11ecf78b95801f8..a30a28dec3749065ae4b3b6ecfe96f75caba979f 100644 --- a/Assets/InteractionEngine/FactSpawner.cs +++ b/Assets/InteractionEngine/FactSpawner.cs @@ -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; } diff --git a/Assets/InteractionEngine/ToolModeText.cs b/Assets/InteractionEngine/ToolModeText.cs index 3fefd92c5e030721880a1e6f5862fd716973ea8d..07b2bf45eb0a2fcc6f76ba93b2f09b7190628d9d 100644 --- a/Assets/InteractionEngine/ToolModeText.cs +++ b/Assets/InteractionEngine/ToolModeText.cs @@ -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; diff --git a/Assets/InteractionEngine/WorldCursor.cs b/Assets/InteractionEngine/WorldCursor.cs index ba68fb30287b93c52787d2ed830cc5640f431523..9f302bea3d7646a3560ca5d2441379b0c12bfb5f 100644 --- a/Assets/InteractionEngine/WorldCursor.cs +++ b/Assets/InteractionEngine/WorldCursor.cs @@ -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(); } diff --git a/Assets/Prefabs/Sphere.prefab b/Assets/Prefabs/Sphere.prefab index 34ea5d5cad395e5a013f8812f7e11457cdaac5ab..27638db68ea1ebe17c2e89d36e41ee599201dfdb 100644 --- a/Assets/Prefabs/Sphere.prefab +++ b/Assets/Prefabs/Sphere.prefab @@ -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 diff --git a/Assets/TreeWorld.unity b/Assets/TreeWorld.unity index b9d7940ffafbae0d1d4c6fbc92132c7a29260ea2..c315c8f085e733cce62282d0ec6f940f3923b0cd 100644 --- a/Assets/TreeWorld.unity +++ b/Assets/TreeWorld.unity @@ -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 diff --git a/ProjectSettings/TagManager.asset b/ProjectSettings/TagManager.asset index 1cc35b488ea2e23eda55e6047025156ac41ca058..b15725be44a4b3f86bbe26884a59f53d380a4b44 100644 --- a/ProjectSettings/TagManager.asset +++ b/ProjectSettings/TagManager.asset @@ -5,7 +5,7 @@ TagManager: serializedVersion: 2 tags: - ToolModeDisplay - - Point + - Selectable layers: - Default - TransparentFX