315 lines
12 KiB
C#
315 lines
12 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using Random = UnityEngine.Random;
|
|
|
|
public class GachaUI : uScrollViewMgr
|
|
{
|
|
public GameObject[] gos_grade;
|
|
public Slider[] slider_lucky, slider_lucky2;
|
|
public Image[] images_slider; // 알파 슬라이더 이미지들
|
|
public GameObject[] gos_sliderhandle;
|
|
public TextMeshProUGUI[] texts_money; // 0 앨범 오픈 재화, 1 챗 코인, 2 가챠 코인
|
|
public TextMeshProUGUI[] texts; // 0 럭키 %, 1 광고 충전량, 2 가챠 필요량, 3 충전 시간, 4 차징 시 획득량, 5 가챠 획득량
|
|
public TextMeshProUGUI[] texts_luckypoint; // 획득한 럭키 포인트들
|
|
public GameObject go_CanEnterLuckyGame, go_autocharge, go_gachaskip;
|
|
public Image i_Chest, i_GachaReward;
|
|
public Slider slider_charge;
|
|
|
|
DateTime GachaAutoRefillTime;
|
|
float fRefillTime, ToastY = -400f;
|
|
List<(eMoney, int)> list_log = new List<(eMoney, int)>();
|
|
Coroutine co_sliderupdate;
|
|
|
|
private void Start()
|
|
{
|
|
texts[1].text = $"{table_GlobalValue.Ins.Get_Float("GachaAD_Reward")}";
|
|
texts[2].text = $"{table_GlobalValue.Ins.Get_Int("GachaAmount")}";
|
|
texts[4].text = $"{table_GlobalValue.Ins.Get_Int("GachaAmount")}";
|
|
}
|
|
|
|
private void Update()
|
|
{
|
|
if (!SaveMgr.Ins.Check_Money(eMoney.Gacha, table_GlobalValue.Ins.Get_Int("GachaAmount"), false))
|
|
{
|
|
var cal = GachaAutoRefillTime - InternetTime.Ins.Time;
|
|
fRefillTime -= Time.deltaTime;
|
|
if (cal.TotalSeconds <= 0) fRefillTime = 0f;
|
|
texts[3].text = fRefillTime > 0f ? $"{fRefillTime:F1}s" : "0s";
|
|
var fRefillTimeMax = table_GlobalValue.Ins.Get_Float("GachaAutoRefill_DelayTime");
|
|
if (SaveMgr.Ins.GachaChargeTime_Reduce()) fRefillTimeMax -= fRefillTimeMax * 0.9f;
|
|
slider_charge.value = DSUtil.Get_SliderValue(fRefillTime / fRefillTimeMax);
|
|
if (cal.TotalSeconds <= 0 && fRefillTime <= 0f)
|
|
{
|
|
SaveMgr.Ins.Add_Money(eMoney.Gacha, table_GlobalValue.Ins.Get_Int("GachaAutoRefill_Amount"));
|
|
SaveMgr.Ins.Save();
|
|
LobbyUI.Ins.m_ToastUI.Set("별 코인이 자동 충전되었습니다.", ToastY);
|
|
|
|
Set_Money();
|
|
}
|
|
}
|
|
}
|
|
|
|
public void Set()
|
|
{
|
|
gameObject.SetActive(true);
|
|
SoundInfo.Ins.Play_BGM(eBGM.b005_Gacha);
|
|
DSUtil.InActivateGameObjects(gos_grade);
|
|
for (int i = 0; i < texts_luckypoint.Length; i++)
|
|
texts_luckypoint[i].alpha = 0f;
|
|
Set_UI(false);
|
|
Init_GachaAnim();
|
|
|
|
var cal = GachaAutoRefillTime - InternetTime.Ins.Time;
|
|
if (cal.TotalMilliseconds > 0f)
|
|
fRefillTime = (float)cal.TotalMilliseconds * 0.001f;
|
|
}
|
|
|
|
void Set_UI(bool updateSlider)
|
|
{
|
|
if (updateSlider)
|
|
{
|
|
if (co_sliderupdate != null) StopCoroutine(co_sliderupdate);
|
|
co_sliderupdate = StartCoroutine(Co_UpdateSlider());
|
|
}
|
|
else
|
|
{
|
|
var cal = SaveMgr.Ins.Get_Money(eMoney.Lucky) / table_GlobalValue.Ins.Get_Float("LuckyPoint");
|
|
slider_lucky[0].value = slider_lucky[1].value = DSUtil.Get_SliderValue(cal);
|
|
slider_lucky2[0].value = slider_lucky2[1].value = DSUtil.Get_SliderValue(cal - 1f);
|
|
images_slider[0].color = images_slider[1].color = Color.white;
|
|
texts[0].text = MyText.Get_PercentValueText_100_NoPoint(cal > 2f ? 2f : cal);
|
|
Set_SliderHandle();
|
|
}
|
|
|
|
go_CanEnterLuckyGame.SetActive(SaveMgr.Ins.Get_Money(eMoney.Lucky) >= table_GlobalValue.Ins.Get_Float("LuckyPoint"));
|
|
go_gachaskip.SetActive(false);
|
|
|
|
Set_Money();
|
|
}
|
|
|
|
void Set_SliderHandle()
|
|
{
|
|
gos_sliderhandle[0].SetActive(slider_lucky[0].value < 1f);
|
|
gos_sliderhandle[1].SetActive(slider_lucky[0].value >= 1f);
|
|
}
|
|
|
|
IEnumerator Co_UpdateSlider()
|
|
{
|
|
float lucky = SaveMgr.Ins.Get_Money(eMoney.Lucky) / table_GlobalValue.Ins.Get_Float("LuckyPoint");
|
|
float targetValue1 = Mathf.Min(lucky, 1f); // slider_lucky 목표
|
|
slider_lucky[1].value = targetValue1;
|
|
float targetValue2 = Mathf.Max(lucky - 1f, 0f); // slider_lucky2 목표
|
|
slider_lucky2[1].value = targetValue2;
|
|
|
|
gos_sliderhandle[0].SetActive(slider_lucky[0].value < 1f);
|
|
gos_sliderhandle[1].SetActive(slider_lucky[0].value >= 1f);
|
|
|
|
float duration = 0.5f; // 각 슬라이더당 시간
|
|
float elapsed = 0f;
|
|
|
|
// slider_lucky 먼저
|
|
var slider = slider_lucky[0];
|
|
var slider2 = slider_lucky2[0];
|
|
float startValue1 = slider.value;
|
|
while (elapsed < duration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
float t = Mathf.Clamp01(elapsed / duration);
|
|
slider.value = Mathf.Lerp(startValue1, targetValue1, t);
|
|
texts[0].text = MyText.Get_PercentValueText_100_NoPoint(slider.value + slider2.value);
|
|
Set_SliderHandle();
|
|
yield return null;
|
|
}
|
|
slider.value = targetValue1;
|
|
texts[0].text = MyText.Get_PercentValueText_100_NoPoint(slider.value + slider2.value);
|
|
|
|
// slider_lucky2 다음
|
|
elapsed = 0f;
|
|
float startValue2 = slider2.value;
|
|
while (elapsed < duration)
|
|
{
|
|
elapsed += Time.deltaTime;
|
|
float t = Mathf.Clamp01(elapsed / duration);
|
|
slider2.value = Mathf.Lerp(startValue2, targetValue2, t);
|
|
texts[0].text = MyText.Get_PercentValueText_100_NoPoint(slider.value + slider2.value);
|
|
Set_SliderHandle();
|
|
yield return null;
|
|
}
|
|
slider2.value = targetValue2;
|
|
texts[0].text = MyText.Get_PercentValueText_100_NoPoint(slider.value + slider2.value);
|
|
}
|
|
|
|
void Set_Money()
|
|
{
|
|
texts_money[0].text = SaveMgr.Ins.Get_Money(eMoney.AlbumOpen).ToString();
|
|
texts_money[1].text = SaveMgr.Ins.Get_Money(eMoney.Chat).ToString();
|
|
texts_money[2].text = SaveMgr.Ins.Get_Money(eMoney.Gacha).ToString();
|
|
|
|
go_autocharge.SetActive(!SaveMgr.Ins.Check_Money(eMoney.Gacha, table_GlobalValue.Ins.Get_Int("GachaAmount"), false));
|
|
}
|
|
|
|
public void OnClick_Lucky()
|
|
{
|
|
if (SaveMgr.Ins.Check_Money(eMoney.Lucky, table_GlobalValue.Ins.Get_Int("LuckyPoint"), true, ToastY))
|
|
{
|
|
Init_GachaAnim();
|
|
SaveMgr.Ins.Add_Money(eMoney.Lucky, -table_GlobalValue.Ins.Get_Int("LuckyPoint"));
|
|
SaveMgr.Ins.Save();
|
|
LobbyUI.Ins.m_Game_Lucky.Set();
|
|
Set_UI(false);
|
|
}
|
|
}
|
|
|
|
public void OnClick_AD()
|
|
{
|
|
if (SaveMgr.Ins.CanShowGachaAD())
|
|
{
|
|
ADInfo.Ins.Show_AD(false, () =>
|
|
{
|
|
SaveMgr.Ins.Add_Money(eMoney.Gacha, table_GlobalValue.Ins.Get_Int("GachaAD_Reward"));
|
|
SaveMgr.Ins.Save();
|
|
LobbyUI.Ins.m_ToastUI.Set($"뽑기 재화 {table_GlobalValue.Ins.Get_Int("GachaAD_Reward")}개를 획득했습니다.", ToastY);
|
|
Set_Money();
|
|
});
|
|
}
|
|
}
|
|
|
|
public void OnClick_Gacha()
|
|
{
|
|
if (!isGacha && SaveMgr.Ins.Check_Money(eMoney.Gacha, table_GlobalValue.Ins.Get_Int("GachaAmount"), true, ToastY))
|
|
{
|
|
isGacha = true;
|
|
Init_GachaAnim();
|
|
VideoMgr.Ins.PlayVideo(1f, () => { StartCoroutine(GachaReward()); });
|
|
//StartCoroutine(Co_Gacha());
|
|
}
|
|
}
|
|
|
|
public GameObject[] gos_effect;
|
|
bool isGacha = false;
|
|
|
|
void Init_GachaAnim()
|
|
{
|
|
DSUtil.InActivateGameObjects(gos_effect);
|
|
DSUtil.InActivateGameObjects(gos_grade);
|
|
i_Chest.gameObject.SetActive(false);
|
|
i_GachaReward.transform.parent.parent.gameObject.SetActive(false);
|
|
}
|
|
|
|
IEnumerator Co_Gacha()
|
|
{
|
|
isGacha = true;
|
|
Init_GachaAnim();
|
|
i_Chest.sprite = UIAtlasMgr.Ins.Get_Sprite($"GameBox-{Random.Range(0, 20)}");
|
|
gos_effect[5].SetActive(true); // 바닥 컬라이더
|
|
|
|
SoundInfo.Ins.Play_OneShot((eSound)Random.Range(12, 14));
|
|
|
|
i_Chest.gameObject.SetActive(true);
|
|
var rb2d = i_Chest.GetComponent<Rigidbody2D>();
|
|
rb2d.linearVelocity = Vector2.zero; // 이동 속도 초기화
|
|
rb2d.angularVelocity = 0f; // 회전 속도 초기화
|
|
rb2d.transform.rotation = Quaternion.identity; // 회전 초기화
|
|
i_Chest.GetComponent<RectTransform>().anchoredPosition = Vector2.up * 2000f;
|
|
|
|
yield return new WaitForSeconds(0.2f);
|
|
go_gachaskip.SetActive(true);
|
|
|
|
yield return new WaitForSeconds(1.1f);
|
|
|
|
// 바닥에 상자 부딪혔을 때 이펙트
|
|
gos_effect[0].SetActive(true);
|
|
|
|
yield return new WaitForSeconds(1.1f);
|
|
|
|
i_Chest.gameObject.SetActive(false);
|
|
yield return StartCoroutine(GachaReward());
|
|
}
|
|
|
|
IEnumerator GachaReward()
|
|
{
|
|
SaveMgr.Ins.Add_Money(eMoney.Gacha, -table_GlobalValue.Ins.Get_Int("GachaAmount"));
|
|
var gradedata = table_gacharateconfig.Ins.Get_RadomData();
|
|
var reward = table_gachareward.Ins.Get_Reward(gradedata.n_GachaGrade);
|
|
i_GachaReward.transform.parent.parent.gameObject.SetActive(true);
|
|
i_GachaReward.sprite = UIAtlasMgr.Ins.Get_Sprite(reward.Item1);
|
|
switch (reward.Item1)
|
|
{
|
|
case eMoney.AlbumOpen:
|
|
SoundInfo.Ins.Play_OneShot(eSound.s006_MiniGameGetHeart);
|
|
break;
|
|
case eMoney.Chat:
|
|
SoundInfo.Ins.Play_OneShot(eSound.s007_MiniGameGetChatCoint);
|
|
break;
|
|
case eMoney.Gacha:
|
|
SoundInfo.Ins.Play_OneShot(eSound.s008_MiniGameGetGachaCoin);
|
|
break;
|
|
}
|
|
SaveMgr.Ins.Add_Money(reward.Item1, reward.Item2);
|
|
texts[5].text = reward.Item2.ToString();
|
|
SaveMgr.Ins.Add_Money(eMoney.Lucky, reward.Item3);
|
|
SaveMgr.Ins.Save();
|
|
list_log.Add((reward.Item1, reward.Item2));
|
|
if (reward.Item3 > 0)
|
|
for (int i = 0; i < texts_luckypoint.Length; i++)
|
|
{
|
|
if (texts_luckypoint[i].alpha <= 0f)
|
|
{
|
|
texts_luckypoint[i].text = $"+{reward.Item3}";
|
|
texts_luckypoint[i].GetComponent<Animation>().Play();
|
|
break;
|
|
}
|
|
}
|
|
//list_log.Add((eMoney.Lucky, reward.Item3));
|
|
Set_ScrollView(list_log);
|
|
Set_Vertical_ScrollEnd(0);
|
|
Set_UI(true);
|
|
|
|
fRefillTime = table_GlobalValue.Ins.Get_Float("GachaAutoRefill_DelayTime");
|
|
if (SaveMgr.Ins.GachaChargeTime_Reduce()) fRefillTime -= fRefillTime * 0.9f;
|
|
GachaAutoRefillTime = InternetTime.Ins.Time.AddSeconds(fRefillTime);
|
|
|
|
switch (gradedata.n_GachaGrade)
|
|
{
|
|
case 1: case 2: case 3: gos_effect[1].SetActive(true); break;
|
|
case 4: case 5: gos_effect[2].SetActive(true); break;
|
|
case 6: case 7: gos_effect[3].SetActive(true); break;
|
|
case 8: case 9: gos_effect[4].SetActive(true); break;
|
|
}
|
|
|
|
yield return new WaitForSeconds(0.5f);
|
|
|
|
switch (gradedata.n_GachaGrade)
|
|
{
|
|
case 1: case 2: gos_grade[0].SetActive(true); break;
|
|
case 3: break;
|
|
default:
|
|
DSUtil.InActivateGameObjects(gos_grade, gradedata.n_GachaGrade - 2);
|
|
break;
|
|
}
|
|
isGacha = false;
|
|
}
|
|
|
|
public void OnClick_Skip()
|
|
{
|
|
if (!isGacha) return;
|
|
|
|
StopAllCoroutines();
|
|
|
|
//AnimationState state = m_GachaAnim["Gacha"];
|
|
//state.normalizedTime = 0.8f; // 지점 이동
|
|
//m_GachaAnim.Sample(); // 즉시 반영
|
|
|
|
Init_GachaAnim();
|
|
StartCoroutine(GachaReward());
|
|
}
|
|
|
|
public void OnClick_GachaRate()
|
|
{
|
|
Application.OpenURL("https://mergehero.notion.site/2a7e9deec1718038bae6dbce1a91f4c4");
|
|
}
|
|
} |