diff --git a/Assets/Resources/Prefabs/Stage_Default.prefab b/Assets/Resources/Prefabs/Stage_Default.prefab index efd2e63377ac59f1c8ce33ec71d3cb0c830385e5..a7d03e5445d15a695dfe2cae55d836c52b37fea5 100644 --- a/Assets/Resources/Prefabs/Stage_Default.prefab +++ b/Assets/Resources/Prefabs/Stage_Default.prefab @@ -2124,6 +2124,11 @@ PrefabInstance: propertyPath: m_AnchorMin.x value: 0 objectReference: {fileID: 0} + - target: {fileID: 1063267681976544645, guid: b996060e27da25c498842defc1996d84, + type: 3} + propertyPath: m_IsActive + value: 1 + objectReference: {fileID: 0} - target: {fileID: 1063267681976544647, guid: b996060e27da25c498842defc1996d84, type: 3} propertyPath: m_Size @@ -2132,7 +2137,7 @@ PrefabInstance: - target: {fileID: 1063267681976544647, guid: b996060e27da25c498842defc1996d84, type: 3} propertyPath: m_Value - value: 0 + value: 1 objectReference: {fileID: 0} - target: {fileID: 1063267682090589445, guid: b996060e27da25c498842defc1996d84, type: 3} @@ -2407,12 +2412,12 @@ PrefabInstance: - target: {fileID: 6244008554354758921, guid: b996060e27da25c498842defc1996d84, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6244008554354758921, guid: b996060e27da25c498842defc1996d84, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 6244008554354758921, guid: b996060e27da25c498842defc1996d84, type: 3} @@ -2506,6 +2511,11 @@ PrefabInstance: propertyPath: m_AnchorMax.y value: 0 objectReference: {fileID: 0} + - target: {fileID: 558514683179411186, guid: f6ee936e2ace8e84ba70ad7e1ae58bdc, + type: 3} + propertyPath: m_SortingOrder + value: 10 + objectReference: {fileID: 0} - target: {fileID: 625961838730955993, guid: f6ee936e2ace8e84ba70ad7e1ae58bdc, type: 3} propertyPath: m_Enabled @@ -3030,6 +3040,28 @@ MonoBehaviour: m_EditorClassIdentifier: m_MovementRange: 50 m_ControlPath: <Gamepad>/leftStick +--- !u!1 &4584836137803151881 stripped +GameObject: + m_CorrespondingSourceObject: {fileID: 9218050178699362217, guid: f6ee936e2ace8e84ba70ad7e1ae58bdc, + type: 3} + m_PrefabInstance: {fileID: 4633513391531001248} + m_PrefabAsset: {fileID: 0} +--- !u!114 &2258042202925325658 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 4584836137803151881} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fc18334af0ab5ac4c9487f0675dbd439, type: 3} + m_Name: + m_EditorClassIdentifier: + mathModeCanvas: {fileID: 0} + factLayerMask: + serializedVersion: 2 + m_Bits: 64512 --- !u!1 &4982402009794970575 stripped GameObject: m_CorrespondingSourceObject: {fileID: 389710745492588143, guid: f6ee936e2ace8e84ba70ad7e1ae58bdc, diff --git a/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab b/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab index ae7550b5042a2e5a20f2207ae651f2e1dd656d69..c252ce6ba41851b0aa13d8ef0209ffd1e0363d80 100644 --- a/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab +++ b/Assets/Resources/Prefabs/UI/Ingame/FrameITUI_mobile.prefab @@ -3755,7 +3755,7 @@ Canvas: m_SortingBucketNormalizedSize: 0 m_AdditionalShaderChannelsFlag: 25 m_SortingLayerID: 0 - m_SortingOrder: 0 + m_SortingOrder: 10 m_TargetDisplay: 0 --- !u!114 &1831671680050863756 MonoBehaviour: @@ -4112,12 +4112,12 @@ PrefabInstance: - target: {fileID: 9207926681420349736, guid: b162218cc487f1242bd5ac7b4315a051, type: 3} propertyPath: m_Size - value: 0.4705884 + value: 1 objectReference: {fileID: 0} - target: {fileID: 9207926681420349736, guid: b162218cc487f1242bd5ac7b4315a051, type: 3} propertyPath: m_Value - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 9207926681445974865, guid: b162218cc487f1242bd5ac7b4315a051, type: 3} @@ -4157,7 +4157,7 @@ PrefabInstance: - target: {fileID: 9207926681532248490, guid: b162218cc487f1242bd5ac7b4315a051, type: 3} propertyPath: m_AnchoredPosition.x - value: 22783.914 + value: 0 objectReference: {fileID: 0} m_RemovedComponents: - {fileID: 9207926679892754397, guid: b162218cc487f1242bd5ac7b4315a051, type: 3} @@ -4298,12 +4298,12 @@ PrefabInstance: - target: {fileID: 8553388048532215990, guid: 884ac57de337c364391b247761071fb1, type: 3} propertyPath: m_AnchorMax.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8553388048532215990, guid: 884ac57de337c364391b247761071fb1, type: 3} propertyPath: m_AnchorMin.y - value: 1 + value: 0 objectReference: {fileID: 0} - target: {fileID: 8553388048532215990, guid: 884ac57de337c364391b247761071fb1, type: 3} diff --git a/Assets/Scripts/InteractionEngine/WorldFactInteraction.cs b/Assets/Scripts/InteractionEngine/WorldFactInteraction.cs new file mode 100644 index 0000000000000000000000000000000000000000..17cc7374a23381c681fc31404d5702d90a895a68 --- /dev/null +++ b/Assets/Scripts/InteractionEngine/WorldFactInteraction.cs @@ -0,0 +1,75 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; +using UnityEngine.UI; + +/// <summary> +/// This class handles displaying Fact tooltips, when hovering over a fact in the Gameworld +/// </summary> +public class WorldFactInteraction : MonoBehaviour +{ + public LayerMask factLayerMask; + + private GameObject currentDisplay; + private Transform lastHit = null; + + void LateUpdate() + { + if (currentDisplay != null && currentDisplay.GetComponent<DragHandling>().dragged) + { + // currently dragging -> remove transparency to indicate dragging and let DragHandling.cs take over + ChangeImageAlpha(currentDisplay.GetComponent<Image>(), 1); + return; + } + + UpdateDisplay(); + } + + private void UpdateDisplay() + { + Ray ray = Camera.main.ScreenPointToRay(Input.mousePosition); + if (!Physics.Raycast(ray, out RaycastHit hit, Mathf.Infinity, factLayerMask)) // check if fact was hit + { + lastHit = null; + Destroy(currentDisplay); // nothing was hit -> destroy currentDisplay if it exists + return; + } + + FactObject factObj = hit.transform.gameObject.GetComponentInChildren<FactObject>(); + + if (factObj == null) + { + // should never happen, if the layerMask is set up correctly + Debug.LogError("WorldFactInteraction Raycast collided with object in factLayerMask, that did not contain a FactObject script: " + hit.transform.gameObject.name); + lastHit = null; + return; + } + + if (hit.transform != lastHit) // a fact has been hit for the first time -> delete old display and instantiate new one + { + InstantiateNewDisplay(factObj); + } + + currentDisplay.transform.position = Input.mousePosition; // move currentDisplay to mousePosition + ChangeImageAlpha(currentDisplay.GetComponent<Image>(), 0.5f); // ensure that image alpha is correct, since it could have changed due to dragging + + lastHit = hit.transform; + } + + private void InstantiateNewDisplay(FactObject factObj) + { + if (currentDisplay) + Destroy(currentDisplay); + Fact fact = StageStatic.stage.factState[factObj.URI]; + // TODO: this link to DisplayFacts is not ideal: maybe refactor to SciptableObject or such + currentDisplay = fact.instantiateDisplay(DisplayFacts.prefabDictionary[fact.GetType()], transform); + } + + #region Helper + private static void ChangeImageAlpha(Image img, float alpha) + { + img.color = new Color(img.color.r, img.color.g, img.color.b, alpha); + } + #endregion Helper +} + diff --git a/Assets/Scripts/InteractionEngine/WorldFactInteraction.cs.meta b/Assets/Scripts/InteractionEngine/WorldFactInteraction.cs.meta new file mode 100644 index 0000000000000000000000000000000000000000..b5cbae1444a1985f120072c25b62251c25df3ac2 --- /dev/null +++ b/Assets/Scripts/InteractionEngine/WorldFactInteraction.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: fc18334af0ab5ac4c9487f0675dbd439 +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/InventoryStuff/DisplayFacts.cs b/Assets/Scripts/InventoryStuff/DisplayFacts.cs index b077f7469b08622a5c1f2b9ae28396efe0f927ac..c35ffe7e24a04bba2884f9f166eef8e6741277c7 100644 --- a/Assets/Scripts/InventoryStuff/DisplayFacts.cs +++ b/Assets/Scripts/InventoryStuff/DisplayFacts.cs @@ -6,7 +6,7 @@ public class DisplayFacts : MonoBehaviour { - public Dictionary<Type, GameObject> prefabDictionary; + public static Dictionary<Type, GameObject> prefabDictionary; public Dictionary<string, GameObject> displayedFacts = new(); diff --git a/Assets/Scripts/InventoryStuff/DragHandling.cs b/Assets/Scripts/InventoryStuff/DragHandling.cs index 8b51c3751be844dceefc13090ebd7cdd47b7dab6..597c13f09268de9c1bd9db314d0a66ff336ee849 100644 --- a/Assets/Scripts/InventoryStuff/DragHandling.cs +++ b/Assets/Scripts/InventoryStuff/DragHandling.cs @@ -5,7 +5,7 @@ public class DragHandling : MonoBehaviour, IDragHandler, IEndDragHandler { private Vector3 StartingPosition; private Transform StartingParent; - private bool dragged = false; + public bool dragged = false; public void OnDrag(PointerEventData eventData) { if (!dragged)