MatchablePool.cs
unknown
csharp
a year ago
1.8 kB
22
Indexable
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
public class MatchablePool : ObjectPool<Matchable>
{
[SerializeField] private int howManyTypes;
[SerializeField] private Sprite[] sprites;
[SerializeField] private Color[] colors;
[SerializeField] private Sprite match4PowerUp;
[SerializeField] private Sprite match5PowerUp;
[SerializeField] private Sprite crossMatchPowerUp;
public void RandomizeType(Matchable toRandomize)
{
int random = Random.Range(0,howManyTypes);
toRandomize.SetType(random, sprites[random], colors[random]);
}
public Matchable GetRandomMatchable()
{
Matchable randomMatchable = GetPooledObject();
RandomizeType(randomMatchable);
return randomMatchable;
}
public Matchable UpgradeMatchable(Matchable toBeUpgraded, MatchType matchType)
{
if (matchType == MatchType.cross)
return toBeUpgraded.Upgrade(MatchType.cross,crossMatchPowerUp);
if (matchType == MatchType.match4)
return toBeUpgraded.Upgrade(MatchType.match4,match4PowerUp);
if (matchType == MatchType.match5)
return toBeUpgraded.Upgrade(MatchType.match5,match5PowerUp);
Debug.LogWarning("Tried to upgrade a matchable with an invalid match type");
return toBeUpgraded;
}
public int NextType(Matchable matchable)
{
int nextType = (matchable.Type + 1) % howManyTypes ;
matchable.SetType(nextType, sprites[nextType], colors[nextType]);
return nextType;
}
public void ChangeType(Matchable toChanged, int type)
{
toChanged.SetType(type, sprites[type], colors[type]);
}
}
Editor is loading...
Leave a Comment