mirror of
https://github.com/DerTyp7/harvestdale-unity.git
synced 2025-10-30 13:07:10 +01:00
interactable
This commit is contained in:
66
Assets/Scripts/Field/Field.cs
Normal file
66
Assets/Scripts/Field/Field.cs
Normal file
@@ -0,0 +1,66 @@
|
||||
using UnityEngine;
|
||||
|
||||
public enum FieldState
|
||||
{
|
||||
EMPTY,
|
||||
DEAD,
|
||||
GROWING,
|
||||
HARVESTABLE,
|
||||
}
|
||||
|
||||
public class Field : Building
|
||||
{
|
||||
public Crop crop;
|
||||
|
||||
public SpriteRenderer currentCropSpriteRenderer;
|
||||
public int daysSincePlanted;
|
||||
public bool isWatered = false;
|
||||
public FieldState state = FieldState.EMPTY;
|
||||
|
||||
|
||||
private void Start()
|
||||
{
|
||||
TimeManager.OnDayChanged += AddDay;
|
||||
|
||||
}
|
||||
|
||||
private void SetSprite(Sprite sprite)
|
||||
{
|
||||
if (currentCropSpriteRenderer)
|
||||
{
|
||||
currentCropSpriteRenderer.sprite = sprite;
|
||||
currentCropSpriteRenderer.drawMode = SpriteDrawMode.Tiled;
|
||||
currentCropSpriteRenderer.size = new Vector2(10, 10); // TODO: Make this dynamic
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void AddDay()
|
||||
{
|
||||
if (crop && isPlaced && state != FieldState.DEAD)
|
||||
{
|
||||
if (!isWatered)
|
||||
state = FieldState.DEAD;
|
||||
else
|
||||
{
|
||||
daysSincePlanted++;
|
||||
SetSprite(crop.sprites[daysSincePlanted]);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public void Plant(Crop newCrop)
|
||||
{
|
||||
daysSincePlanted = 0;
|
||||
state = FieldState.GROWING;
|
||||
crop = newCrop;
|
||||
SetSprite(crop.sprites[0]);
|
||||
|
||||
}
|
||||
|
||||
public override void OnPlace()
|
||||
{
|
||||
Plant(null);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Field/Field.cs.meta
Normal file
11
Assets/Scripts/Field/Field.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 53c8af14dae8dbe4e95cda372289f89e
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
14
Assets/Scripts/Field/FieldController.cs
Normal file
14
Assets/Scripts/Field/FieldController.cs
Normal file
@@ -0,0 +1,14 @@
|
||||
// Interactable object which lets the player plant & harvest a seed
|
||||
using UnityEngine;
|
||||
|
||||
public class FieldController : Interactable
|
||||
{
|
||||
public Field field;
|
||||
public Crop testCrop;
|
||||
|
||||
public override void OnInteract()
|
||||
{
|
||||
Debug.Log("Interacting with field");
|
||||
field.Plant(testCrop);
|
||||
}
|
||||
}
|
||||
11
Assets/Scripts/Field/FieldController.cs.meta
Normal file
11
Assets/Scripts/Field/FieldController.cs.meta
Normal file
@@ -0,0 +1,11 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 6b43d0d1aa7cd2c4db0db026202eb972
|
||||
MonoImporter:
|
||||
externalObjects: {}
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
||||
Reference in New Issue
Block a user