Added custom item behaviour
This commit is contained in:
@@ -3,13 +3,15 @@ using UnityEngine;
|
||||
|
||||
namespace Fruitomation.Game.Items
|
||||
{
|
||||
public class ItemBehaviour : MonoBehaviour
|
||||
public sealed class ItemBehaviour : MonoBehaviour
|
||||
{
|
||||
protected RectTransform RectTransform { get; private set; }
|
||||
protected Rigidbody2D Body2D { get; private set; }
|
||||
protected Canvas AttachedCanvas { get; private set; }
|
||||
protected bool EnteredCanvas { get; private set; }
|
||||
public RectTransform RectTransform { get; private set; }
|
||||
public Rigidbody2D Body2D { get; private set; }
|
||||
|
||||
private Canvas AttachedCanvas { get; set; }
|
||||
private bool EnteredCanvas { get; set; }
|
||||
|
||||
private CustomItemBehaviour CustomBehaviour;
|
||||
private GameObject CurrentChild;
|
||||
|
||||
private ItemType InternalItemType;
|
||||
@@ -23,8 +25,6 @@ namespace Fruitomation.Game.Items
|
||||
OnUpdateItemType();
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnInitialized() { }
|
||||
|
||||
public void InitBehaviour(Canvas canvas, ItemType startType)
|
||||
{
|
||||
@@ -35,21 +35,29 @@ namespace Fruitomation.Game.Items
|
||||
CurrentType = startType;
|
||||
EnteredCanvas = false;
|
||||
|
||||
OnInitialized();
|
||||
CustomBehaviour?.OnCreation();
|
||||
}
|
||||
|
||||
private void OnUpdateItemType()
|
||||
{
|
||||
if (CurrentChild is not null)
|
||||
{
|
||||
CustomBehaviour = null;
|
||||
Destroy(CurrentChild);
|
||||
}
|
||||
|
||||
ItemInfo info = ItemInfoRegistry.Get(CurrentType);
|
||||
CurrentChild = Instantiate(info.Prefab, transform);
|
||||
|
||||
CustomBehaviour = info.GetCustomBehaviour();
|
||||
if (CustomBehaviour is not null)
|
||||
{
|
||||
CustomBehaviour.AttachedItemBehaviour = this;
|
||||
CustomBehaviour.OnCreation();
|
||||
}
|
||||
}
|
||||
|
||||
protected void Update()
|
||||
private void Update()
|
||||
{
|
||||
if (!GameStateController.Is(GameState.Simulation))
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user