Shegotwet/Assets/Scripts/Game/MiniGameObtacle.cs

138 lines
4.7 KiB
C#
Raw Normal View History

2025-09-14 05:09:31 +00:00
using GUPS.AntiCheat.Protected;
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.UI;
public enum eMiniGameObtacleType { White, Red, HpHeal, AlbumOpen, ChatCoin, GachaCoin, ItemBomb, ItemUmbrella, ItemDildo }
2025-09-14 05:09:31 +00:00
public class MiniGameObtacle : MonoBehaviour
{
public RectTransform m_RectTransform;
public Rigidbody2D m_Rigidbody2D;
public Image i_img;
2025-09-18 20:42:29 +00:00
public RectTransform tf_objend;
2025-09-14 05:09:31 +00:00
eMiniGameObtacleType m_Type;
ProtectedInt32 m_Dmg;
2025-09-18 20:42:29 +00:00
public void Set(Dictionary<eMiniGameObtacleType, int> dic_weight, RectTransform rtend)
2025-09-14 05:09:31 +00:00
{
gameObject.SetActive(true);
SetRandomTypeByWeight(dic_weight);
2025-09-18 20:42:29 +00:00
tf_objend = rtend;
2025-09-14 05:09:31 +00:00
m_Rigidbody2D.gravityScale = Random.Range(table_GlobalValue.Ins.Get_Float("MiniGameSpeedMin"),
table_GlobalValue.Ins.Get_Float("MiniGameSpeedMax"));
var x = (Screen.width >> 1) - 50;
m_RectTransform.anchoredPosition = new Vector2(Random.Range(-x, x), 0f);
switch (m_Type)
{
case eMiniGameObtacleType.White:
2025-09-18 20:21:29 +00:00
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("icon 1_mini game");
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_White_DMG");
2025-09-14 05:09:31 +00:00
break;
case eMiniGameObtacleType.Red:
2025-09-18 20:21:29 +00:00
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("icon 2_mini game");
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Red_DMG");
2025-09-14 05:09:31 +00:00
break;
case eMiniGameObtacleType.AlbumOpen:
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.AlbumOpen);
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Heart_Amount");
2025-09-14 05:09:31 +00:00
break;
case eMiniGameObtacleType.ChatCoin:
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Chat);
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_ChatCoin_Amount");
2025-09-14 05:09:31 +00:00
break;
case eMiniGameObtacleType.GachaCoin:
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Gacha);
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_GachaCoin_Amount");
2025-09-14 05:09:31 +00:00
break;
case eMiniGameObtacleType.HpHeal:
2025-09-18 20:21:29 +00:00
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("icon 5_mini game");
m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Heal");
2025-09-14 05:09:31 +00:00
break;
case eMiniGameObtacleType.ItemBomb:
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("item_bomb");
m_Dmg = 1;
break;
case eMiniGameObtacleType.ItemUmbrella:
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("item_umbrella");
m_Dmg = 1;
break;
case eMiniGameObtacleType.ItemDildo:
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("item_dildo");
m_Dmg = 1;
break;
2025-09-14 05:09:31 +00:00
}
2025-09-18 20:21:29 +00:00
i_img.SetNativeSize();
if (m_Type == eMiniGameObtacleType.AlbumOpen || m_Type == eMiniGameObtacleType.ChatCoin ||
m_Type == eMiniGameObtacleType.GachaCoin)
i_img.transform.localScale = Vector3.one * 0.5f;
2025-09-18 20:42:29 +00:00
else
i_img.transform.localScale = Vector3.one;
i_img.transform.eulerAngles = Vector3.zero;
m_Dmg.Obfuscate();
2025-09-14 05:09:31 +00:00
void SetRandomTypeByWeight(Dictionary<eMiniGameObtacleType, int> dic_weight)
{
// 총합
int totalWeight = dic_weight.Values.Sum();
if (totalWeight <= 0)
{
Debug.LogWarning("가중치 총합이 0 이하입니다. 기본값으로 White 선택.");
m_Type = eMiniGameObtacleType.White;
return;
}
// 랜덤 뽑기
int rand = Random.Range(0, totalWeight);
int cumulative = 0;
foreach (var pair in dic_weight)
{
cumulative += pair.Value;
if (rand < cumulative)
{
m_Type = pair.Key;
return;
}
}
}
}
private void Update()
{
2025-09-18 20:42:29 +00:00
if (m_RectTransform.position.y < tf_objend.position.y)
2025-09-14 05:09:31 +00:00
{
2025-09-14 07:05:38 +00:00
Off(false);
2025-09-14 05:09:31 +00:00
}
}
2025-09-16 00:55:24 +00:00
public void Off_OnlyObtacle()
{
if (m_Type == eMiniGameObtacleType.White || m_Type == eMiniGameObtacleType.Red)
Off(true);
}
void Off(bool showeffect, bool playsound = true)
2025-09-14 05:09:31 +00:00
{
gameObject.SetActive(false);
2025-09-14 07:05:38 +00:00
if (showeffect)
{
LobbyUI.Ins.m_Game_Mini.Show_HitEffect(m_RectTransform.position);
2025-09-16 00:55:24 +00:00
if (playsound)
SoundInfo.Ins.Play_OneShot(eSound.s002_Bubble, 1f);
2025-09-14 07:05:38 +00:00
}
2025-09-14 05:09:31 +00:00
}
private void OnTriggerEnter2D(Collider2D collision)
{
if (collision.tag.Equals("Player"))
{
2025-09-14 07:05:38 +00:00
Off(true);
2025-09-14 18:34:04 +00:00
LobbyUI.Ins.m_Game_Mini.Hit(m_Type, m_Dmg);
2025-09-14 05:09:31 +00:00
}
}
}