Added custom item behaviour
This commit is contained in:
@@ -14,41 +14,49 @@ MonoBehaviour:
|
||||
m_EditorClassIdentifier: Fruitomation::Fruitomation.Game.Items.SerializedItemInfoRegistry
|
||||
Registry:
|
||||
- Type: 0
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: 23e3bfe33d8c6004c85fd638db567ab6,
|
||||
type: 3}
|
||||
MinMoney: 0.5
|
||||
MaxMoney: 1.5
|
||||
- Type: 1
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 8799415981405337049, guid: c21e0b5539573904cb10d979de4a3f72,
|
||||
type: 3}
|
||||
MinMoney: 3
|
||||
MaxMoney: 7
|
||||
- Type: 2
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: 5e1f7f5d4294c1d4fa3e6f88dec0dfa6,
|
||||
type: 3}
|
||||
MinMoney: 12
|
||||
MaxMoney: 18
|
||||
- Type: 3
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: b224b6df33529e64d83245d78e0feb9f,
|
||||
type: 3}
|
||||
MinMoney: 40
|
||||
MaxMoney: 60
|
||||
- Type: 4
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: 7af455f1c1666e5409156598fe669f74,
|
||||
type: 3}
|
||||
MinMoney: 120
|
||||
MaxMoney: 160
|
||||
- Type: 6
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: 13f2740b5ae396e40940587ab2effd65,
|
||||
type: 3}
|
||||
MinMoney: 250
|
||||
MaxMoney: 350
|
||||
- Type: 7
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: ebddb1b81a288cc4c993a25bc9efe894,
|
||||
type: 3}
|
||||
MinMoney: 800
|
||||
MaxMoney: 900
|
||||
- Type: 5
|
||||
CustomBehaviour: 1
|
||||
Prefab: {fileID: 4062657912758122058, guid: 2cf42dbc57bb6374b9e6ec700aad5854,
|
||||
type: 3}
|
||||
MinMoney: 2000
|
||||
|
||||
@@ -1,12 +1,14 @@
|
||||
using JetBrains.Annotations;
|
||||
using UnityEngine.Scripting;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Fruitomation.Game.Items
|
||||
{
|
||||
public class FruitBehaviour : ItemBehaviour
|
||||
[UsedImplicitly, Preserve] public class FruitBehaviour : CustomItemBehaviour
|
||||
{
|
||||
protected override void OnInitialized()
|
||||
public override void OnCreation()
|
||||
{
|
||||
Body2D.linearVelocity = Random.insideUnitCircle * 2.5f;
|
||||
AttachedItemBehaviour.Body2D.linearVelocity = Random.insideUnitCircle * 2.5f;
|
||||
}
|
||||
}
|
||||
}
|
||||
9
Assets/Scripts/Game/Items/ICustomItemBehaviour.cs
Normal file
9
Assets/Scripts/Game/Items/ICustomItemBehaviour.cs
Normal file
@@ -0,0 +1,9 @@
|
||||
namespace Fruitomation.Game.Items
|
||||
{
|
||||
public abstract class CustomItemBehaviour
|
||||
{
|
||||
public ItemBehaviour AttachedItemBehaviour;
|
||||
|
||||
public abstract void OnCreation();
|
||||
}
|
||||
}
|
||||
3
Assets/Scripts/Game/Items/ICustomItemBehaviour.cs.meta
Normal file
3
Assets/Scripts/Game/Items/ICustomItemBehaviour.cs.meta
Normal file
@@ -0,0 +1,3 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 77bf10644007434586ed2f8b9e640469
|
||||
timeCreated: 1776516125
|
||||
@@ -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;
|
||||
@@ -24,8 +26,6 @@ namespace Fruitomation.Game.Items
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnInitialized() { }
|
||||
|
||||
public void InitBehaviour(Canvas canvas, ItemType startType)
|
||||
{
|
||||
RectTransform = transform.GetComponent<RectTransform>();
|
||||
@@ -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))
|
||||
{
|
||||
|
||||
@@ -3,6 +3,13 @@ using System;
|
||||
|
||||
namespace Fruitomation.Game.Items
|
||||
{
|
||||
[Serializable] public enum CustomBehaviourType
|
||||
{
|
||||
None,
|
||||
|
||||
FruitBehaviour,
|
||||
}
|
||||
|
||||
[Serializable] public enum ItemType
|
||||
{
|
||||
Apple,
|
||||
@@ -58,9 +65,23 @@ namespace Fruitomation.Game.Items
|
||||
{
|
||||
public ItemType Type;
|
||||
|
||||
[SerializeField] private CustomBehaviourType CustomBehaviour;
|
||||
|
||||
public GameObject Prefab;
|
||||
public float MinMoney;
|
||||
public float MaxMoney;
|
||||
|
||||
public CustomItemBehaviour GetCustomBehaviour()
|
||||
{
|
||||
return CustomBehaviour switch
|
||||
{
|
||||
CustomBehaviourType.None => null,
|
||||
|
||||
CustomBehaviourType.FruitBehaviour => new FruitBehaviour(),
|
||||
|
||||
var _ => throw new ArgumentOutOfRangeException()
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
[CreateAssetMenu] public class SerializedItemInfoRegistry : ScriptableObject
|
||||
|
||||
Reference in New Issue
Block a user