crop in inv
This commit is contained in:
parent
7ceb7e4bcb
commit
81e91c185c
2 changed files with 54 additions and 88 deletions
|
|
@ -4,8 +4,7 @@ using UnityEngine;
|
||||||
using static CropAction;
|
using static CropAction;
|
||||||
|
|
||||||
|
|
||||||
enum CropAction
|
enum CropAction {
|
||||||
{
|
|
||||||
NextDay,
|
NextDay,
|
||||||
Hoe,
|
Hoe,
|
||||||
Scythe,
|
Scythe,
|
||||||
|
|
@ -13,9 +12,7 @@ enum CropAction
|
||||||
Seeds
|
Seeds
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class Crop {
|
||||||
public class Crop
|
|
||||||
{
|
|
||||||
private const int FinalGrowthStage = 4;
|
private const int FinalGrowthStage = 4;
|
||||||
|
|
||||||
private static Sprite _smallCrop;
|
private static Sprite _smallCrop;
|
||||||
|
|
@ -34,156 +31,116 @@ public class Crop
|
||||||
private SpriteRenderer _cropSpriteRenderer;
|
private SpriteRenderer _cropSpriteRenderer;
|
||||||
private SpriteRenderer _hydrationSpriteRenderer;
|
private SpriteRenderer _hydrationSpriteRenderer;
|
||||||
|
|
||||||
public Crop(SpriteRenderer cropSpriteRenderer, SpriteRenderer hydrationSpriteRenderer)
|
public Crop(SpriteRenderer cropSpriteRenderer, SpriteRenderer hydrationSpriteRenderer) {
|
||||||
{
|
|
||||||
_planted = false;
|
_planted = false;
|
||||||
_hydrated = false;
|
_hydrated = false;
|
||||||
|
|
||||||
_cropSpriteRenderer = cropSpriteRenderer;
|
_cropSpriteRenderer = cropSpriteRenderer;
|
||||||
_hydrationSpriteRenderer = hydrationSpriteRenderer;
|
_hydrationSpriteRenderer = hydrationSpriteRenderer;
|
||||||
|
|
||||||
_smallCrop = BaseTile.GenerateSpriteFromFile("Assets/Farming Asset Pack/Split Assets/farming_tileset_027.png");
|
|
||||||
_fullyGrownCrop = BaseTile.GenerateSpriteFromFile("Assets/Farming Asset Pack/Split Assets/farming_tileset_040.png");
|
|
||||||
|
|
||||||
_hydratedColor = new Color(0.5f, 0.5f, 1.0f, 0.5f);
|
_smallCrop = BaseTile.GenerateSpriteFromFile("Assets/Farming Asset Pack/Split Assets/farming_tileset_027.png");
|
||||||
|
_fullyGrownCrop =
|
||||||
|
BaseTile.GenerateSpriteFromFile("Assets/Farming Asset Pack/Split Assets/farming_tileset_040.png");
|
||||||
|
|
||||||
|
_hydratedColor = new Color(0.5f, 0.5f, 1.0f, 0.269420f);
|
||||||
|
|
||||||
UpdateSprite();
|
UpdateSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Grow()
|
private void Grow() {
|
||||||
{
|
|
||||||
_growthStage++;
|
_growthStage++;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DayLightStep()
|
public void DayLightStep() {
|
||||||
{
|
|
||||||
Debug.Log("Crop.DayLightStep");
|
Debug.Log("Crop.DayLightStep");
|
||||||
ApplyAction(NextDay);
|
ApplyAction(NextDay);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void Clicked(UsableItem usableItem)
|
public void Clicked(UsableItem usableItem) {
|
||||||
{
|
|
||||||
Debug.Log("Crop.Clicked UsableItem " + usableItem);
|
Debug.Log("Crop.Clicked UsableItem " + usableItem);
|
||||||
if (usableItem != null)
|
if(usableItem != null) {
|
||||||
{
|
|
||||||
ItemContainer ic = ItemContainer.Instance;
|
ItemContainer ic = ItemContainer.Instance;
|
||||||
if (ic.GetItemIdByName("Hoe") == usableItem.id)
|
if(ic.GetItemIdByName("Hoe") == usableItem.id) {
|
||||||
{
|
|
||||||
ApplyAction(Hoe);
|
ApplyAction(Hoe);
|
||||||
}
|
} else if(ic.GetItemIdByName("Scythe") == usableItem.id) {
|
||||||
else if (ic.GetItemIdByName("Scythe") == usableItem.id)
|
|
||||||
{
|
|
||||||
ApplyAction(Scythe);
|
ApplyAction(Scythe);
|
||||||
}
|
} else if(ic.GetItemIdByName("Wheat Seeds") == usableItem.id) {
|
||||||
else if (ic.GetItemIdByName("Wheat Seeds") == usableItem.id)
|
|
||||||
{
|
|
||||||
ApplyAction(Seeds);
|
ApplyAction(Seeds);
|
||||||
}
|
} else if(ic.GetItemIdByName("Watering Can") == usableItem.id) {
|
||||||
else if (ic.GetItemIdByName("Watering Can") == usableItem.id)
|
|
||||||
{
|
|
||||||
ApplyAction(WateringCan);
|
ApplyAction(WateringCan);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void ApplyAction(CropAction action)
|
private void ApplyAction(CropAction action) {
|
||||||
{
|
|
||||||
Debug.Log("ApplyAction: CropAction " + action);
|
Debug.Log("ApplyAction: CropAction " + action);
|
||||||
if (_planted)
|
if(_planted) {
|
||||||
{
|
if(Hoe == action) {
|
||||||
if (Hoe == action)
|
|
||||||
{
|
|
||||||
_planted = false;
|
_planted = false;
|
||||||
}
|
} else if(Scythe == action) {
|
||||||
else if (Scythe == action)
|
if(_fullyGrown) {
|
||||||
{
|
|
||||||
if (_fullyGrown)
|
|
||||||
{
|
|
||||||
Harvest();
|
Harvest();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if(!_planted) {
|
||||||
else if (!_planted)
|
if(Seeds == action) {
|
||||||
{
|
|
||||||
if (Seeds == action)
|
|
||||||
{
|
|
||||||
_planted = true;
|
_planted = true;
|
||||||
|
Inventory.instance.RemoveItem(ItemContainer.Instance.GetItemByName("Wheat Seeds"), 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hydrated)
|
if(_hydrated) {
|
||||||
{
|
if(NextDay == action) {
|
||||||
if (NextDay == action)
|
|
||||||
{
|
|
||||||
_hydrated = false;
|
_hydrated = false;
|
||||||
if (_planted)
|
if(_planted) {
|
||||||
{
|
|
||||||
Grow();
|
Grow();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
} else if(!_hydrated) {
|
||||||
else if (!_hydrated)
|
if(WateringCan == action) {
|
||||||
{
|
|
||||||
if (WateringCan == action)
|
|
||||||
{
|
|
||||||
_hydrated = true;
|
_hydrated = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSprite();
|
UpdateSprite();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Harvest()
|
private void Harvest() {
|
||||||
{
|
|
||||||
|
|
||||||
AddCropToInventory();
|
AddCropToInventory();
|
||||||
_planted = false;
|
_planted = false;
|
||||||
_growthStage = 0;
|
_growthStage = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void AddCropToInventory()
|
private void AddCropToInventory() {
|
||||||
{
|
|
||||||
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Wheat Seeds"), 3);
|
Inventory.instance.AddItem(ItemContainer.Instance.GetItemByName("Wheat Seeds"), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateSprite()
|
private void UpdateSprite() {
|
||||||
{
|
|
||||||
Dump();
|
Dump();
|
||||||
if (_planted)
|
if(_planted) {
|
||||||
{
|
if(_fullyGrown) {
|
||||||
if (_fullyGrown)
|
|
||||||
{
|
|
||||||
//Debug.Log("sprite fg");
|
//Debug.Log("sprite fg");
|
||||||
_cropSpriteRenderer.sprite = _fullyGrownCrop;
|
_cropSpriteRenderer.sprite = _fullyGrownCrop;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
//Debug.Log("sprite smallCrop");
|
//Debug.Log("sprite smallCrop");
|
||||||
_cropSpriteRenderer.sprite = _smallCrop;
|
_cropSpriteRenderer.sprite = _smallCrop;
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
_cropSpriteRenderer.sprite = null;
|
_cropSpriteRenderer.sprite = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_hydrated)
|
if(_hydrated) {
|
||||||
{
|
|
||||||
//Debug.Log("sprite hydrated");
|
//Debug.Log("sprite hydrated");
|
||||||
_hydrationSpriteRenderer.color = _hydratedColor;
|
_hydrationSpriteRenderer.color = _hydratedColor;
|
||||||
}
|
} else {
|
||||||
else
|
|
||||||
{
|
|
||||||
//Debug.Log("sprite no hydrated");
|
//Debug.Log("sprite no hydrated");
|
||||||
_hydrationSpriteRenderer.color = Color.clear;
|
_hydrationSpriteRenderer.color = Color.clear;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void Dump()
|
private void Dump() {
|
||||||
{
|
|
||||||
Debug.Log("age: " + _growthStage + "\n" +
|
Debug.Log("age: " + _growthStage + "\n" +
|
||||||
"hydrated: " + _hydrated + "\n" +
|
"hydrated: " + _hydrated + "\n" +
|
||||||
"planted: " + _planted);
|
"planted: " + _planted);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
@ -137,12 +137,21 @@
|
||||||
"dependencies": {},
|
"dependencies": {},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
|
"com.unity.nuget.newtonsoft-json": {
|
||||||
|
"version": "3.0.2",
|
||||||
|
"depth": 2,
|
||||||
|
"source": "registry",
|
||||||
|
"dependencies": {},
|
||||||
|
"url": "https://packages.unity.com"
|
||||||
|
},
|
||||||
"com.unity.services.core": {
|
"com.unity.services.core": {
|
||||||
"version": "1.0.1",
|
"version": "1.3.1",
|
||||||
"depth": 1,
|
"depth": 1,
|
||||||
"source": "registry",
|
"source": "registry",
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"com.unity.modules.unitywebrequest": "1.0.0"
|
"com.unity.modules.unitywebrequest": "1.0.0",
|
||||||
|
"com.unity.nuget.newtonsoft-json": "3.0.2",
|
||||||
|
"com.unity.modules.androidjni": "1.0.0"
|
||||||
},
|
},
|
||||||
"url": "https://packages.unity.com"
|
"url": "https://packages.unity.com"
|
||||||
},
|
},
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue