Made item sprites able to be easily changed
This commit is contained in:
@@ -14,26 +14,42 @@ MonoBehaviour:
|
|||||||
m_EditorClassIdentifier: Fruitomation::Fruitomation.Game.Items.SerializedItemInfoRegistry
|
m_EditorClassIdentifier: Fruitomation::Fruitomation.Game.Items.SerializedItemInfoRegistry
|
||||||
Registry:
|
Registry:
|
||||||
- Type: 0
|
- Type: 0
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: 23e3bfe33d8c6004c85fd638db567ab6,
|
||||||
|
type: 3}
|
||||||
MinMoney: 0.5
|
MinMoney: 0.5
|
||||||
MaxMoney: 1.5
|
MaxMoney: 1.5
|
||||||
- Type: 1
|
- Type: 1
|
||||||
|
Prefab: {fileID: 8799415981405337049, guid: c21e0b5539573904cb10d979de4a3f72,
|
||||||
|
type: 3}
|
||||||
MinMoney: 3
|
MinMoney: 3
|
||||||
MaxMoney: 7
|
MaxMoney: 7
|
||||||
- Type: 2
|
- Type: 2
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: 5e1f7f5d4294c1d4fa3e6f88dec0dfa6,
|
||||||
|
type: 3}
|
||||||
MinMoney: 12
|
MinMoney: 12
|
||||||
MaxMoney: 18
|
MaxMoney: 18
|
||||||
- Type: 3
|
- Type: 3
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: b224b6df33529e64d83245d78e0feb9f,
|
||||||
|
type: 3}
|
||||||
MinMoney: 40
|
MinMoney: 40
|
||||||
MaxMoney: 60
|
MaxMoney: 60
|
||||||
- Type: 4
|
- Type: 4
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: 7af455f1c1666e5409156598fe669f74,
|
||||||
|
type: 3}
|
||||||
MinMoney: 120
|
MinMoney: 120
|
||||||
MaxMoney: 160
|
MaxMoney: 160
|
||||||
- Type: 6
|
- Type: 6
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: 13f2740b5ae396e40940587ab2effd65,
|
||||||
|
type: 3}
|
||||||
MinMoney: 250
|
MinMoney: 250
|
||||||
MaxMoney: 350
|
MaxMoney: 350
|
||||||
- Type: 7
|
- Type: 7
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: ebddb1b81a288cc4c993a25bc9efe894,
|
||||||
|
type: 3}
|
||||||
MinMoney: 800
|
MinMoney: 800
|
||||||
MaxMoney: 900
|
MaxMoney: 900
|
||||||
- Type: 5
|
- Type: 5
|
||||||
|
Prefab: {fileID: 4062657912758122058, guid: 2cf42dbc57bb6374b9e6ec700aad5854,
|
||||||
|
type: 3}
|
||||||
MinMoney: 2000
|
MinMoney: 2000
|
||||||
MaxMoney: 3000
|
MaxMoney: 3000
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
using Fruitomation.Global;
|
using Fruitomation.Game.Items;
|
||||||
|
using Fruitomation.Global;
|
||||||
using UnityEngine;
|
using UnityEngine;
|
||||||
|
|
||||||
namespace Fruitomation.Game
|
namespace Fruitomation.Game
|
||||||
|
|||||||
@@ -47,37 +47,35 @@ namespace Fruitomation.Game
|
|||||||
|
|
||||||
private void SpawnFruit()
|
private void SpawnFruit()
|
||||||
{
|
{
|
||||||
List<(ItemType, GameObject)> unlocked = new() { (ItemType.Apple, ApplePrefab) };
|
List<ItemType> unlocked = new() { ItemType.Apple };
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.Grapes))
|
if (UpgradeManager.Is(BasicUpgrade.Grapes))
|
||||||
unlocked.Add((ItemType.Grape, GrapePrefab));
|
unlocked.Add(ItemType.Grape);
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.Bananas))
|
if (UpgradeManager.Is(BasicUpgrade.Bananas))
|
||||||
unlocked.Add((ItemType.Banana, BananaPrefab));
|
unlocked.Add(ItemType.Banana);
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.Kiwi))
|
if (UpgradeManager.Is(BasicUpgrade.Kiwi))
|
||||||
unlocked.Add((ItemType.Kiwi, KiwiPrefab));
|
unlocked.Add(ItemType.Kiwi);
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.Mangoes))
|
if (UpgradeManager.Is(BasicUpgrade.Mangoes))
|
||||||
unlocked.Add((ItemType.Mango, MangoPrefab));
|
unlocked.Add(ItemType.Mango);
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.Durian))
|
if (UpgradeManager.Is(BasicUpgrade.Durian))
|
||||||
unlocked.Add((ItemType.Durian, DurianPrefab));
|
unlocked.Add(ItemType.Durian);
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.BuddhasHand))
|
if (UpgradeManager.Is(BasicUpgrade.BuddhasHand))
|
||||||
unlocked.Add((ItemType.BuddhasHand, BuddhasHandPrefab));
|
unlocked.Add(ItemType.BuddhasHand);
|
||||||
|
|
||||||
if (UpgradeManager.Is(BasicUpgrade.Pitayas))
|
if (UpgradeManager.Is(BasicUpgrade.Pitayas))
|
||||||
unlocked.Add((ItemType.Pitaya, PitayaPrefab));
|
unlocked.Add(ItemType.Pitaya);
|
||||||
|
|
||||||
GameObject parent = Instantiate(BaseItemPrefab, FruitSpawnParent);
|
GameObject parent = Instantiate(BaseItemPrefab, FruitSpawnParent);
|
||||||
|
ItemType type = unlocked[Random.Range(0, unlocked.Count)];
|
||||||
(ItemType type, GameObject prefab) = unlocked[Random.Range(0, unlocked.Count)];
|
|
||||||
GameObject go = Instantiate(prefab, parent.transform);
|
|
||||||
|
|
||||||
ItemBehaviour behaviour = parent.GetComponent<ItemBehaviour>();
|
ItemBehaviour behaviour = parent.GetComponent<ItemBehaviour>();
|
||||||
Debug.Assert(behaviour is not null, "Could not find ItemBehaviour");
|
Debug.Assert(behaviour is not null, "Could not find ItemBehaviour");
|
||||||
|
|
||||||
behaviour.InitBehaviour(GameCanvas, type);
|
behaviour.InitBehaviour(GameCanvas, type);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,12 +10,18 @@ namespace Fruitomation.Game.Items
|
|||||||
protected Canvas AttachedCanvas { get; private set; }
|
protected Canvas AttachedCanvas { get; private set; }
|
||||||
protected bool EnteredCanvas { get; private set; }
|
protected bool EnteredCanvas { get; private set; }
|
||||||
|
|
||||||
|
private GameObject CurrentChild;
|
||||||
|
|
||||||
private ItemType InternalItemType;
|
private ItemType InternalItemType;
|
||||||
|
|
||||||
public ItemType CurrentType
|
public ItemType CurrentType
|
||||||
{
|
{
|
||||||
get => InternalItemType;
|
get => InternalItemType;
|
||||||
set => InternalItemType = value;
|
set
|
||||||
|
{
|
||||||
|
InternalItemType = value;
|
||||||
|
OnUpdateItemType();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected virtual void OnInitialized() { }
|
protected virtual void OnInitialized() { }
|
||||||
@@ -25,15 +31,22 @@ namespace Fruitomation.Game.Items
|
|||||||
RectTransform = transform.GetComponent<RectTransform>();
|
RectTransform = transform.GetComponent<RectTransform>();
|
||||||
Body2D = transform.GetComponent<Rigidbody2D>();
|
Body2D = transform.GetComponent<Rigidbody2D>();
|
||||||
|
|
||||||
InternalItemType = startType;
|
|
||||||
AttachedCanvas = canvas;
|
AttachedCanvas = canvas;
|
||||||
|
CurrentType = startType;
|
||||||
EnteredCanvas = false;
|
EnteredCanvas = false;
|
||||||
|
|
||||||
OnInitialized();
|
OnInitialized();
|
||||||
}
|
}
|
||||||
|
|
||||||
private void UpdateItem()
|
private void OnUpdateItemType()
|
||||||
{
|
{
|
||||||
|
if (CurrentChild is not null)
|
||||||
|
{
|
||||||
|
Destroy(CurrentChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
ItemInfo info = ItemInfoRegistry.Get(CurrentType);
|
||||||
|
CurrentChild = Instantiate(info.Prefab, transform);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void Update()
|
protected void Update()
|
||||||
|
|||||||
@@ -18,6 +18,8 @@ namespace Fruitomation.Game.Items
|
|||||||
[Serializable] public class ItemInfo
|
[Serializable] public class ItemInfo
|
||||||
{
|
{
|
||||||
public ItemType Type;
|
public ItemType Type;
|
||||||
|
|
||||||
|
public GameObject Prefab;
|
||||||
public float MinMoney;
|
public float MinMoney;
|
||||||
public float MaxMoney;
|
public float MaxMoney;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user