Assign GemSprite to BombPrefab
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using Enums;
|
||||
using Structs;
|
||||
using UnityEngine;
|
||||
|
||||
namespace Services {
|
||||
@@ -14,10 +15,10 @@ namespace Services {
|
||||
private GemType colorType;
|
||||
public GemType MatchColor => this.type == GemType.Bomb ? this.colorType : this.type;
|
||||
|
||||
public Gem(GemType type, Vector2Int position, int scoreValue, GemType? colorType = null) {
|
||||
public Gem(GemType type, Vector2Int position, GemTypeValues gemValue, GemType? colorType = null) {
|
||||
this.type = type;
|
||||
this.position = position;
|
||||
this.scoreValue = scoreValue;
|
||||
this.scoreValue = gemValue.scoreValue;
|
||||
|
||||
this.colorType = colorType ?? type;
|
||||
}
|
||||
|
||||
@@ -83,11 +83,12 @@ namespace Services {
|
||||
GemView gemView = this.objectPool.Get(gemType, position, this.gameVariables.dropHeight);
|
||||
gemView.name = "Gem - " + position.x + ", " + position.y + ' ' + gemType;
|
||||
|
||||
GemTypeValues gemValue = GemUtils.GetGemValues(gemType, this.gameVariables.gemsPrefabs);
|
||||
|
||||
// If we randomly spawned a bomb, give it a random color group (so it can match by color).
|
||||
int scoreValue = GemUtils.GetGemValues(gemType, this.gameVariables.gemsPrefabs).scoreValue;
|
||||
Gem gem = new Gem(gemType, position, scoreValue);
|
||||
Gem gem = new Gem(gemType, position, gemValue);
|
||||
|
||||
gemView.Bind(gem);
|
||||
gemView.Bind(gem, gemValue);
|
||||
|
||||
this.gemPresenters.Add(new GemPresenter(gem, gemView));
|
||||
SetGem(new Vector2Int(position.x, position.y), gem);
|
||||
@@ -99,10 +100,11 @@ namespace Services {
|
||||
|
||||
GemView gemView = this.objectPool.Get(GemType.Bomb, position, 0);
|
||||
gemView.name = "Bomb - " + position.x + ", " + position.y + ' ' + GemType.Bomb;
|
||||
|
||||
GemTypeValues gemValue = GemUtils.GetGemValues(color, this.gameVariables.gemsPrefabs);
|
||||
|
||||
int scoreValue = GemUtils.GetGemValues(color, this.gameVariables.gemsPrefabs).scoreValue;
|
||||
Gem bombGem = new Gem(GemType.Bomb, position, scoreValue, color);
|
||||
gemView.Bind(bombGem, isBomb: true);
|
||||
Gem bombGem = new Gem(GemType.Bomb, position, gemValue, color);
|
||||
gemView.Bind(bombGem, gemValue, isBomb: true);
|
||||
|
||||
this.gemPresenters.Add(new GemPresenter(bombGem, gemView));
|
||||
SetGem(position, bombGem);
|
||||
|
||||
@@ -9,6 +9,7 @@ namespace Structs {
|
||||
public GemType type;
|
||||
public GemView gemPrefab;
|
||||
public GameObject explosionPrefab;
|
||||
public Sprite gemSprite;
|
||||
public int scoreValue;
|
||||
}
|
||||
}
|
||||
@@ -2,45 +2,47 @@ using System.Threading;
|
||||
using Cysharp.Threading.Tasks;
|
||||
using Enums;
|
||||
using Services;
|
||||
using Structs;
|
||||
using UnityEngine;
|
||||
using Utils;
|
||||
|
||||
namespace Views {
|
||||
public class GemView : MonoBehaviour {
|
||||
[SerializeField]
|
||||
private SpriteRenderer childSpriteRenderer;
|
||||
|
||||
private Gem gem;
|
||||
public Gem Gem => this.gem;
|
||||
|
||||
private SpriteRenderer spriteRenderer;
|
||||
|
||||
private bool isFalling;
|
||||
private const float SPAWN_SCALE_FROM = 0f;
|
||||
private const float SPAWN_SCALE_DURATION = 0.12f;
|
||||
|
||||
private CancellationTokenSource spawnScaleCts;
|
||||
|
||||
public void Bind(Gem gem, bool isBomb = false) {
|
||||
public void Bind(Gem gem, GemTypeValues gemvalue, bool isBomb = false) {
|
||||
this.gem = gem;
|
||||
this.gameObject.SetActive(true);
|
||||
|
||||
SetupGem(isBomb);
|
||||
SetupGem(isBomb, gemvalue.gemSprite);
|
||||
PlaySpawnScale();
|
||||
}
|
||||
|
||||
private void SetupGem(bool isBomb) {
|
||||
this.spriteRenderer ??= GetComponent<SpriteRenderer>();
|
||||
private void SetupGem(bool isBomb, Sprite gemSprite = null) {
|
||||
if (!isBomb)
|
||||
return;
|
||||
|
||||
if (isBomb) {
|
||||
this.spriteRenderer.color = this.gem.MatchColor switch {
|
||||
GemType.Blue => Color.blue,
|
||||
GemType.Green => Color.green,
|
||||
GemType.Red => Color.red,
|
||||
GemType.Yellow => Color.yellow,
|
||||
GemType.Purple => Color.magenta,
|
||||
_ => this.spriteRenderer.color
|
||||
};
|
||||
if (this.childSpriteRenderer is null)
|
||||
return;
|
||||
|
||||
if (gemSprite != null) {
|
||||
this.childSpriteRenderer.enabled = true;
|
||||
this.childSpriteRenderer.sprite = gemSprite;
|
||||
} else {
|
||||
this.spriteRenderer.color = Color.white;
|
||||
this.childSpriteRenderer.enabled = false;
|
||||
this.childSpriteRenderer.color = Color.white;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public void Unbind() {
|
||||
|
||||
Reference in New Issue
Block a user