From 9c31bcc303078eb8d4b5ad39cb1ba02cb2a64c41 Mon Sep 17 00:00:00 2001 From: s-prechtl Date: Thu, 9 Jun 2022 00:01:48 +0200 Subject: [PATCH] Meta and stuff --- Assets/Farming Asset Pack/Split Assets.meta | 8 ++ Assets/Resources/Items/Fish.asset | 19 +++ Assets/Resources/Items/Fish.asset.meta | 8 ++ Assets/Resources/Items/Usable/Shovel.asset | 20 +++ .../Resources/Items/Usable/Shovel.asset.meta | 8 ++ Assets/Scripts/FishingController.cs | 114 ++++++++++++++++++ Assets/Scripts/FishingController.cs.meta | 11 ++ Assets/Scripts/ItemContainer.cs | 12 +- 8 files changed, 197 insertions(+), 3 deletions(-) create mode 100644 Assets/Farming Asset Pack/Split Assets.meta create mode 100644 Assets/Resources/Items/Fish.asset create mode 100644 Assets/Resources/Items/Fish.asset.meta create mode 100644 Assets/Resources/Items/Usable/Shovel.asset create mode 100644 Assets/Resources/Items/Usable/Shovel.asset.meta create mode 100644 Assets/Scripts/FishingController.cs create mode 100644 Assets/Scripts/FishingController.cs.meta diff --git a/Assets/Farming Asset Pack/Split Assets.meta b/Assets/Farming Asset Pack/Split Assets.meta new file mode 100644 index 0000000..658129b --- /dev/null +++ b/Assets/Farming Asset Pack/Split Assets.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: f8e433f0b06051243aaf8575a862a7e4 +folderAsset: yes +DefaultImporter: + externalObjects: {} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Resources/Items/Fish.asset b/Assets/Resources/Items/Fish.asset new file mode 100644 index 0000000..f9a3583 --- /dev/null +++ b/Assets/Resources/Items/Fish.asset @@ -0,0 +1,19 @@ +%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: 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/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/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/Scripts/FishingController.cs b/Assets/Scripts/FishingController.cs new file mode 100644 index 0000000..a7fcb1c --- /dev/null +++ b/Assets/Scripts/FishingController.cs @@ -0,0 +1,114 @@ +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; + +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 + + 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 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) { //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 { + _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 = 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) { + Debug.Log("Caught!"); + Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Fish"), (int)(3 / _fishingTime)); + ResetFishing(); + } else { + Debug.Log("Failed to catch!"); + _catchable = false; + _fishingTime = 0f; + _exMark.SetActive(false); + _fishCooldown = Random.Range(_minFishCooldown+2, _maxFishCooldown); + } + } + } +} \ 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/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; } }