diff --git a/Assets/Items/Crops/Apple.asset b/Assets/Items/Crops/Apple.asset new file mode 100644 index 0000000..d2c0222 --- /dev/null +++ b/Assets/Items/Crops/Apple.asset @@ -0,0 +1,27 @@ +%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: f00df81b4ec12f844a6f928d013437b2, type: 3} + m_Name: Apple + m_EditorClassIdentifier: + uuid: apple + itemName: Apple Crop + sprite: {fileID: -992969038, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + stackable: 0 + maxStackSize: 1 + daysToGrow: 6 + sprites: + - {fileID: -1568493089, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + - {fileID: 1918686608, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + - {fileID: -400346732, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + - {fileID: -1058307475, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + - {fileID: -1664452952, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + - {fileID: 1402415594, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} diff --git a/Assets/Items/Crops/Apple.asset.meta b/Assets/Items/Crops/Apple.asset.meta new file mode 100644 index 0000000..cd719cb --- /dev/null +++ b/Assets/Items/Crops/Apple.asset.meta @@ -0,0 +1,8 @@ +fileFormatVersion: 2 +guid: 4ce577b0996dc314ab1b42f42614e3a2 +NativeFormatImporter: + externalObjects: {} + mainObjectFileID: 11400000 + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Scenes/SampleScene.unity b/Assets/Scenes/SampleScene.unity index f0d41a8..5500f9f 100644 --- a/Assets/Scenes/SampleScene.unity +++ b/Assets/Scenes/SampleScene.unity @@ -142,7 +142,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &153338328 RectTransform: m_ObjectHideFlags: 0 @@ -215,6 +215,9 @@ MonoBehaviour: m_EditorClassIdentifier: panelName: Hotbar hotbarSlotPrefab: {fileID: 1989902681405785901, guid: 9bed75a8e605a864fb4b41f3e0ae9517, type: 3} + slots: [] + playerController: {fileID: 0} + hotbarSlotCount: 9 --- !u!114 &153338332 MonoBehaviour: m_ObjectHideFlags: 0 @@ -318,7 +321,6 @@ GameObject: - component: {fileID: 224768190} - component: {fileID: 224768189} - component: {fileID: 224768188} - - component: {fileID: 224768193} - component: {fileID: 224768187} - component: {fileID: 224768191} - component: {fileID: 224768192} @@ -468,21 +470,6 @@ CapsuleCollider2D: m_Offset: {x: 0.005384445, y: -0.8123081} m_Size: {x: 0.3146143, y: 0.3146143} m_Direction: 0 ---- !u!114 &224768193 -MonoBehaviour: - m_ObjectHideFlags: 0 - m_CorrespondingSourceObject: {fileID: 0} - m_PrefabInstance: {fileID: 0} - m_PrefabAsset: {fileID: 0} - m_GameObject: {fileID: 224768186} - m_Enabled: 1 - m_EditorHideFlags: 0 - m_Script: {fileID: 11500000, guid: d50a6d9f6c7ba0e49a308d097eb64fb7, type: 3} - m_Name: - m_EditorClassIdentifier: - isPlayerInventory: 1 - maxSlots: 36 - items: [] --- !u!114 &224768194 MonoBehaviour: m_ObjectHideFlags: 0 @@ -495,12 +482,90 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: fd29210254821be4dab438ab0312df18, type: 3} m_Name: m_EditorClassIdentifier: - testItem1: {fileID: 11400000, guid: 601d7a33a6c338d49a35134d5c772940, type: 2} - testItem2: {fileID: 11400000, guid: cbbbe8384f7ec2845b4145744d51ecf8, type: 2} - interactionDistance: 2 - hotbarSlotCount: 9 - activeHotbarSlot: 0 - playerInventory: {fileID: 0} +--- !u!1 &518922041 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 518922043} + - component: {fileID: 518922042} + m_Layer: 0 + m_Name: Crops + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &518922042 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 518922041} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 949894591 + m_SortingLayer: -1 + m_SortingOrder: 1 + m_Sprite: {fileID: 109301499, guid: 81f3e7dd6e7b15747a4a5c1923fb8521, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 2 + m_Size: {x: 10, y: 10} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &518922043 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 518922041} + m_LocalRotation: {x: 0, y: 0, z: 0, w: 1} + m_LocalPosition: {x: 0, y: 0.1, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: [] + m_Father: {fileID: 1047402456} + m_RootOrder: 0 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &519420028 GameObject: m_ObjectHideFlags: 0 @@ -817,6 +882,90 @@ Tilemap: e31: 0 e32: 0 e33: 1 +--- !u!1 &531540402 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 531540404} + - component: {fileID: 531540403} + m_Layer: 0 + m_Name: Background + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!212 &531540403 +SpriteRenderer: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 531540402} + m_Enabled: 1 + m_CastShadows: 0 + m_ReceiveShadows: 0 + m_DynamicOccludee: 1 + m_StaticShadowCaster: 0 + m_MotionVectors: 1 + m_LightProbeUsage: 1 + m_ReflectionProbeUsage: 1 + m_RayTracingMode: 0 + m_RayTraceProcedural: 0 + m_RenderingLayerMask: 1 + m_RendererPriority: 0 + m_Materials: + - {fileID: 2100000, guid: a97c105638bdf8b4a8650670310a4cd3, type: 2} + m_StaticBatchInfo: + firstSubMesh: 0 + subMeshCount: 0 + m_StaticBatchRoot: {fileID: 0} + m_ProbeAnchor: {fileID: 0} + m_LightProbeVolumeOverride: {fileID: 0} + m_ScaleInLightmap: 1 + m_ReceiveGI: 1 + m_PreserveUVs: 0 + m_IgnoreNormalsForChartDetection: 0 + m_ImportantGI: 0 + m_StitchLightmapSeams: 1 + m_SelectedEditorRenderState: 0 + m_MinimumChartSize: 4 + m_AutoUVMaxDistance: 0.5 + m_AutoUVMaxAngle: 89 + m_LightmapParameters: {fileID: 0} + m_SortingLayerID: 949894591 + m_SortingLayer: -1 + m_SortingOrder: 0 + m_Sprite: {fileID: 2046970518, guid: 705252b03b9874148b86d73e7eb692ac, type: 3} + m_Color: {r: 1, g: 1, b: 1, a: 1} + m_FlipX: 0 + m_FlipY: 0 + m_DrawMode: 2 + m_Size: {x: 10, y: 10} + m_AdaptiveModeThreshold: 0.5 + m_SpriteTileMode: 0 + m_WasSpriteAssigned: 1 + m_MaskInteraction: 0 + m_SpriteSortPoint: 0 +--- !u!4 &531540404 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 531540402} + 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: 1047402456} + m_RootOrder: 1 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &550426624 GameObject: m_ObjectHideFlags: 0 @@ -1087,6 +1236,7 @@ GameObject: - component: {fileID: 727688472} - component: {fileID: 727688471} - component: {fileID: 727688473} + - component: {fileID: 727688474} m_Layer: 0 m_Name: ---GameManager--- m_TagString: GameController @@ -1106,7 +1256,7 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: efc6be5d380533e4bb0a0179bec47c77, type: 3} m_Name: m_EditorClassIdentifier: - minuteToRealTime: 0.5 + minuteToRealTime: 0.05 --- !u!4 &727688472 Transform: m_ObjectHideFlags: 0 @@ -1134,6 +1284,22 @@ MonoBehaviour: m_Script: {fileID: 11500000, guid: 7f6b0f7d7d44d8a4c9fa79d01ee4ec53, type: 3} m_Name: m_EditorClassIdentifier: +--- !u!114 &727688474 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 727688470} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: 7465a8b99db65d04a862b423ae2ccdf3, type: 3} + m_Name: + m_EditorClassIdentifier: + cropInventory: + maxSlots: 0 + maxStackSize: 0 + items: [] --- !u!1 &789509403 GameObject: m_ObjectHideFlags: 0 @@ -56771,7 +56937,7 @@ GameObject: m_Icon: {fileID: 0} m_NavMeshLayer: 0 m_StaticEditorFlags: 0 - m_IsActive: 1 + m_IsActive: 0 --- !u!224 &1027537965 RectTransform: m_ObjectHideFlags: 0 @@ -56847,6 +57013,60 @@ MonoBehaviour: slotPrefab: {fileID: 9079120991637034566, guid: 9fb7f575f90d73343b4841c421d17567, type: 3} slotListObj: {fileID: 1707136373} slotUIList: [] +--- !u!1 &1047402454 +GameObject: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + serializedVersion: 6 + m_Component: + - component: {fileID: 1047402456} + - component: {fileID: 1047402455} + m_Layer: 0 + m_Name: Field + m_TagString: Untagged + m_Icon: {fileID: 0} + m_NavMeshLayer: 0 + m_StaticEditorFlags: 0 + m_IsActive: 1 +--- !u!114 &1047402455 +MonoBehaviour: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1047402454} + m_Enabled: 1 + m_EditorHideFlags: 0 + m_Script: {fileID: 11500000, guid: d700e4905ee3fd2408f52a4e3ecb48e8, type: 3} + m_Name: + m_EditorClassIdentifier: + isPlaced: 1 + placeableObject: {fileID: 0} + TESTCROP: {fileID: 11400000, guid: 4ce577b0996dc314ab1b42f42614e3a2, type: 2} + crop: {fileID: 0} + currentCropSprite: {fileID: 518922042} + daysSincePlanted: 0 + isWatered: 1 + state: 0 +--- !u!4 &1047402456 +Transform: + m_ObjectHideFlags: 0 + m_CorrespondingSourceObject: {fileID: 0} + m_PrefabInstance: {fileID: 0} + m_PrefabAsset: {fileID: 0} + m_GameObject: {fileID: 1047402454} + m_LocalRotation: {x: -0, y: -0, z: -0, w: 1} + m_LocalPosition: {x: -25, y: -5, z: 0} + m_LocalScale: {x: 1, y: 1, z: 1} + m_ConstrainProportionsScale: 0 + m_Children: + - {fileID: 518922043} + - {fileID: 531540404} + m_Father: {fileID: 0} + m_RootOrder: 6 + m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0} --- !u!1 &1507699183 GameObject: m_ObjectHideFlags: 0 diff --git a/Assets/Scripts/Clock.cs b/Assets/Scripts/Clock.cs index aa74853..cb19830 100644 --- a/Assets/Scripts/Clock.cs +++ b/Assets/Scripts/Clock.cs @@ -12,6 +12,6 @@ public class Clock : MonoBehaviour } private void GetTime() { - text.SetText($"{TimeManager.Day:00}D | {TimeManager.Hour:00}:{TimeManager.Minute:00}"); + text.SetText($"{TimeManager.Hour:00}:{TimeManager.Minute:00}
{TimeManager.Day:00}.{TimeManager.Month:00}.{TimeManager.Year:00}"); } } \ No newline at end of file diff --git a/Assets/Scripts/FarmManager.cs b/Assets/Scripts/FarmManager.cs new file mode 100644 index 0000000..9166206 --- /dev/null +++ b/Assets/Scripts/FarmManager.cs @@ -0,0 +1,10 @@ +using UnityEngine; + +public class FarmManager : MonoBehaviour +{ + public Inventory cropInventory; + private void Start() + { + cropInventory = new Inventory(2, 200); + } +} \ No newline at end of file diff --git a/Assets/Scripts/Items/Hoe.cs.meta b/Assets/Scripts/FarmManager.cs.meta similarity index 83% rename from Assets/Scripts/Items/Hoe.cs.meta rename to Assets/Scripts/FarmManager.cs.meta index 42cd96a..1c603be 100644 --- a/Assets/Scripts/Items/Hoe.cs.meta +++ b/Assets/Scripts/FarmManager.cs.meta @@ -1,5 +1,5 @@ fileFormatVersion: 2 -guid: ab99e668aa1ba5a469eef680f3bb4b45 +guid: 7465a8b99db65d04a862b423ae2ccdf3 MonoImporter: externalObjects: {} serializedVersion: 2 diff --git a/Assets/Scripts/Field.cs b/Assets/Scripts/Field.cs index bc8ae76..a90324b 100644 --- a/Assets/Scripts/Field.cs +++ b/Assets/Scripts/Field.cs @@ -1,5 +1,12 @@ using UnityEngine; -using UnityEngine.Tilemaps; + +public enum FieldState +{ + EMPTY, + DEAD, + GROWING, + HARVESTABLE, +} public class Field : Building { @@ -8,18 +15,22 @@ public class Field : Building public SpriteRenderer currentCropSprite; public int daysSincePlanted; - public bool isWatered; - public bool isDead = false; + public bool isWatered = false; + public FieldState state = FieldState.EMPTY; + + private void Start() { TimeManager.OnDayChanged += AddDay; + //! DEBUG + OnPlace(); } private void AddDay() { - if (crop && isPlaced && !isDead) + if (crop && isPlaced && state != FieldState.DEAD) { if (!isWatered) - isDead = true; + state = FieldState.DEAD; else { daysSincePlanted++; @@ -32,14 +43,14 @@ public class Field : Building public void Plant(Crop newCrop) { daysSincePlanted = 0; - isDead = false; + state = FieldState.GROWING; crop = newCrop; } public override void OnPlace() { daysSincePlanted = 0; - isDead = false; + state = FieldState.GROWING; Plant(TESTCROP); } } \ No newline at end of file diff --git a/Assets/Scripts/Inventory.cs b/Assets/Scripts/Inventory.cs index 64a0c74..09a80c3 100644 --- a/Assets/Scripts/Inventory.cs +++ b/Assets/Scripts/Inventory.cs @@ -1,26 +1,39 @@ -using System.Collections.Generic; using UnityEngine; using System; -public class Inventory : MonoBehaviour + +[System.Serializable] +public class Inventory where TItem : Item { - public static Action OnPlayerInventoryChanged; + [SerializeField] + private int maxSlots; + public int maxStackSize; - public bool isPlayerInventory = false; - public int maxSlots = 20; // maximum number of slots in the inventory - public InventoryItem[] items; // list of items in the inventory + [SerializeField] + private InventoryItem[] items; - - private void Awake() + public Inventory(int maxSlots = 1, int maxStackSize = 100) { - items = new InventoryItem[maxSlots]; - for (int i = 0; i < maxSlots; i++) + this.maxSlots = maxSlots; + this.maxStackSize = maxStackSize; + items = new InventoryItem[maxSlots]; + generateEmtpySlots(); + } + + public void setMaxSlots(int newMaxSlots) + { + maxSlots = newMaxSlots; + generateEmtpySlots(); + } + + private void generateEmtpySlots() + { + for (int i = items.Length > 0 ? items.Length - 1 : 0; i < maxSlots; i++) { items[i] = null; } } - // adds an item to the inventory, returns the quantity of items which could not be added - public int Add(Item item, int count) + public int Add(TItem item, int count) { int remainingCount = count; @@ -31,11 +44,11 @@ public class Inventory : MonoBehaviour // look for an existing stack of the same item in the inventory for (int i = 0; i < items.Length; i++) { - InventoryItem invItem = items[i]; - if (invItem != null && invItem.item == item && invItem.count < item.maxStackSize) + InventoryItem invItem = items[i]; + if (invItem != null && invItem.item == item && invItem.count < maxStackSize) { // add as many items as possible to the stack - int space = item.maxStackSize - invItem.count; + int space = maxStackSize - invItem.count; int toAdd = Mathf.Min(space, remainingCount); invItem.count += toAdd; remainingCount -= toAdd; @@ -43,10 +56,6 @@ public class Inventory : MonoBehaviour // exit the loop if all items have been added if (remainingCount == 0) { - if (isPlayerInventory) - { - OnPlayerInventoryChanged?.Invoke(); - } return 0; } @@ -58,35 +67,23 @@ public class Inventory : MonoBehaviour for (int i = 0; i < items.Length; i++) { - InventoryItem invItem = items[i]; + InventoryItem invItem = items[i]; Debug.Log(invItem); if (invItem?.item == null) { - int toAdd = Mathf.Min(item.maxStackSize, remainingCount); - items[i] = new InventoryItem(item, toAdd); + int toAdd = Mathf.Min(maxStackSize, remainingCount); + items[i] = new InventoryItem(item, toAdd); remainingCount -= toAdd; // exit the loop if all items have been added if (remainingCount == 0) { - - if (isPlayerInventory) - { - OnPlayerInventoryChanged?.Invoke(); - } - return 0; } } } - // return the quantity of items which could not be added - if (isPlayerInventory) - { - OnPlayerInventoryChanged?.Invoke(); - } - return remainingCount; } @@ -99,7 +96,7 @@ public class Inventory : MonoBehaviour // look for an existing stack of the item in the inventory for (int i = 0; i < items.Length; i++) { - InventoryItem invItem = items[i]; + InventoryItem invItem = items[i]; if (invItem != null && invItem.item == item) { // remove as many items as possible from the stack @@ -116,32 +113,22 @@ public class Inventory : MonoBehaviour // exit the loop if all items have been removed if (remainingCount == 0) { - if (isPlayerInventory) - { - OnPlayerInventoryChanged?.Invoke(); - } + return 0; } } } // return the quantity of items which could not be removed - if (isPlayerInventory) - { - OnPlayerInventoryChanged?.Invoke(); - } + return remainingCount; } public void SwapItems(int index1, int index2) { - InventoryItem temp = items[index1]; + InventoryItem temp = items[index1]; items[index1] = items[index2]; items[index2] = temp; - if (isPlayerInventory) - { - OnPlayerInventoryChanged?.Invoke(); - } } } diff --git a/Assets/Scripts/InventoryItem.cs b/Assets/Scripts/InventoryItem.cs index 12a7585..b205329 100644 --- a/Assets/Scripts/InventoryItem.cs +++ b/Assets/Scripts/InventoryItem.cs @@ -5,12 +5,12 @@ using System.Collections.Generic; // represents an item in the inventory and its count [System.Serializable] -public class InventoryItem +public class InventoryItem where TItem : Item { - public Item item; + public TItem item; public int count; - public InventoryItem(Item item, int count) + public InventoryItem(TItem item, int count) { this.item = item; this.count = count; diff --git a/Assets/Scripts/Items/Hoe.cs b/Assets/Scripts/Items/Hoe.cs deleted file mode 100644 index e9afb44..0000000 --- a/Assets/Scripts/Items/Hoe.cs +++ /dev/null @@ -1,32 +0,0 @@ -using UnityEngine; - -[CreateAssetMenu(fileName = "Hoe", menuName = "Harvestdale/Tools/Hoe", order = 0)] -public class Hoe : Tool -{ - - GameObject player; - private void Start() - { - player = GameObject.FindGameObjectWithTag("Player"); - } - - private Vector3 GetVector3IntInMouseDirection() - { - - Vector3 direction = (player.transform.position - GridBuildingSystem.Instance.GetSnappedMousePosition()).normalized; - Debug.Log(direction); - return direction; - } - public override void OnUse() - { - Debug.Log("Hoe on use"); - GetVector3IntInMouseDirection(); - - } - - public override void Use() - { - Debug.Log("Hoe use"); - OnUse(); - } -} \ No newline at end of file diff --git a/Assets/Scripts/Items/Tool.cs b/Assets/Scripts/Items/Tool.cs deleted file mode 100644 index 7f8d848..0000000 --- a/Assets/Scripts/Items/Tool.cs +++ /dev/null @@ -1,14 +0,0 @@ -using UnityEngine; - - -public abstract class Tool : Item -{ - public abstract void Use(); - public abstract void OnUse(); - - private void Awake() - { - stackable = false; - maxStackSize = 1; - } -} \ No newline at end of file diff --git a/Assets/Scripts/Items/Tool.cs.meta b/Assets/Scripts/Items/Tool.cs.meta deleted file mode 100644 index bee8a65..0000000 --- a/Assets/Scripts/Items/Tool.cs.meta +++ /dev/null @@ -1,11 +0,0 @@ -fileFormatVersion: 2 -guid: 943c595a7de78d44eae1ff08651910a2 -MonoImporter: - externalObjects: {} - serializedVersion: 2 - defaultReferences: [] - executionOrder: 0 - icon: {instanceID: 0} - userData: - assetBundleName: - assetBundleVariant: diff --git a/Assets/Scripts/PlayerController.cs b/Assets/Scripts/PlayerController.cs index c8c4640..be74d9e 100644 --- a/Assets/Scripts/PlayerController.cs +++ b/Assets/Scripts/PlayerController.cs @@ -6,100 +6,14 @@ using System; public class PlayerController : MonoBehaviour { - public static Action OnActiveSlotChanged; - public Item testItem1; - public Item testItem2; - public float interactionDistance = 2.5f; - public int hotbarSlotCount = 9; - public int activeHotbarSlot = 0; - [SerializeField] private Inventory playerInventory; - // Start is called before the first frame update void Start() { - playerInventory = GetComponent(); - GuiManager.Instance.OpenPanel("Hotbar"); } // Update is called once per frame void Update() { - float scroll = Input.GetAxis("Mouse ScrollWheel"); - if (scroll != 0) - { - activeHotbarSlot += (int)Mathf.Sign(scroll); - if (activeHotbarSlot < 0) - { - activeHotbarSlot = hotbarSlotCount - 1; - } - else if (activeHotbarSlot >= hotbarSlotCount) - { - activeHotbarSlot = 0; - } - OnActiveSlotChanged?.Invoke(); - } - - if (Input.GetKeyDown(KeyCode.Tab)) - { - GuiManager.Instance.TogglePanel("Inventory"); - } - - if (Input.GetMouseButtonDown(0)) - { - Vector3Int snappedMousePosition = GridBuildingSystem.Instance.GetSnappedMousePosition(); - Vector3Int snappedPlayerPosition = GridBuildingSystem.Instance.GetSnappedPosition(gameObject.transform.position); - if (Vector3Int.Distance(snappedMousePosition, snappedPlayerPosition) <= interactionDistance) - { - if (playerInventory.items[activeHotbarSlot]?.item is Tool) - { - Tool tool = playerInventory.items[activeHotbarSlot].item as Tool; - tool.Use(); - } - } - else - { - Debug.Log("Not in range"); - } - - } - - //! DEBUG - if (Input.GetKeyDown(KeyCode.U)) - { - // add 5 apples - int remainingCount = playerInventory.Add(testItem1, 5); - Debug.Log("Added " + (5 - remainingCount) + " apples to playerInventory."); - } - - if (Input.GetKeyDown(KeyCode.I)) - { // add 15 more apples - int remainingCount = playerInventory.Add(testItem1, 15); - Debug.Log("Added " + (15 - remainingCount) + " apples to playerInventory."); - } - - if (Input.GetKeyDown(KeyCode.O)) - { - // add 10 bananas - int remainingCount = playerInventory.Add(testItem2, 10); - Debug.Log("Added " + (10 - remainingCount) + " bananas to playerInventory."); - } - - - if (Input.GetKeyDown(KeyCode.J)) - { - int count = 3; - int applesRemaining = playerInventory.Remove(testItem1, count); - Debug.Log("Removed " + (count - applesRemaining) + " apples."); - - } - - if (Input.GetKeyDown(KeyCode.K)) - { - int count = 5; - int bananasRemaining = playerInventory.Remove(testItem2, count); - Debug.Log("Removed " + (count - bananasRemaining) + " bananas."); - - } } diff --git a/Assets/Scripts/TimeManager.cs b/Assets/Scripts/TimeManager.cs index 9060dbe..57f2f35 100644 --- a/Assets/Scripts/TimeManager.cs +++ b/Assets/Scripts/TimeManager.cs @@ -1,25 +1,33 @@ using UnityEngine; using System; -using System.Collections; -using System.Collections.Generic; + public class TimeManager : MonoBehaviour { public static Action OnMinuteChanged; public static Action OnHourChanged; public static Action OnDayChanged; + public static Action OnMonthChanged; + public static Action OnYearChanged; + public static int Minute { get; private set; } public static int Hour { get; private set; } public static int Day { get; private set; } + public static int Month { get; private set; } + public static int Year { get; private set; } - public float minuteToRealTime = .2f; + [SerializeField] + [Range(.05f, 10f)] + private float minuteToRealTime = .05f; private float timer; private void Start() { Minute = 0; Hour = 10; - Day = 1; + Day = 25; + Month = 4; + Year = 1; timer = minuteToRealTime; } @@ -29,17 +37,34 @@ public class TimeManager : MonoBehaviour if (timer <= 0) { + // Increase minute Minute++; OnMinuteChanged?.Invoke(); if (Minute >= 60) { + // Increase hour Hour++; Minute = 0; if (Hour >= 24) { + // Increase day Day++; Hour = 0; OnDayChanged?.Invoke(); + if (Day > 28) + { + // Increase month + Month++; + Day = 1; + OnMonthChanged?.Invoke(); + if (Month > 4) + { + // Increase year + Year++; + Month = 1; + OnYearChanged?.Invoke(); + } + } } OnHourChanged?.Invoke(); diff --git a/Assets/Scripts/UI/DraggableSlotContentUI.cs b/Assets/Scripts/UI/DraggableSlotContentUI.cs index 268821c..2c6b634 100644 --- a/Assets/Scripts/UI/DraggableSlotContentUI.cs +++ b/Assets/Scripts/UI/DraggableSlotContentUI.cs @@ -1,33 +1,33 @@ -using UnityEngine; -using UnityEngine.EventSystems; -using UnityEngine.UI; +// using UnityEngine; +// using UnityEngine.EventSystems; +// using UnityEngine.UI; -public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler -{ - public int slotIndex; // slotIndex is set by SlotUI - [HideInInspector] public Transform parentAfterDrag; - public Image image; - public void OnBeginDrag(PointerEventData eventData) - { - parentAfterDrag = transform.parent; - slotIndex = parentAfterDrag.GetComponent().slotIndex; // Set slotIndex again to be safe, but should be already set - transform.SetParent(transform.root); - transform.SetAsLastSibling(); - image.raycastTarget = false; - } +// public class DraggableSlotContentUI : MonoBehaviour, IBeginDragHandler, IDragHandler, IEndDragHandler +// { +// public int slotIndex; // slotIndex is set by SlotUI +// [HideInInspector] public Transform parentAfterDrag; +// public Image image; +// public void OnBeginDrag(PointerEventData eventData) +// { +// parentAfterDrag = transform.parent; +// slotIndex = parentAfterDrag.GetComponent().slotIndex; // Set slotIndex again to be safe, but should be already set +// transform.SetParent(transform.root); +// transform.SetAsLastSibling(); +// image.raycastTarget = false; +// } - public void OnDrag(PointerEventData eventData) - { - Debug.Log("Dragging"); - transform.position = Input.mousePosition; +// public void OnDrag(PointerEventData eventData) +// { +// Debug.Log("Dragging"); +// transform.position = Input.mousePosition; - } +// } - public void OnEndDrag(PointerEventData eventData) - { - transform.SetParent(parentAfterDrag); - image.raycastTarget = true; - // invoke - Inventory.OnPlayerInventoryChanged?.Invoke(); - } -} \ No newline at end of file +// public void OnEndDrag(PointerEventData eventData) +// { +// transform.SetParent(parentAfterDrag); +// image.raycastTarget = true; +// // invoke +// Inventory.OnPlayerInventoryChanged?.Invoke(); +// } +// } \ No newline at end of file diff --git a/Assets/Scripts/UI/HotbarSlotUI.cs b/Assets/Scripts/UI/HotbarSlotUI.cs index 5510148..ff04db0 100644 --- a/Assets/Scripts/UI/HotbarSlotUI.cs +++ b/Assets/Scripts/UI/HotbarSlotUI.cs @@ -1,56 +1,56 @@ -using System.Collections; -using UnityEngine.UI; -using System.Collections.Generic; -using UnityEngine; -using TMPro; -public class HotbarSlotUI : MonoBehaviour -{ - public int slotIndex; +// using System.Collections; +// using UnityEngine.UI; +// using System.Collections.Generic; +// using UnityEngine; +// using TMPro; +// public class HotbarSlotUI : MonoBehaviour +// { +// public int slotIndex; - private PlayerController playerController; +// private PlayerController playerController; - private InventoryItem invItem; +// private InventoryItem invItem; - [SerializeField] private Image border; - [SerializeField] private Image image; - [SerializeField] private TextMeshProUGUI quantityText; +// [SerializeField] private Image border; +// [SerializeField] private Image image; +// [SerializeField] private TextMeshProUGUI quantityText; - private void Start() - { - playerController = GameObject.FindGameObjectWithTag("Player").GetComponent(); - PlayerController.OnActiveSlotChanged += CheckSelectedSlot; - CheckSelectedSlot(); - } +// private void Start() +// { +// playerController = GameObject.FindGameObjectWithTag("Player").GetComponent(); +// PlayerController.OnActiveSlotChanged += CheckSelectedSlot; +// CheckSelectedSlot(); +// } - private void CheckSelectedSlot() - { - if (playerController.activeHotbarSlot == slotIndex) - { - border.gameObject.SetActive(true); - } - else - { - border.gameObject.SetActive(false); - } - } +// private void CheckSelectedSlot() +// { +// if (playerController.activeHotbarSlot == slotIndex) +// { +// border.gameObject.SetActive(true); +// } +// else +// { +// border.gameObject.SetActive(false); +// } +// } - public void SetInventoryItem(InventoryItem newInvItem) - { - invItem = newInvItem; - UpdateSlot(); - } +// public void SetInventoryItem(InventoryItem newInvItem) +// { +// invItem = newInvItem; +// UpdateSlot(); +// } - private void UpdateSlot() - { - image.sprite = invItem?.item?.sprite ?? null; - quantityText.SetText(invItem?.count.ToString() ?? ""); - if (image.sprite == null) - { - image.color = new Color(0, 0, 0, 0); - } - else - { - image.color = Color.white; - } - } -} +// private void UpdateSlot() +// { +// image.sprite = invItem?.item?.sprite ?? null; +// quantityText.SetText(invItem?.count.ToString() ?? ""); +// if (image.sprite == null) +// { +// image.color = new Color(0, 0, 0, 0); +// } +// else +// { +// image.color = Color.white; +// } +// } +// } diff --git a/Assets/Scripts/UI/HotbarUI.cs b/Assets/Scripts/UI/HotbarUI.cs index 70eda6d..4e7a96d 100644 --- a/Assets/Scripts/UI/HotbarUI.cs +++ b/Assets/Scripts/UI/HotbarUI.cs @@ -1,52 +1,52 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; +// using System.Collections; +// using System.Collections.Generic; +// using UnityEngine; +// using UnityEngine.UI; -public class HotbarUI : GuiPanel -{ - [SerializeField] private GameObject hotbarSlotPrefab; - private List slots = new List(); - private Inventory playerInventory; - private PlayerController playerController; - private int hotbarSlotCount = 9; +// public class HotbarUI : GuiPanel +// { +// [SerializeField] private GameObject hotbarSlotPrefab; +// private List slots = new List(); +// private Inventory playerInventory; +// private PlayerController playerController; +// private int hotbarSlotCount = 9; - private void Start() - { - Inventory.OnPlayerInventoryChanged += UpdateSlots; - } - public override void OnOpen() - { - if (slots.Count == 0) - { - playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); - playerController = GameObject.FindGameObjectWithTag("Player").GetComponent(); - hotbarSlotCount = playerController.hotbarSlotCount; - CreateSlots(); - } - UpdateSlots(); - } +// private void Start() +// { +// Inventory.OnPlayerInventoryChanged += UpdateSlots; +// } +// public override void OnOpen() +// { +// if (slots.Count == 0) +// { +// playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); +// playerController = GameObject.FindGameObjectWithTag("Player").GetComponent(); +// hotbarSlotCount = playerController.hotbarSlotCount; +// CreateSlots(); +// } +// UpdateSlots(); +// } - public override void OnClose() - { - } +// public override void OnClose() +// { +// } - private void CreateSlots() - { - for (int i = 0; i < hotbarSlotCount; i++) - { - HotbarSlotUI newSlot = Instantiate(hotbarSlotPrefab, Vector3.zero, Quaternion.identity, transform).GetComponent(); - newSlot.slotIndex = i; - slots.Add(newSlot); - } - } +// private void CreateSlots() +// { +// for (int i = 0; i < hotbarSlotCount; i++) +// { +// HotbarSlotUI newSlot = Instantiate(hotbarSlotPrefab, Vector3.zero, Quaternion.identity, transform).GetComponent(); +// newSlot.slotIndex = i; +// slots.Add(newSlot); +// } +// } - private void UpdateSlots() - { - for (int i = 0; i < slots.Count; i++) - { - slots[i].SetInventoryItem(playerInventory.items[i] ?? null); - } - } +// private void UpdateSlots() +// { +// for (int i = 0; i < slots.Count; i++) +// { +// slots[i].SetInventoryItem(playerInventory.items[i] ?? null); +// } +// } -} +// } diff --git a/Assets/Scripts/UI/InventoryUI.cs b/Assets/Scripts/UI/InventoryUI.cs index 9653c2b..edca92a 100644 --- a/Assets/Scripts/UI/InventoryUI.cs +++ b/Assets/Scripts/UI/InventoryUI.cs @@ -1,53 +1,53 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; +// using System.Collections; +// using System.Collections.Generic; +// using UnityEngine; -public class InventoryUI : GuiPanel -{ - [SerializeField] private GameObject slotPrefab; - [SerializeField] private GameObject slotListObj; - [SerializeField] private List slotUIList; +// public class InventoryUI : GuiPanel +// { +// [SerializeField] private GameObject slotPrefab; +// [SerializeField] private GameObject slotListObj; +// [SerializeField] private List slotUIList; - private Inventory playerInventory; +// private Inventory playerInventory; - private void Start() - { - Inventory.OnPlayerInventoryChanged += UpdateSlots; - } - public override void OnOpen() - { - if (slotUIList.Count == 0) - { - playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); - CreateSlots(); - } - UpdateSlots(); - GuiManager.Instance.ClosePanel("Hotbar"); - } +// private void Start() +// { +// Inventory.OnPlayerInventoryChanged += UpdateSlots; +// } +// public override void OnOpen() +// { +// if (slotUIList.Count == 0) +// { +// playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); +// CreateSlots(); +// } +// UpdateSlots(); +// GuiManager.Instance.ClosePanel("Hotbar"); +// } - public override void OnClose() - { - GuiManager.Instance.OpenPanel("Hotbar"); - } - private void CreateSlots() - { - playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); +// public override void OnClose() +// { +// GuiManager.Instance.OpenPanel("Hotbar"); +// } +// private void CreateSlots() +// { +// playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); - for (int i = 0; i < playerInventory.maxSlots; i++) - { - SlotUI newSlot = Instantiate(slotPrefab, Vector3.zero, Quaternion.identity, slotListObj.transform).GetComponent(); - newSlot.slotIndex = i; - slotUIList.Add(newSlot); - } - } - private void UpdateSlots() - { - int i = 0; - foreach (SlotUI slotUi in slotUIList) - { - slotUi.SetInventoryItem(playerInventory.items[i]); - i++; - } - } +// for (int i = 0; i < playerInventory.maxSlots; i++) +// { +// SlotUI newSlot = Instantiate(slotPrefab, Vector3.zero, Quaternion.identity, slotListObj.transform).GetComponent(); +// newSlot.slotIndex = i; +// slotUIList.Add(newSlot); +// } +// } +// private void UpdateSlots() +// { +// int i = 0; +// foreach (SlotUI slotUi in slotUIList) +// { +// slotUi.SetInventoryItem(playerInventory.items[i]); +// i++; +// } +// } -} +// } diff --git a/Assets/Scripts/UI/SlotUI.cs b/Assets/Scripts/UI/SlotUI.cs index 91b514b..38d6286 100644 --- a/Assets/Scripts/UI/SlotUI.cs +++ b/Assets/Scripts/UI/SlotUI.cs @@ -1,60 +1,60 @@ -using System.Collections; -using System.Collections.Generic; -using UnityEngine; -using UnityEngine.UI; -using UnityEngine.EventSystems; -public class SlotUI : MonoBehaviour, IDropHandler -{ - public int slotIndex; - [SerializeField] private GameObject contentObject; - [SerializeField] private InventoryItem inventoryItem; - [SerializeField] private Image itemSpriteImage; - [SerializeField] private TMPro.TextMeshProUGUI quantityText; +// using System.Collections; +// using System.Collections.Generic; +// using UnityEngine; +// using UnityEngine.UI; +// using UnityEngine.EventSystems; +// public class SlotUI : MonoBehaviour, IDropHandler +// { +// public int slotIndex; +// [SerializeField] private GameObject contentObject; +// [SerializeField] private InventoryItem inventoryItem; +// [SerializeField] private Image itemSpriteImage; +// [SerializeField] private TMPro.TextMeshProUGUI quantityText; - private Inventory playerInventory; - private void Start() - { - UpdateSlot(); - playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); - } - public void SetInventoryItem(InventoryItem newInventoryItem) - { - inventoryItem = newInventoryItem; - UpdateSlot(); - } +// private Inventory playerInventory; +// private void Start() +// { +// UpdateSlot(); +// playerInventory = GameObject.FindGameObjectWithTag("Player").GetComponent(); +// } +// public void SetInventoryItem(InventoryItem newInventoryItem) +// { +// inventoryItem = newInventoryItem; +// UpdateSlot(); +// } - private void UpdateSlot() - { - if (inventoryItem != null) - { - itemSpriteImage.sprite = inventoryItem?.item?.sprite ?? null; - if (itemSpriteImage.sprite == null) - { - itemSpriteImage.color = new Color(0, 0, 0, 0); - } - else - { - itemSpriteImage.color = new Color(255, 255, 255, 1); - } +// private void UpdateSlot() +// { +// if (inventoryItem != null) +// { +// itemSpriteImage.sprite = inventoryItem?.item?.sprite ?? null; +// if (itemSpriteImage.sprite == null) +// { +// itemSpriteImage.color = new Color(0, 0, 0, 0); +// } +// else +// { +// itemSpriteImage.color = new Color(255, 255, 255, 1); +// } - quantityText.SetText(inventoryItem.count != 0 ? inventoryItem.count.ToString() : ""); - } - else - { - itemSpriteImage.sprite = null; - quantityText.SetText(""); - itemSpriteImage.color = new Color(0, 0, 0, 0); - } +// quantityText.SetText(inventoryItem.count != 0 ? inventoryItem.count.ToString() : ""); +// } +// else +// { +// itemSpriteImage.sprite = null; +// quantityText.SetText(""); +// itemSpriteImage.color = new Color(0, 0, 0, 0); +// } - } +// } - public void OnDrop(PointerEventData eventData) - { - Debug.Log("DROP"); - DraggableSlotContentUI dropped = eventData.pointerDrag.GetComponent(); - playerInventory.SwapItems(dropped.slotIndex, slotIndex); - } +// public void OnDrop(PointerEventData eventData) +// { +// Debug.Log("DROP"); +// DraggableSlotContentUI dropped = eventData.pointerDrag.GetComponent(); +// playerInventory.SwapItems(dropped.slotIndex, slotIndex); +// } -} +// }