From 1a12d986c4ea8078b99ef17739023ec25d98d3f5 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Wed, 8 Jun 2022 11:44:22 +0200 Subject: [PATCH 1/3] WaterTile.cs + Shovel.asset --- Assets/Resources/Items/Usable/Shovel.asset | 20 +++++++++ .../Resources/Items/Usable/Shovel.asset.meta | 8 ++++ Assets/Scenes/MainScene.unity | 10 ++--- Assets/Scripts/Tiles/BaseTile.cs | 2 +- Assets/Scripts/Tiles/GrassTile.cs | 6 ++- Assets/Scripts/Tiles/WaterTile.cs | 41 ++++++++++++++++--- 6 files changed, 72 insertions(+), 15 deletions(-) create mode 100644 Assets/Resources/Items/Usable/Shovel.asset create mode 100644 Assets/Resources/Items/Usable/Shovel.asset.meta diff --git a/Assets/Resources/Items/Usable/Shovel.asset b/Assets/Resources/Items/Usable/Shovel.asset new file mode 100644 index 0000000..1168f1d --- /dev/null +++ b/Assets/Resources/Items/Usable/Shovel.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 761f645f009328845bc7851753024e92, type: 3} + m_Name: Shovel + m_EditorClassIdentifier: + displayName: Shovel + description: Used to dig ground. + id: 6 + selectedSprite: {fileID: 21300000, guid: 58952d7ae1da0f0468af9c9d916af2fc, type: 3} + defaultSprite: {fileID: 21300000, guid: 1ea3a182dfc173440993d81065fdbdf0, type: 3} + cost: 200 diff --git a/Assets/Resources/Items/Usable/Shovel.asset.meta b/Assets/Resources/Items/Usable/Shovel.asset.meta new file mode 100644 index 0000000..600d315 --- /dev/null +++ b/Assets/Resources/Items/Usable/Shovel.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 6bac44b5c4527b641a3ae772d217ec43 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 5e7dacb..e640feb 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1536,7 +1536,7 @@ MonoBehaviour: m_HandleRect: {fileID: 2006577138} m_Direction: 2 m_Value: 1 - m_Size: 0.59324205 + m_Size: 0.5932421 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -6516,6 +6516,7 @@ MonoBehaviour: - {fileID: 11400000, guid: bb9777a7d5804bd6bf25d5510206aaf0, type: 2} - {fileID: 11400000, guid: bb9777a7d5804bd6bf25d5510206aaf0, type: 2} - {fileID: 11400000, guid: 008a8fdd2c3a95745acafee4087a855d, type: 2} + - {fileID: 11400000, guid: 6bac44b5c4527b641a3ae772d217ec43, type: 2} --- !u!1001 &1701153146 PrefabInstance: m_ObjectHideFlags: 0 @@ -6790,6 +6791,7 @@ MonoBehaviour: - {fileID: 11400000, guid: 008a8fdd2c3a95745acafee4087a855d, type: 2} - {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2} - {fileID: 11400000, guid: ea1a26b19bc34a0ba29bad77253c7266, type: 2} + - {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2} --- !u!114 &1800469992 MonoBehaviour: m_ObjectHideFlags: 0 @@ -6802,12 +6804,6 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 05183797fdda4aa9ac518eee0d2d85d4, type: 3} m_Name: m_EditorClassIdentifier: - allItems: - - {fileID: 11400000, guid: bb9777a7d5804bd6bf25d5510206aaf0, type: 2} - - {fileID: 11400000, guid: d651d57ba97a4246a0094409e29fe56a, type: 2} - - {fileID: 11400000, guid: 430db451ae959f34b8fba8d8b17276fd, type: 2} - - {fileID: 11400000, guid: 008a8fdd2c3a95745acafee4087a855d, type: 2} - - {fileID: 11400000, guid: ea1a26b19bc34a0ba29bad77253c7266, type: 2} --- !u!1001 &1805366398 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Tiles/BaseTile.cs b/Assets/Scripts/Tiles/BaseTile.cs index 0b5d34f..77df98a 100644 --- a/Assets/Scripts/Tiles/BaseTile.cs +++ b/Assets/Scripts/Tiles/BaseTile.cs @@ -31,7 +31,7 @@ namespace Tiles public virtual BaseTile Clicked(UsableItem usable) { - Debug.Log(usable.ToString() + " used on " + this.ToString()); + Debug.Log(usable + " used on " + this); return null; } diff --git a/Assets/Scripts/Tiles/GrassTile.cs b/Assets/Scripts/Tiles/GrassTile.cs index 56b4fc7..3dba8bc 100644 --- a/Assets/Scripts/Tiles/GrassTile.cs +++ b/Assets/Scripts/Tiles/GrassTile.cs @@ -16,12 +16,14 @@ namespace Tiles /// a subclass of BaseTile if the Tile has to change, null if it stays the same type public override BaseTile Clicked(UsableItem usable) { BaseTile rv = null; + ItemContainer ic = ItemContainer.Instance; if (usable != null) { base.Clicked(usable); - if (usable.id == ItemContainer.Instance.GetItemIdByName(new string("Hoe"))) - { + if (usable.id == ic.GetItemIdByName("Hoe")) { rv = new FarmlandTile(); + } else if (usable.id == ic.GetItemIdByName("Shovel")) { + rv = new WaterTile(); } } return rv; diff --git a/Assets/Scripts/Tiles/WaterTile.cs b/Assets/Scripts/Tiles/WaterTile.cs index 37afdd7..3ddd957 100644 --- a/Assets/Scripts/Tiles/WaterTile.cs +++ b/Assets/Scripts/Tiles/WaterTile.cs @@ -1,11 +1,42 @@ -using UnityEngine; +using System.Collections; +using UnityEngine; namespace Tiles { - public class WaterTile : BaseTile - { - public WaterTile() : base(null) - { + public class WaterTile : BaseTile { + private double _fishingTime; + private bool _fishing = false; + private bool _catchable = false; + private int _lastCall = 0; + public WaterTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_023.png") { + } + + public override BaseTile Clicked(UsableItem usable) { + base.Clicked(usable); + + ItemContainer ic = ItemContainer.Instance; + + if (usable.id == ic.GetItemIdByName("Fishing Rod")) { + if (!_fishing) { + _fishing = true; + _fishingTime = 0f; + Fish(); + } else if (_catchable) { + _fishing = false; + Debug.Log("Fished for" + _fishingTime/1000); + } +} + + return null; + } + + private void Fish() { + if (_fishing) { + if (_catchable) { + // _fishingTime += _lastCall - System.DateTime.Now; deltaTime between last recursive call + } + //Fish(); + } } } From 9e91220be4d574892a8b8f864d5f37d2bc4fd6ef Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Wed, 8 Jun 2022 22:19:40 +0200 Subject: [PATCH 2/3] Major Fishing changes --- Assets/Resources/Items/Fish.asset | 20 ++++++ Assets/Resources/Items/Fish.asset.meta | 8 +++ Assets/Scenes/MainScene.unity | 15 ++++- Assets/Scripts/FishingController.cs | 82 ++++++++++++++++++++++++ Assets/Scripts/FishingController.cs.meta | 11 ++++ Assets/Scripts/Item.cs | 16 +++-- Assets/Scripts/ItemContainer.cs | 12 +++- Assets/Scripts/Tiles/BaseTile.cs | 10 --- Assets/Scripts/Tiles/FarmlandTile.cs | 6 +- Assets/Scripts/Tiles/GrassTile.cs | 4 +- Assets/Scripts/Tiles/WaterTile.cs | 38 ++++------- 11 files changed, 173 insertions(+), 49 deletions(-) create mode 100644 Assets/Resources/Items/Fish.asset create mode 100644 Assets/Resources/Items/Fish.asset.meta create mode 100644 Assets/Scripts/FishingController.cs create mode 100644 Assets/Scripts/FishingController.cs.meta diff --git a/Assets/Resources/Items/Fish.asset b/Assets/Resources/Items/Fish.asset new file mode 100644 index 0000000..42befb7 --- /dev/null +++ b/Assets/Resources/Items/Fish.asset @@ -0,0 +1,20 @@ +%YAML 1.1 +%TAG !u! tag:unity3d.com,2011: +--- !u!114 &11400000 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 0} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 5f096d187f76a734fac022700054dfec, type: 3} + m_Name: Fish + m_EditorClassIdentifier: + displayName: + description: + id: 0 + selectedSprite: {fileID: 0} + defaultSprite: {fileID: 0} + cost: 0 diff --git a/Assets/Resources/Items/Fish.asset.meta b/Assets/Resources/Items/Fish.asset.meta new file mode 100644 index 0000000..1b1f709 --- /dev/null +++ b/Assets/Resources/Items/Fish.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 7fc4aaa640c1c1e49a0c0a9241fbcf07 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index e640feb..7f760e9 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1536,7 +1536,7 @@ MonoBehaviour: m_HandleRect: {fileID: 2006577138} m_Direction: 2 m_Value: 1 - m_Size: 0.5932421 + m_Size: 0.59324205 m_NumberOfSteps: 0 m_OnValueChanged: m_PersistentCalls: @@ -6739,6 +6739,7 @@ GameObject: - component: {fileID: 1800469989} - component: {fileID: 1800469991} - component: {fileID: 1800469992} + - component: {fileID: 1800469993} m_Layer: 0 m_Name: Player m_TagString: Untagged @@ -6804,6 +6805,18 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 05183797fdda4aa9ac518eee0d2d85d4, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &1800469993 +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: 00d85fb65e728cd429cb33d865a5d31a, type: 3} + m_Name: + m_EditorClassIdentifier: --- !u!1001 &1805366398 PrefabInstance: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/FishingController.cs b/Assets/Scripts/FishingController.cs new file mode 100644 index 0000000..be98cd6 --- /dev/null +++ b/Assets/Scripts/FishingController.cs @@ -0,0 +1,82 @@ +using System; +using System.Collections; +using System.Collections.Generic; +using System.Data.Common; +using UnityEngine; +using Random = UnityEngine.Random; + +public class FishingController : MonoBehaviour { + #region Singleton + + public static FishingController instance; + + private void Awake() { + if (instance != null) { + Debug.LogWarning("More than one instance of FishingController found"); + } + + instance = this; + } + + #endregion + + private double _fishingTime; + private bool _fishing; + private bool _catchable; + private bool _caught; + private double _fishCooldown; + private readonly double _totalFishCooldown = 1.5f; + private readonly double _maxTime = 2f; + private bool _spawnFish; + + public bool Fishing => _fishing; + + // Start is called before the first frame update + void Start() { + ResetFishing(); + } + + // Update is called once per frame + void Update() { + if (_fishing) { + if (!_catchable) { + _fishCooldown += Time.deltaTime; + if (_spawnFish && _fishCooldown >= _totalFishCooldown && Random.Range(0, 100) <= 1) { + _spawnFish = false; + //particles for fish -> catchable true + + } + } else { + if (!_caught) { + _fishingTime += Time.deltaTime; + } + } + } + } + + private void ResetFishing() { + _fishing = false; + _catchable = false; + _fishingTime = 0f; + _fishCooldown = 1.5f; + _spawnFish = true; + } + + public void StartFishing() { + _fishing = true; + } + + public void TryCatch() { + if (_fishing && _catchable) { + if (_fishingTime <= _maxTime) { + _fishing = false; + _caught = true; + Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3/_fishingTime)); + } else { + _spawnFish = true; + _catchable = false; + _fishingTime = 0f; + } + } + } +} \ No newline at end of file diff --git a/Assets/Scripts/FishingController.cs.meta b/Assets/Scripts/FishingController.cs.meta new file mode 100644 index 0000000..486f755 --- /dev/null +++ b/Assets/Scripts/FishingController.cs.meta @@ -0,0 +1,11 @@ +fileFormatVersion: 2 +guid: 00d85fb65e728cd429cb33d865a5d31a +MonoImporter: + externalObjects: {} + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scripts/Item.cs b/Assets/Scripts/Item.cs index 1e50d59..66ee52b 100644 --- a/Assets/Scripts/Item.cs +++ b/Assets/Scripts/Item.cs @@ -5,18 +5,26 @@ using UnityEngine; public class Item : ScriptableObject, IComparable { public string displayName; public string description; - public int id; //TODO: create an actual ID System that makes snens + private int _id = -1; public Sprite selectedSprite; public Sprite defaultSprite; public int cost; - + + public int ID => _id; + public Item(string displayName, string description, int id) { this.displayName = displayName; this.description = description; - this.id = id; + this._id = id; } public int CompareTo(Item other) { - return this.id - other.id; + return this._id - other._id; + } + + public void SetID(int id) { + if (_id != -1) { + _id = id; + } } } diff --git a/Assets/Scripts/ItemContainer.cs b/Assets/Scripts/ItemContainer.cs index e0b84d5..1ed56b2 100644 --- a/Assets/Scripts/ItemContainer.cs +++ b/Assets/Scripts/ItemContainer.cs @@ -26,8 +26,10 @@ public class ItemContainer : MonoBehaviour { string[] files = Directory.GetFiles("Assets\\Resources\\Items", "*.asset", SearchOption.AllDirectories); foreach (string file in files) { - String path = file.Replace("Assets\\Resources\\", "").Replace(".asset", ""); - _allItems.Add(Resources.Load(path)); + String path = StripPath(file); + Item currItem = Resources.Load(path); + currItem.SetID(_allItems.Count); + _allItems.Add(currItem); } } @@ -41,7 +43,11 @@ public class ItemContainer : MonoBehaviour { return null; } + private String StripPath(String path) { + return path.Replace("Assets\\Resources\\", "").Replace(".asset", ""); + } + public int GetItemIdByName(String name) { - return GetItemByName(name).id; + return GetItemByName(name).ID; } } diff --git a/Assets/Scripts/Tiles/BaseTile.cs b/Assets/Scripts/Tiles/BaseTile.cs index 77df98a..11eeaa3 100644 --- a/Assets/Scripts/Tiles/BaseTile.cs +++ b/Assets/Scripts/Tiles/BaseTile.cs @@ -14,16 +14,6 @@ namespace Tiles this._sprite = GenerateSpriteFromFile(pathToImageFile); } - protected void Start() - { - - } - - protected void Update() - { - - } - public void DayLightStep() { diff --git a/Assets/Scripts/Tiles/FarmlandTile.cs b/Assets/Scripts/Tiles/FarmlandTile.cs index 7ad967c..27c0ef1 100644 --- a/Assets/Scripts/Tiles/FarmlandTile.cs +++ b/Assets/Scripts/Tiles/FarmlandTile.cs @@ -21,18 +21,18 @@ namespace Tiles ItemContainer ic = ItemContainer.Instance; - if (usable.id == ic.GetItemIdByName("Hoe")) + if (usable.ID == ic.GetItemIdByName("Hoe")) { Debug.Log("Farmland hydrated"); //_hydrated = true; } - if (usable.id == ic.GetItemIdByName("Wheat Seed") && _crop == null) + if (usable.ID == ic.GetItemIdByName("Wheat Seed") && _crop == null) { Plant(); } - if (usable.id == ic.GetItemIdByName("Scythe") && _crop != null && _crop.FullyGrown) + if (usable.ID == ic.GetItemIdByName("Scythe") && _crop != null && _crop.FullyGrown) { Harvest(); } diff --git a/Assets/Scripts/Tiles/GrassTile.cs b/Assets/Scripts/Tiles/GrassTile.cs index 3dba8bc..2902e7a 100644 --- a/Assets/Scripts/Tiles/GrassTile.cs +++ b/Assets/Scripts/Tiles/GrassTile.cs @@ -20,9 +20,9 @@ namespace Tiles if (usable != null) { base.Clicked(usable); - if (usable.id == ic.GetItemIdByName("Hoe")) { + if (usable.ID == ic.GetItemIdByName("Hoe")) { rv = new FarmlandTile(); - } else if (usable.id == ic.GetItemIdByName("Shovel")) { + } else if (usable.ID == ic.GetItemIdByName("Shovel")) { rv = new WaterTile(); } } diff --git a/Assets/Scripts/Tiles/WaterTile.cs b/Assets/Scripts/Tiles/WaterTile.cs index 3ddd957..4781be3 100644 --- a/Assets/Scripts/Tiles/WaterTile.cs +++ b/Assets/Scripts/Tiles/WaterTile.cs @@ -1,43 +1,29 @@ using System.Collections; using UnityEngine; -namespace Tiles -{ +namespace Tiles { public class WaterTile : BaseTile { - private double _fishingTime; - private bool _fishing = false; - private bool _catchable = false; - private int _lastCall = 0; public WaterTile() : base("Assets/Farming Asset Pack/Split Assets/farming_tileset_023.png") { } public override BaseTile Clicked(UsableItem usable) { base.Clicked(usable); + BaseTile rv = null; ItemContainer ic = ItemContainer.Instance; - if (usable.id == ic.GetItemIdByName("Fishing Rod")) { - if (!_fishing) { - _fishing = true; - _fishingTime = 0f; - Fish(); - } else if (_catchable) { - _fishing = false; - Debug.Log("Fished for" + _fishingTime/1000); + if (usable.ID == ic.GetItemIdByName("Fishing Rod")) { + FishingController fc = FishingController.instance; + if (!fc.Fishing) { + fc.StartFishing(); + } else { + fc.TryCatch(); } -} - - return null; - } - - private void Fish() { - if (_fishing) { - if (_catchable) { - // _fishingTime += _lastCall - System.DateTime.Now; deltaTime between last recursive call - } - //Fish(); + } else if (usable.ID == ic.GetItemIdByName("Shovel")) { + rv = new GrassTile(); } - + + return rv; } } } \ No newline at end of file From cf8851745d823d6ff4781ec735ea5eb190be80ac Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Wed, 8 Jun 2022 23:55:17 +0200 Subject: [PATCH 3/3] FishingController.cs finished --- Assets/Resources/Items/Fish.asset | 11 +- Assets/Scenes/MainScene.unity | 214 ++++++++++++++++++++++++++++ Assets/Scripts/FishingController.cs | 72 +++++++--- 3 files changed, 271 insertions(+), 26 deletions(-) diff --git a/Assets/Resources/Items/Fish.asset b/Assets/Resources/Items/Fish.asset index 42befb7..f9a3583 100644 --- a/Assets/Resources/Items/Fish.asset +++ b/Assets/Resources/Items/Fish.asset @@ -12,9 +12,8 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 5f096d187f76a734fac022700054dfec, type: 3} m_Name: Fish m_EditorClassIdentifier: - displayName: - description: - id: 0 - selectedSprite: {fileID: 0} - defaultSprite: {fileID: 0} - cost: 0 + displayName: Fish + description: Used to slap people. + selectedSprite: {fileID: 21300000, guid: 8c01c1a230575ac4bb0aee5ba1c7757a, type: 3} + defaultSprite: {fileID: 21300000, guid: d1b54b7f17e2d4d4e82d50d710d4482c, type: 3} + cost: 150 diff --git a/Assets/Scenes/MainScene.unity b/Assets/Scenes/MainScene.unity index 7f760e9..0471522 100644 --- a/Assets/Scenes/MainScene.unity +++ b/Assets/Scenes/MainScene.unity @@ -1972,6 +1972,83 @@ CanvasRenderer: m_PrefabAsset: {fileID: 0} m_GameObject: {fileID: 656110740} m_CullTransparentMesh: 1 +--- !u!1 &656860534 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 656860535} + - component: {fileID: 656860537} + - component: {fileID: 656860536} + m_Layer: 5 + m_Name: FishingParent + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &656860535 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 656860534} + 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: 2090400144} + m_Father: {fileID: 1061398534} + m_RootOrder: 2 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0, y: 1} + m_AnchorMax: {x: 0, y: 1} + m_AnchoredPosition: {x: 40, y: -179.4} + m_SizeDelta: {x: 50, y: 50} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &656860536 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 656860534} + 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: 349d3f5d7a4156146b8e923d5c06314d, 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 &656860537 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 656860534} + m_CullTransparentMesh: 1 --- !u!1001 &729139770 PrefabInstance: m_ObjectHideFlags: 0 @@ -3652,6 +3729,7 @@ RectTransform: m_Children: - {fileID: 1070476668} - {fileID: 1649897726} + - {fileID: 656860535} m_Father: {fileID: 0} m_RootOrder: 9 m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} @@ -6817,6 +6895,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 00d85fb65e728cd429cb33d865a5d31a, type: 3} m_Name: m_EditorClassIdentifier: + _exMark: {fileID: 656860534} --- !u!1001 &1805366398 PrefabInstance: m_ObjectHideFlags: 0 @@ -7986,6 +8065,141 @@ PrefabInstance: objectReference: {fileID: 0} m_RemovedComponents: [] m_SourcePrefab: {fileID: 100100000, guid: 44dae5fbdb6f7df4f93a10807f66956f, type: 3} +--- !u!1 &2090400143 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 2090400144} + - component: {fileID: 2090400146} + - component: {fileID: 2090400145} + m_Layer: 5 + m_Name: ExMark + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!224 &2090400144 +RectTransform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2090400143} + 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: 656860535} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} + m_AnchorMin: {x: 0.5, y: 0.5} + m_AnchorMax: {x: 0.5, y: 0.5} + m_AnchoredPosition: {x: 0, y: 0} + m_SizeDelta: {x: 50, y: 50} + m_Pivot: {x: 0.5, y: 0.5} +--- !u!114 &2090400145 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2090400143} + 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: '!' + 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: 4280045691 + m_fontColor: {r: 0.48235297, g: 0.3137255, b: 0.10980393, 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: 40 + m_fontSizeBase: 40 + m_fontWeight: 400 + m_enableAutoSizing: 0 + m_fontSizeMin: 18 + m_fontSizeMax: 72 + m_fontStyle: 9 + 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 &2090400146 +CanvasRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 2090400143} + m_CullTransparentMesh: 1 --- !u!1 &2091640948 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/FishingController.cs b/Assets/Scripts/FishingController.cs index be98cd6..a7fcb1c 100644 --- a/Assets/Scripts/FishingController.cs +++ b/Assets/Scripts/FishingController.cs @@ -2,6 +2,8 @@ using System; using System.Collections; using System.Collections.Generic; using System.Data.Common; +using System.Net.Mail; +using System.Threading; using UnityEngine; using Random = UnityEngine.Random; @@ -20,62 +22,92 @@ public class FishingController : MonoBehaviour { #endregion + public GameObject _exMark; + private double _fishingTime; + private double _fishCooldown; + private readonly float _minFishCooldown = 1.5f; + private readonly float _maxFishCooldown = 7f; + private readonly double _maxTime = 2f; private bool _fishing; private bool _catchable; private bool _caught; - private double _fishCooldown; - private readonly double _totalFishCooldown = 1.5f; - private readonly double _maxTime = 2f; - private bool _spawnFish; + private Vector2 _ampsXY; public bool Fishing => _fishing; // Start is called before the first frame update void Start() { ResetFishing(); + _ampsXY = new Vector2(10, 10); } // Update is called once per frame void Update() { - if (_fishing) { - if (!_catchable) { - _fishCooldown += Time.deltaTime; - if (_spawnFish && _fishCooldown >= _totalFishCooldown && Random.Range(0, 100) <= 1) { - _spawnFish = false; - //particles for fish -> catchable true - + if (_fishing) { //Fishing + if (!_catchable) { // Fish not spawned yet + _fishCooldown -= Time.deltaTime; + if (_fishCooldown <= 0) { //fish will get spawned + _catchable = true; + if (!_exMark.activeSelf) { + _exMark.SetActive(true); + } } } else { - if (!_caught) { - _fishingTime += Time.deltaTime; - } + _fishingTime += Time.deltaTime; + //NotifyShake(); } } } + private void NotifyShake() { + _exMark.transform.position = + new Vector3(_exMark.transform.position.x * _ampsXY.x * Time.deltaTime, + _exMark.transform.position.y * _ampsXY.y * Time.deltaTime, + transform.position.z); + _ampsXY.x *= -1; + _ampsXY.y *= -1; + } + private void ResetFishing() { _fishing = false; _catchable = false; _fishingTime = 0f; - _fishCooldown = 1.5f; - _spawnFish = true; + _fishCooldown = Random.Range(_minFishCooldown, _maxFishCooldown); + _exMark.SetActive(false); } public void StartFishing() { + Vector3 pos = Input.mousePosition; + + if (Camera.main != null) { + float newPosX = pos.x; + float newPosY; + + if (pos.y - 50 - ((RectTransform)_exMark.transform).rect.height >= 0) { //check if bottom of panel is in screen + newPosY = pos.y - ((RectTransform)_exMark.transform).rect.height; + } else { + newPosY = pos.y + ((RectTransform)_exMark.transform).rect.height; + } + + _exMark.transform.position = new Vector3(newPosX, newPosY); + } _fishing = true; } public void TryCatch() { if (_fishing && _catchable) { + Debug.Log("Tried to catch!"); if (_fishingTime <= _maxTime) { - _fishing = false; - _caught = true; - Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3/_fishingTime)); + Debug.Log("Caught!"); + Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3 / _fishingTime)); + ResetFishing(); } else { - _spawnFish = true; + Debug.Log("Failed to catch!"); _catchable = false; _fishingTime = 0f; + _exMark.SetActive(false); + _fishCooldown = Random.Range(_minFishCooldown+2, _maxFishCooldown); } } }