Shegotwet/Assets/Scripts/Game/Game_Mini.cs

113 lines
3.6 KiB
C#
Raw Normal View History

2025-09-14 04:12:35 +00:00
using GUPS.AntiCheat.Protected;
using System.Collections;
2025-09-14 05:09:31 +00:00
using System.Collections.Generic;
2025-09-14 04:12:35 +00:00
using UnityEngine;
using UnityEngine.ResourceManagement.AsyncOperations;
using UnityEngine.UI;
public class Game_Mini : MonoBehaviour
{
public Image i_girl, i_girlsd;
public MiniGameItemCard[] items;
public Slider slider_hp;
2025-09-14 05:09:31 +00:00
public Transform tf_obtacleParent;
public GameObject go_Obtacle;
2025-09-14 04:12:35 +00:00
// 1 평소, 2 맞았을 때
AsyncOperationHandle<Sprite> m_Handle1, m_Handle2, m_HandleSD;
ProtectedInt32 m_HP;
2025-09-14 05:09:31 +00:00
Dictionary<eMiniGameObtacleType, int> dic_weight = new Dictionary<eMiniGameObtacleType, int>();
List<MiniGameObtacle> list_MiniGameObtacle = new List<MiniGameObtacle>();
2025-09-14 04:12:35 +00:00
public void Set()
{
2025-09-14 05:09:31 +00:00
if (dic_weight.Count == 0)
{
dic_weight.Add(eMiniGameObtacleType.White, table_GlobalValue.Ins.Get_Int("MiniGameWeight_White"));
dic_weight.Add(eMiniGameObtacleType.Red, table_GlobalValue.Ins.Get_Int("MiniGameWeight_Red"));
dic_weight.Add(eMiniGameObtacleType.AlbumOpen, table_GlobalValue.Ins.Get_Int("MiniGameWeight_AlbumOpen"));
dic_weight.Add(eMiniGameObtacleType.ChatCoin, table_GlobalValue.Ins.Get_Int("MiniGameWeight_ChatCoin"));
dic_weight.Add(eMiniGameObtacleType.GachaCoin, table_GlobalValue.Ins.Get_Int("MiniGameWeight_GachaCoin"));
dic_weight.Add(eMiniGameObtacleType.HpHeal, table_GlobalValue.Ins.Get_Int("MiniGameWeight_HpHeal"));
}
2025-09-14 04:12:35 +00:00
gameObject.SetActive(true);
for (int i = 0; i < items.Length; i++)
items[i].Set();
i_girl.enabled = false;
AddrResourceMgr.Ins.LoadObject<Sprite>($"Girl_Game/{SaveMgr.Ins.Get_SelectGirlID()}-1.png", handle =>
{
m_Handle1 = handle;
i_girl.enabled = true;
i_girl.sprite = handle.Result;
});
AddrResourceMgr.Ins.LoadObject<Sprite>($"Girl_Game/{SaveMgr.Ins.Get_SelectGirlID()}-2.png", handle =>
{
m_Handle2 = handle;
});
i_girlsd.enabled = false;
AddrResourceMgr.Ins.LoadObject<Sprite>($"Girl_Game/{SaveMgr.Ins.Get_SelectGirlID()}sd.png", handle =>
{
m_HandleSD = handle;
i_girlsd.enabled = true;
i_girlsd.sprite = handle.Result;
});
slider_hp.value = 1f;
m_HP = table_GlobalValue.Ins.Get_Int("MiniGameHP");
m_HP.Obfuscate();
2025-09-14 05:09:31 +00:00
StartCoroutine(Co_Update());
}
IEnumerator Co_Update()
{
yield return new WaitForSeconds(3f);
float gap = 0.5f;
list_MiniGameObtacle.ForEach(f => f.gameObject.SetActive(false));
while (true)
{
if (m_HP <= 0) break;
var obtacle = list_MiniGameObtacle.Find(f => !f.gameObject.activeInHierarchy);
if (obtacle == null)
{
obtacle = DSUtil.Get_Clone<MiniGameObtacle>(go_Obtacle, tf_obtacleParent);
list_MiniGameObtacle.Add(obtacle);
}
obtacle.Set(dic_weight);
yield return new WaitForSeconds(gap);
gap -= Time.deltaTime;
if (gap < 0.1f) gap = 0.1f;
}
2025-09-14 04:12:35 +00:00
}
2025-09-14 05:09:31 +00:00
Coroutine cohit;
public void Hit()
{
if (cohit != null) StopCoroutine(cohit);
cohit = StartCoroutine(Co_Hit());
}
2025-09-14 04:12:35 +00:00
IEnumerator Co_Hit()
{
--m_HP;
m_HP.Obfuscate();
slider_hp.value = m_HP / table_GlobalValue.Ins.Get_Float("MiniGameHP");
if (m_HP <= 0) GameOver();
i_girl.sprite = m_Handle2.Result;
yield return new WaitForSeconds(0.5f);
i_girl.sprite = m_Handle1.Result;
}
void GameOver()
{
}
}