Working on the tooltip.

This commit is contained in:
That-One-Nerd 2025-01-16 15:24:25 -05:00
parent b44504c0a4
commit 37250c6f84
5 changed files with 957 additions and 113 deletions

File diff suppressed because one or more lines are too long

View File

@ -761,9 +761,8 @@ RectTransform:
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: m_Children:
- {fileID: 127939172} - {fileID: 127939172}
- {fileID: 1742646164}
m_Father: {fileID: 1293669686} m_Father: {fileID: 1293669686}
m_RootOrder: 1 m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0.5, y: 0.5}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0.5, y: 0.5}
@ -1740,6 +1739,142 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 3154916079333882549, guid: cecedfa0c5e18984cb3000265067bf47, type: 3} m_CorrespondingSourceObject: {fileID: 3154916079333882549, guid: cecedfa0c5e18984cb3000265067bf47, type: 3}
m_PrefabInstance: {fileID: 569017521} m_PrefabInstance: {fileID: 569017521}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &581002075
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 581002076}
- component: {fileID: 581002078}
- component: {fileID: 581002077}
m_Layer: 5
m_Name: Footer
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &581002076
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 581002075}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1742646164}
m_RootOrder: 2
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 0}
m_AnchorMax: {x: 0, y: 0}
m_AnchoredPosition: {x: 31.5, y: 22.25}
m_SizeDelta: {x: 437, y: 35}
m_Pivot: {x: 0, y: 0}
--- !u!114 &581002077
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 581002075}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: 'Footer
'
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 3e9223a74cf8f5147ba8ec739992abf8, type: 2}
m_sharedMaterial: {fileID: -983720085404516624, guid: 3e9223a74cf8f5147ba8ec739992abf8, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 20
m_fontSizeBase: 20
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 1024
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: -140
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &581002078
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 581002075}
m_CullTransparentMesh: 1
--- !u!224 &607779170 stripped --- !u!224 &607779170 stripped
RectTransform: RectTransform:
m_CorrespondingSourceObject: {fileID: 3154916079333882549, guid: cecedfa0c5e18984cb3000265067bf47, type: 3} m_CorrespondingSourceObject: {fileID: 3154916079333882549, guid: cecedfa0c5e18984cb3000265067bf47, type: 3}
@ -2122,6 +2257,140 @@ Animator:
m_HasTransformHierarchy: 1 m_HasTransformHierarchy: 1
m_AllowConstantClipSamplingOptimization: 1 m_AllowConstantClipSamplingOptimization: 1
m_KeepAnimatorControllerStateOnDisable: 0 m_KeepAnimatorControllerStateOnDisable: 0
--- !u!1 &928746189
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 928746190}
- component: {fileID: 928746192}
- component: {fileID: 928746191}
m_Layer: 5
m_Name: Content
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &928746190
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 928746189}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1742646164}
m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 31.5, y: -66.5}
m_SizeDelta: {x: 437, y: 35}
m_Pivot: {x: 0, y: 1}
--- !u!114 &928746191
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 928746189}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: This is where the content goes.
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 3e9223a74cf8f5147ba8ec739992abf8, type: 2}
m_sharedMaterial: {fileID: -983720085404516624, guid: 3e9223a74cf8f5147ba8ec739992abf8, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 20
m_fontSizeBase: 20
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 256
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: -140
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &928746192
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 928746189}
m_CullTransparentMesh: 1
--- !u!1 &943628639 --- !u!1 &943628639
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2296,6 +2565,140 @@ RectTransform:
m_CorrespondingSourceObject: {fileID: 3154916079333882549, guid: cecedfa0c5e18984cb3000265067bf47, type: 3} m_CorrespondingSourceObject: {fileID: 3154916079333882549, guid: cecedfa0c5e18984cb3000265067bf47, type: 3}
m_PrefabInstance: {fileID: 964661264} m_PrefabInstance: {fileID: 964661264}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
--- !u!1 &1047473546
GameObject:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
serializedVersion: 6
m_Component:
- component: {fileID: 1047473547}
- component: {fileID: 1047473549}
- component: {fileID: 1047473548}
m_Layer: 5
m_Name: Title
m_TagString: Untagged
m_Icon: {fileID: 0}
m_NavMeshLayer: 0
m_StaticEditorFlags: 0
m_IsActive: 1
--- !u!224 &1047473547
RectTransform:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1047473546}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: []
m_Father: {fileID: 1742646164}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 31.5, y: -31.5}
m_SizeDelta: {x: 437, y: 35}
m_Pivot: {x: 0, y: 1}
--- !u!114 &1047473548
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1047473546}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: f4688fdb7df04437aeb418b961361dc5, type: 3}
m_Name:
m_EditorClassIdentifier:
m_Material: {fileID: 0}
m_Color: {r: 1, g: 1, b: 1, a: 1}
m_RaycastTarget: 1
m_RaycastPadding: {x: 0, y: 0, z: 0, w: 0}
m_Maskable: 1
m_OnCullStateChanged:
m_PersistentCalls:
m_Calls: []
m_text: Title
m_isRightToLeft: 0
m_fontAsset: {fileID: 11400000, guid: 3e9223a74cf8f5147ba8ec739992abf8, type: 2}
m_sharedMaterial: {fileID: -983720085404516624, guid: 3e9223a74cf8f5147ba8ec739992abf8, type: 2}
m_fontSharedMaterials: []
m_fontMaterial: {fileID: 0}
m_fontMaterials: []
m_fontColor32:
serializedVersion: 2
rgba: 4294967295
m_fontColor: {r: 1, g: 1, b: 1, a: 1}
m_enableVertexGradient: 0
m_colorMode: 3
m_fontColorGradient:
topLeft: {r: 1, g: 1, b: 1, a: 1}
topRight: {r: 1, g: 1, b: 1, a: 1}
bottomLeft: {r: 1, g: 1, b: 1, a: 1}
bottomRight: {r: 1, g: 1, b: 1, a: 1}
m_fontColorGradientPreset: {fileID: 0}
m_spriteAsset: {fileID: 0}
m_tintAllSprites: 0
m_StyleSheet: {fileID: 0}
m_TextStyleHashCode: -1183493901
m_overrideHtmlColors: 0
m_faceColor:
serializedVersion: 2
rgba: 4294967295
m_fontSize: 23
m_fontSizeBase: 23
m_fontWeight: 400
m_enableAutoSizing: 0
m_fontSizeMin: 18
m_fontSizeMax: 72
m_fontStyle: 0
m_HorizontalAlignment: 1
m_VerticalAlignment: 8192
m_textAlignment: 65535
m_characterSpacing: 0
m_wordSpacing: 0
m_lineSpacing: 0
m_lineSpacingMax: 0
m_paragraphSpacing: 0
m_charWidthMaxAdj: 0
m_enableWordWrapping: 1
m_wordWrappingRatios: 0.4
m_overflowMode: 0
m_linkedTextComponent: {fileID: 0}
parentLinkedComponent: {fileID: 0}
m_enableKerning: 1
m_enableExtraPadding: 0
checkPaddingRequired: 0
m_isRichText: 1
m_parseCtrlCharacters: 1
m_isOrthographic: 1
m_isCullingEnabled: 0
m_horizontalMapping: 0
m_verticalMapping: 0
m_uvLineOffset: 0
m_geometrySortingOrder: 0
m_IsTextObjectScaleStatic: 0
m_VertexBufferAutoSizeReduction: 0
m_useMaxVisibleDescender: 1
m_pageToDisplay: 1
m_margin: {x: 0, y: 0, z: 0, w: 0}
m_isUsingLegacyAnimationComponent: 0
m_isVolumetricText: 0
m_hasFontAssetChanged: 0
m_baseMaterial: {fileID: 0}
m_maskOffset: {x: 0, y: 0, z: 0, w: 0}
--- !u!222 &1047473549
CanvasRenderer:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1047473546}
m_CullTransparentMesh: 1
--- !u!1 &1062579969 --- !u!1 &1062579969
GameObject: GameObject:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -2539,6 +2942,7 @@ RectTransform:
m_LocalScale: {x: 0, y: 0, z: 0} m_LocalScale: {x: 0, y: 0, z: 0}
m_Children: m_Children:
- {fileID: 1982289467} - {fileID: 1982289467}
- {fileID: 1742646164}
- {fileID: 179607049} - {fileID: 179607049}
m_Father: {fileID: 0} m_Father: {fileID: 0}
m_RootOrder: 3 m_RootOrder: 3
@ -3398,13 +3802,14 @@ GameObject:
- component: {fileID: 1742646164} - component: {fileID: 1742646164}
- component: {fileID: 1742646166} - component: {fileID: 1742646166}
- component: {fileID: 1742646165} - component: {fileID: 1742646165}
- component: {fileID: 1742646167}
m_Layer: 5 m_Layer: 5
m_Name: Tooltip m_Name: Tooltip
m_TagString: Untagged m_TagString: Untagged
m_Icon: {fileID: 0} m_Icon: {fileID: 0}
m_NavMeshLayer: 0 m_NavMeshLayer: 0
m_StaticEditorFlags: 0 m_StaticEditorFlags: 0
m_IsActive: 0 m_IsActive: 1
--- !u!224 &1742646164 --- !u!224 &1742646164
RectTransform: RectTransform:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3412,18 +3817,21 @@ RectTransform:
m_PrefabInstance: {fileID: 0} m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1742646163} m_GameObject: {fileID: 1742646163}
m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} m_LocalRotation: {x: -0, y: -0, z: -0, w: 1}
m_LocalPosition: {x: 0, y: 0, z: 0} m_LocalPosition: {x: 0, y: 0, z: 0}
m_LocalScale: {x: 1, y: 1, z: 1} m_LocalScale: {x: 1, y: 1, z: 1}
m_Children: [] m_Children:
m_Father: {fileID: 179607049} - {fileID: 1047473547}
- {fileID: 928746190}
- {fileID: 581002076}
m_Father: {fileID: 1293669686}
m_RootOrder: 1 m_RootOrder: 1
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
m_AnchorMin: {x: 0.5, y: 0.5} m_AnchorMin: {x: 0, y: 1}
m_AnchorMax: {x: 0.5, y: 0.5} m_AnchorMax: {x: 0, y: 1}
m_AnchoredPosition: {x: 176.98238, y: -12.080708} m_AnchoredPosition: {x: 0, y: 0}
m_SizeDelta: {x: 503.9648, y: 174.1614} m_SizeDelta: {x: 500, y: 300}
m_Pivot: {x: 0.5, y: 0.5} m_Pivot: {x: 0, y: 1}
--- !u!114 &1742646165 --- !u!114 &1742646165
MonoBehaviour: MonoBehaviour:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0
@ -3462,6 +3870,18 @@ CanvasRenderer:
m_PrefabAsset: {fileID: 0} m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1742646163} m_GameObject: {fileID: 1742646163}
m_CullTransparentMesh: 1 m_CullTransparentMesh: 1
--- !u!114 &1742646167
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInstance: {fileID: 0}
m_PrefabAsset: {fileID: 0}
m_GameObject: {fileID: 1742646163}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: 7cc05ddf3fde8834ba40b0f1d6b2d430, type: 3}
m_Name:
m_EditorClassIdentifier:
--- !u!1001 &1769162367 --- !u!1001 &1769162367
PrefabInstance: PrefabInstance:
m_ObjectHideFlags: 0 m_ObjectHideFlags: 0

View File

@ -1,4 +1,5 @@
using TMPro; using TMPro;
using UnityEditor;
using UnityEngine; using UnityEngine;
using UnityEngine.UI; using UnityEngine.UI;
@ -10,6 +11,9 @@ public class InventoryDisplay : MonoBehaviour
private Image background; private Image background;
private readonly object TOOLTIP_LOCK = new object();
private Tooltip tooltip;
private void Awake() private void Awake()
{ {
Transform slotsRoot = transform.Find("Slots"); Transform slotsRoot = transform.Find("Slots");
@ -24,16 +28,73 @@ public class InventoryDisplay : MonoBehaviour
background = GetComponent<Image>(); background = GetComponent<Image>();
player = FindObjectOfType<PlayerController>(); player = FindObjectOfType<PlayerController>();
tooltip = FindObjectOfType<Tooltip>();
} }
private void Update() private void Update()
{ {
bool active = Input.GetKey(KeyCode.E); bool active = Input.GetKey(KeyCode.E);
for (int i = 0; i < transform.childCount; i++) transform.GetChild(i).gameObject.SetActive(active); for (int i = 0; i < transform.childCount; i++)
{
transform.GetChild(i).gameObject.SetActive(active);
}
background.enabled = active; background.enabled = active;
if (active) RefreshInventory(); if (active)
{
RefreshInventory();
TickTooltip();
}
else tooltip.RemoveRequest(TOOLTIP_LOCK);
}
private void TickTooltip()
{
Vector2 mousePos = Input.mousePosition;
int hovering = -1;
for (int i = 0; i < displays.Length; i++)
{
Image img = displays[i];
Vector2 min = img.rectTransform.position,
max = min + img.rectTransform.sizeDelta;
Debug.Log(img.rectTransform.sizeDelta);
if (min.x > max.x) (min.x, max.x) = (max.x, min.x);
if (min.y > max.y) (min.y, max.y) = (max.y, min.y);
if (mousePos.x >= min.x && mousePos.x <= max.x &&
mousePos.y >= min.y && mousePos.y <= max.y)
{
hovering = i;
break;
}
}
if (hovering == -1 || hovering >= player.Inventory.ItemSlots.Count)
{
tooltip.RemoveRequest(TOOLTIP_LOCK);
return;
}
ItemSlot slot = player.Inventory.ItemSlots[hovering];
if (slot.Item == null)
{
tooltip.RemoveRequest(TOOLTIP_LOCK);
return;
}
Tooltip.Request request = new Tooltip.Request()
{
Reference = TOOLTIP_LOCK,
Priority = 10,
Title = slot.Item.HumanName,
Content = slot.Item.Description,
Footer = $"{slot.Count} / {slot.Item.MaxSlotSize}",
Position = null,
};
tooltip.SetRequest(request);
} }
public void RefreshInventory() public void RefreshInventory()

View File

@ -0,0 +1,72 @@
using System.Collections.Generic;
using TMPro;
using UnityEngine;
using UnityEngine.UI;
public class Tooltip : Singleton<Tooltip>
{
private List<Request> requests;
private Image background;
private TextMeshProUGUI title, content, footer;
protected override void Awake()
{
base.Awake();
requests = new List<Request>();
background = GetComponent<Image>();
title = transform.Find("Title").GetComponent<TextMeshProUGUI>();
content = transform.Find("Content").GetComponent<TextMeshProUGUI>();
footer = transform.Find("Footer").GetComponent<TextMeshProUGUI>();
}
private bool setToMousePos = true;
private void Update()
{
Color desiredColor;
Vector2 desiredPos = transform.position;
if (requests.Count > 0)
{
desiredColor = Color.white;
Request priority = requests[0];
title.text = priority.Title;
content.text = priority.Content;
footer.text = priority.Footer;
if (priority.Position.HasValue)
{
desiredPos = priority.Position.Value;
setToMousePos = false;
}
else setToMousePos = true;
}
else desiredColor = new Color(1, 1, 1, 0);
if (setToMousePos) desiredPos = Input.mousePosition;
background.color = Color.Lerp(background.color, desiredColor, Time.deltaTime * 10);
title.color = Color.Lerp(title.color, desiredColor, Time.deltaTime * 10);
content.color = Color.Lerp(content.color, desiredColor, Time.deltaTime * 10);
footer.color = Color.Lerp(footer.color, desiredColor, Time.deltaTime * 10);
transform.position = Vector2.Lerp(transform.position, desiredPos, Time.deltaTime * 10);
}
public void SetRequest(Request request)
{
requests.Add(request);
requests.Sort((a, b) => a.Priority.CompareTo(b.Priority));
}
public void RemoveRequest(object reference) => requests.RemoveAll(x => x.Reference == reference);
public class Request
{
public object Reference;
public int Priority;
public string Title;
public string Content;
public string Footer;
public Vector2? Position;
}
}

View File

@ -0,0 +1,11 @@
fileFormatVersion: 2
guid: 7cc05ddf3fde8834ba40b0f1d6b2d430
MonoImporter:
externalObjects: {}
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: