Made item sprites able to be easily changed
This commit is contained in:
@@ -10,12 +10,18 @@ namespace Fruitomation.Game.Items
|
||||
protected Canvas AttachedCanvas { get; private set; }
|
||||
protected bool EnteredCanvas { get; private set; }
|
||||
|
||||
private GameObject CurrentChild;
|
||||
|
||||
private ItemType InternalItemType;
|
||||
|
||||
public ItemType CurrentType
|
||||
{
|
||||
get => InternalItemType;
|
||||
set => InternalItemType = value;
|
||||
set
|
||||
{
|
||||
InternalItemType = value;
|
||||
OnUpdateItemType();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnInitialized() { }
|
||||
@@ -25,15 +31,22 @@ namespace Fruitomation.Game.Items
|
||||
RectTransform = transform.GetComponent<RectTransform>();
|
||||
Body2D = transform.GetComponent<Rigidbody2D>();
|
||||
|
||||
InternalItemType = startType;
|
||||
AttachedCanvas = canvas;
|
||||
CurrentType = startType;
|
||||
EnteredCanvas = false;
|
||||
|
||||
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()
|
||||
|
||||
@@ -18,6 +18,8 @@ namespace Fruitomation.Game.Items
|
||||
[Serializable] public class ItemInfo
|
||||
{
|
||||
public ItemType Type;
|
||||
|
||||
public GameObject Prefab;
|
||||
public float MinMoney;
|
||||
public float MaxMoney;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user