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 } public class MiniGameObtacle : MonoBehaviour { public RectTransform m_RectTransform; public Rigidbody2D m_Rigidbody2D; public Image i_img; eMiniGameObtacleType m_Type; ProtectedInt32 m_Dmg; public void Set(Dictionary dic_weight) { gameObject.SetActive(true); SetRandomTypeByWeight(dic_weight); 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); i_img.color = Color.white; switch (m_Type) { case eMiniGameObtacleType.White: i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("whitecircle"); m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_White_DMG"); break; case eMiniGameObtacleType.Red: i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("whitecircle"); i_img.color = Color.red; m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Red_DMG"); break; case eMiniGameObtacleType.AlbumOpen: i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.AlbumOpen); m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Heart_Amount"); break; case eMiniGameObtacleType.ChatCoin: i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Chat); m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_ChatCoin_Amount"); break; case eMiniGameObtacleType.GachaCoin: i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Gacha); m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_GachaCoin_Amount"); break; case eMiniGameObtacleType.HpHeal: i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("hp"); m_Dmg = table_GlobalValue.Ins.Get_Int("MiniGame_Heal"); 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; } m_Dmg.Obfuscate(); void SetRandomTypeByWeight(Dictionary 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() { if (m_RectTransform.anchoredPosition.y < -Screen.height) { Off(false); } } void Off(bool showeffect) { gameObject.SetActive(false); if (showeffect) { LobbyUI.Ins.m_Game_Mini.Show_HitEffect(m_RectTransform.position); SoundInfo.Ins.Play_OneShot(eSound.s002_Bubble, 1f); } } private void OnTriggerEnter2D(Collider2D collision) { if (collision.tag.Equals("Player")) { Off(true); LobbyUI.Ins.m_Game_Mini.Hit(m_Type, m_Dmg); } } }