nightward/Assets/Resources/Prefabs/HorseRush/Script/BubbleCard.cs

86 lines
2.9 KiB
C#
Raw Normal View History

2025-11-25 19:58:58 +00:00
using System.Collections;
using System.Collections.Generic;
using DG.Tweening;
using UnityEngine;
using UnityEngine.UI;
public class BubbleCard : MonoBehaviour
{
[SerializeField] GameObject _leftItem;
[SerializeField] GameObject _rightItem;
public bool IsLeftCarrot { get; private set; }
public bool IsGoldCarrot { get; private set; }
public bool IsSkullStone { get; private set; }
public bool IsFever { get; private set; }
float APPEAR_GOLD_CARROT_RATE;
float APPEAR_SKULL_RATE;
void Awake()
{
APPEAR_GOLD_CARROT_RATE = 100f;
APPEAR_SKULL_RATE = 200f;
}
public void SetScale(int index, float moveTime)
{
Vector3 scale = index == 10 ? new Vector3(1.2f, 1.2f, 1.2f) : index == 11 ? new Vector3(1.5f, 1.5f, 1.5f) : index == 0 ? new Vector3(0.5f, 0.5f, 0.5f) : Vector3.one;
_leftItem.transform.DOScale(scale, moveTime);
_rightItem.transform.DOScale(scale, moveTime);
}
public void SetCard(bool isFever)
{
IsFever = isFever;
string defaultPath = "Prefabs/HorseRush/Image/";
// 좌우 중 어떤쪽이 당근일지 랜덤
bool isLeftCarrot = Random.Range(0, 2) == 0;
IsLeftCarrot = isLeftCarrot;
GameObject carrotObject = isLeftCarrot ? _leftItem : _rightItem;
GameObject stoneObject = isLeftCarrot ? _rightItem : _leftItem;
if (isFever)
{
IsGoldCarrot = true;
carrotObject.GetComponent<Image>().sprite = Resources.Load<Sprite>(defaultPath + "Bubble_Fever");
stoneObject.GetComponent<Image>().sprite = Resources.Load<Sprite>(defaultPath + "Bubble_Fever");
}
else
{
// HorseRushManager.Instance.APPEAR_GOLD_CARROT_RATE
bool isGoldCarrot = Random.Range(0, 10000) <= APPEAR_GOLD_CARROT_RATE;
IsGoldCarrot = isGoldCarrot;
bool isSkullStone = Random.Range(0, 10000) <= APPEAR_SKULL_RATE;
IsSkullStone = isSkullStone;
carrotObject.GetComponent<Image>().sprite = Resources.Load<Sprite>(defaultPath + (isGoldCarrot ? "Bubble_GoldedCarrot" : "Bubble_Carrot"));
stoneObject.GetComponent<Image>().sprite = Resources.Load<Sprite>(defaultPath + (isSkullStone ? "Bubble_Stun" : "Bubble_Stone"));
}
}
public void SetOpacity(int index, bool isFever)
{
if (!isFever)
{
float opacity = Mathf.Clamp01(index / 10f);
_leftItem.GetComponent<Image>().color = new Color(1f, 1f, 1f, opacity);
_rightItem.GetComponent<Image>().color = new Color(1f, 1f, 1f, opacity);
}
else
{
// 12: 100%, 11: 60%, 10 : 30%, 이하 0%
float opacity = index == 12 ? 1f : index >= 11 ? 0.5f : 0.1f;
_leftItem.GetComponent<Image>().color = new Color(1f, 1f, 1f, opacity);
_rightItem.GetComponent<Image>().color = new Color(1f, 1f, 1f, opacity);
}
}
}