105 lines
3.1 KiB
C#
105 lines
3.1 KiB
C#
using GUPS.AntiCheat.Protected;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
|
|
public enum eMiniGameObtacleType { White, Red, AlbumOpen, ChatCoin, GachaCoin, HpHeal }
|
|
|
|
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<eMiniGameObtacleType, int> dic_weight)
|
|
{
|
|
gameObject.SetActive(true);
|
|
SetRandomTypeByWeight(dic_weight);
|
|
m_Dmg = m_Type == eMiniGameObtacleType.Red ? 2 : 1;
|
|
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");
|
|
break;
|
|
case eMiniGameObtacleType.Red:
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("whitecircle");
|
|
i_img.color = Color.red;
|
|
break;
|
|
case eMiniGameObtacleType.AlbumOpen:
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.AlbumOpen);
|
|
break;
|
|
case eMiniGameObtacleType.ChatCoin:
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Chat);
|
|
break;
|
|
case eMiniGameObtacleType.GachaCoin:
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite(eMoney.Gacha);
|
|
break;
|
|
case eMiniGameObtacleType.HpHeal:
|
|
i_img.sprite = UIAtlasMgr.Ins.Get_Sprite("hp");
|
|
break;
|
|
}
|
|
|
|
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()
|
|
{
|
|
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);
|
|
}
|
|
}
|
|
} |