From 6d8233f33f512e13c616f1787c6fa814d0ef9dcd Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Fri, 10 Jun 2022 08:25:19 +0200 Subject: [PATCH 1/2] MessageBox new --- Assets/Scenes/MainScene.unity | 236 +++++++++++++++++++++++++++++++++- 1 file changed, 232 insertions(+), 4 deletions(-) diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 0096d11..cf70052 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1142,6 +1142,141 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} +--- !u!1 &216787472 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 216787473} + - component: {fileID: 216787475} + - component: {fileID: 216787474} + m_Layer: 5 + m_Name: MessageText + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &216787473 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 216787472} + 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_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 396232894} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 0} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: -40, y: -40} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &216787474 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 216787472} + 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: New Text + m_isRightToLeft: 0 + m_fontAsset: {fileID: 11400000, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_sharedMaterial: {fileID: 2180264, guid: 8f586378b4e144a9851e7b34d9b748ee, type: 2} + m_fontSharedMaterials: [] + m_fontMaterial: {fileID: 0} + m_fontMaterials: [] + m_fontColor32: + serializedVersion: 2 + rgba: 4280111227 + m_fontColor: {r: 0.48235297, g: 0.3137255, b: 0.1137255, 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: 53.7 + m_fontSizeBase: 36 + m_fontWeight: 400 + m_enableAutoSizing: 1 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 1 + m_HorizontalAlignment: 2 + m_VerticalAlignment: 512 + 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 &216787475 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 216787472} + m_CullTransparentMesh: 1 --- !u!224 &261459150 stripped RectTransform: m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} @@ -1367,6 +1502,83 @@ RectTransform: m_CorrespondingSourceObject: {fileID: 3510585822996971025, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} m_PrefabInstance: {fileID: 1868238650} m_PrefabAsset: {fileID: 0} +--- !u!1 &396232893 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 396232894} + - component: {fileID: 396232896} + - component: {fileID: 396232895} + m_Layer: 5 + m_Name: MessageParent + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &396232894 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 396232893} + 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_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 216787473} + m_Father: {fileID: 1061398534} + m_RootOrder: 3 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 1, y: 1} + m_AnchoredPosition: {x: 0, y: -105} + m_SizeDelta: {x: -800, y: 100} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &396232895 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 396232893} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: fe87c0e1cc204ed48ad3b37840f39efc, 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_Sprite: {fileID: 21300000, guid: 2a61ecc3d143def478dfed9f6d6ca3fd, type: 3} + m_Type: 1 + m_PreserveAspect: 0 + m_FillCenter: 1 + m_FillMethod: 4 + m_FillAmount: 1 + m_FillClockwise: 1 + m_FillOrigin: 0 + m_UseSpriteMesh: 0 + m_PixelsPerUnitMultiplier: 1 +--- !u!222 &396232896 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 396232893} + m_CullTransparentMesh: 1 --- !u!1 &401600531 GameObject: m_ObjectHideFlags: 0 @@ -1816,7 +2028,7 @@ MonoBehaviour: m_HandleRect: {fileID: 2006577138} m_Direction: 2 m_Value: 1 - m_Size: 0.53866136 + m_Size: 0.5386614 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -3662,7 +3874,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 18 + m_fontSize: 72 m_fontSizeBase: 40 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -4145,6 +4357,7 @@ RectTransform: - {fileID: 1070476668} - {fileID: 1649897726} - {fileID: 615358671} + - {fileID: 396232894} m_Father: {fileID: 0} m_RootOrder: 10 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -7521,6 +7734,7 @@ GameObject: - component: {fileID: 1800469991} - component: {fileID: 1800469992} - component: {fileID: 1800469993} + - component: {fileID: 1800469994} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -7597,6 +7811,20 @@ MonoBehaviour: m_Name: m_EditorClassIdentifier: exMark: {fileID: 615358670} +--- !u!114 &1800469994 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1800469988} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 226f2988544209541b54ccb2ebf036cd, type: 3} + m_Name: + m_EditorClassIdentifier: + messageView: {fileID: 396232893} + message: {fileID: 216787474} --- !u!1001 &1805366398 PrefabInstance: m_ObjectHideFlags: 0 @@ -7959,7 +8187,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 21.3 + m_fontSize: 72 m_fontSizeBase: 20 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -8611,7 +8839,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 21.3 + m_fontSize: 72 m_fontSizeBase: 20 m_fontWeight: 400 m_enableAutoSizing: 1 From 6f8f58566c277b88d438998cc6c43d0b3440f19f Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Fri, 10 Jun 2022 08:54:53 +0200 Subject: [PATCH 2/2] MessageView.cs no animation --- Assets/Scenes/MainScene.unity | 12 ++++++------ Assets/Scripts/FishingController.cs | 17 ++++++++--------- Assets/Scripts/MessageView.cs | 15 +++++++++++++-- 3 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index cf70052..4de9de7 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1561,7 +1561,7 @@ MonoBehaviour: m_OnCullStateChanged: m_PersistentCalls: m_Calls: [] - m_Sprite: {fileID: 21300000, guid: 2a61ecc3d143def478dfed9f6d6ca3fd, type: 3} + m_Sprite: {fileID: 21300000, guid: 349d3f5d7a4156146b8e923d5c06314d, type: 3} m_Type: 1 m_PreserveAspect: 0 m_FillCenter: 1 @@ -2028,7 +2028,7 @@ MonoBehaviour: m_HandleRect: {fileID: 2006577138} m_Direction: 2 m_Value: 1 - m_Size: 0.5386614 + m_Size: 0.5386615 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -2391,8 +2391,8 @@ RectTransform: m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} m_AnchorMin: {x: 0, y: 0} m_AnchorMax: {x: 1, y: 1} - m_AnchoredPosition: {x: -811, y: 348.5} - m_SizeDelta: {x: -1222, y: -697} + m_AnchoredPosition: {x: -811, y: 290} + m_SizeDelta: {x: -1222, y: -580} m_Pivot: {x: 0.5, y: 0.5} --- !u!114 &615358672 MonoBehaviour: @@ -8187,7 +8187,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 72 + m_fontSize: 29.25 m_fontSizeBase: 20 m_fontWeight: 400 m_enableAutoSizing: 1 @@ -8839,7 +8839,7 @@ MonoBehaviour: m_faceColor: serializedVersion: 2 rgba: 4294967295 - m_fontSize: 72 + m_fontSize: 29.25 m_fontSizeBase: 20 m_fontWeight: 400 m_enableAutoSizing: 1 diff --git a/Assets/Scripts/FishingController.cs b/Assets/Scripts/FishingController.cs index 37f4e9d..e339421 100644 --- a/Assets/Scripts/FishingController.cs +++ b/Assets/Scripts/FishingController.cs @@ -45,11 +45,13 @@ public class FishingController : MonoBehaviour { private Vector2 _ampsXY; private Inventory _iv; private ItemContainer _ic; + private MessageView _messageView; public bool Fishing => _fishing; // Start is called before the first frame update void Start() { + _messageView = MessageView.instance; ResetFishing(); _ampsXY = new Vector2(10, 10); _iv = Inventory.instance; @@ -59,7 +61,6 @@ public class FishingController : MonoBehaviour { // Update is called once per frame void Update() { if (_fishing) { //Fishing - if (!Catchable) { // Fish not spawned yet fishCooldown -= Time.deltaTime; @@ -88,7 +89,7 @@ public class FishingController : MonoBehaviour { public void StartFishing() { if (!_iv.items.ContainsKey(_ic.GetItemByName("Bait"))) { - Debug.Log("No bait!"); + _messageView.sendMessage("No bait!", 1.0f); return; } Vector3 pos = Input.mousePosition; @@ -107,21 +108,19 @@ public class FishingController : MonoBehaviour { } _fishing = true; _iv.RemoveItem(_ic.GetItemByName("Bait"), 1); + _messageView.sendMessage("Fishing started", 1.0f); + } public void TryCatch() { if (_fishing && Catchable) { - Debug.Log("Tried to catch!"); if (_fishingTime <= MaxTime) { - Debug.Log("Caught!"); + _messageView.sendMessage("Caught!", 1.5f); _iv.AddItem(_ic.GetItemByName("Fish"), Math.Max((int)(1 / (_fishingTime / 2)), 1)); - ResetFishing(); } else { - Debug.Log("Failed to catch!"); - _fishingTime = 0f; - exMark.SetActive(false); - fishCooldown = Random.Range(MinFishCooldown + 2, MaxFishCooldown); + _messageView.sendMessage("Failed to catch the fish! You were too slow!", 1.5f); } + ResetFishing(); } } } \ No newline at end of file diff --git a/Assets/Scripts/MessageView.cs b/Assets/Scripts/MessageView.cs index 49be9a9..32860a8 100644 --- a/Assets/Scripts/MessageView.cs +++ b/Assets/Scripts/MessageView.cs @@ -23,7 +23,18 @@ public class MessageView : MonoBehaviour public GameObject messageView; public TextMeshProUGUI message; - public void sendMessage(String msg, double duration) { - + private void Start() { + messageView.SetActive(false); + } + + public void sendMessage(String msg, float duration) { + message.text = msg; + StartCoroutine(showForSeconds(duration)); + } + + private IEnumerator showForSeconds(float duration) { + messageView.SetActive(true); + yield return new WaitForSeconds(duration); + messageView.SetActive(false); } }