Changed how items work
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
using PashaBibko.Pacore.Attributes;
|
||||
using System.Collections.Generic;
|
||||
using Fruitomation.Game.Items;
|
||||
using Fruitomation.Global;
|
||||
@@ -18,6 +17,7 @@ namespace Fruitomation.Game
|
||||
[SerializeField] private Canvas GameCanvas;
|
||||
|
||||
[Header("Prefabs")]
|
||||
[SerializeField] private GameObject BaseItemPrefab;
|
||||
[SerializeField] private GameObject ApplePrefab;
|
||||
[SerializeField] private GameObject GrapePrefab;
|
||||
[SerializeField] private GameObject BananaPrefab;
|
||||
@@ -47,36 +47,38 @@ namespace Fruitomation.Game
|
||||
|
||||
private void SpawnFruit()
|
||||
{
|
||||
List<GameObject> unlocked = new() { ApplePrefab };
|
||||
List<(ItemType, GameObject)> unlocked = new() { (ItemType.Apple, ApplePrefab) };
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.Grapes))
|
||||
unlocked.Add(GrapePrefab);
|
||||
unlocked.Add((ItemType.Grape, GrapePrefab));
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.Bananas))
|
||||
unlocked.Add(BananaPrefab);
|
||||
unlocked.Add((ItemType.Banana, BananaPrefab));
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.Kiwi))
|
||||
unlocked.Add(KiwiPrefab);
|
||||
unlocked.Add((ItemType.Kiwi, KiwiPrefab));
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.Mangoes))
|
||||
unlocked.Add(MangoPrefab);
|
||||
unlocked.Add((ItemType.Mango, MangoPrefab));
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.Durian))
|
||||
unlocked.Add(DurianPrefab);
|
||||
unlocked.Add((ItemType.Durian, DurianPrefab));
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.BuddhasHand))
|
||||
unlocked.Add(BuddhasHandPrefab);
|
||||
unlocked.Add((ItemType.BuddhasHand, BuddhasHandPrefab));
|
||||
|
||||
if (UpgradeManager.Is(BasicUpgrade.Pitayas))
|
||||
unlocked.Add(PitayaPrefab);
|
||||
unlocked.Add((ItemType.Pitaya, PitayaPrefab));
|
||||
|
||||
GameObject prefab = unlocked[Random.Range(0, unlocked.Count)];
|
||||
GameObject go = Instantiate(prefab, FruitSpawnParent);
|
||||
GameObject parent = Instantiate(BaseItemPrefab, FruitSpawnParent);
|
||||
|
||||
FruitBehaviour behaviour = go.GetComponent<FruitBehaviour>();
|
||||
Debug.Assert(behaviour is not null, "Could not find FruitBehaviour");
|
||||
(ItemType type, GameObject prefab) = unlocked[Random.Range(0, unlocked.Count)];
|
||||
GameObject go = Instantiate(prefab, parent.transform);
|
||||
|
||||
ItemBehaviour behaviour = parent.GetComponent<ItemBehaviour>();
|
||||
Debug.Assert(behaviour is not null, "Could not find ItemBehaviour");
|
||||
|
||||
behaviour.InitBehaviour(GameCanvas);
|
||||
behaviour.InitBehaviour(GameCanvas, type);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,12 +4,9 @@ namespace Fruitomation.Game.Items
|
||||
{
|
||||
public class FruitBehaviour : ItemBehaviour
|
||||
{
|
||||
[SerializeField] private ItemType OverridenItemType;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
Body2D.linearVelocity = Random.insideUnitCircle * 2.5f;
|
||||
CurrentType = OverridenItemType;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15,19 +15,17 @@ namespace Fruitomation.Game.Items
|
||||
public ItemType CurrentType
|
||||
{
|
||||
get => InternalItemType;
|
||||
set
|
||||
{
|
||||
InternalItemType = value;
|
||||
}
|
||||
set => InternalItemType = value;
|
||||
}
|
||||
|
||||
protected virtual void OnInitialized() { }
|
||||
|
||||
public void InitBehaviour(Canvas canvas)
|
||||
|
||||
public void InitBehaviour(Canvas canvas, ItemType startType)
|
||||
{
|
||||
RectTransform = transform.GetComponent<RectTransform>();
|
||||
Body2D = transform.GetComponent<Rigidbody2D>();
|
||||
|
||||
InternalItemType = startType;
|
||||
AttachedCanvas = canvas;
|
||||
EnteredCanvas = false;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user