2025-09-12 19:39:24 +00:00
|
|
|
using GUPS.AntiCheat.Protected;
|
|
|
|
|
using UnityEngine;
|
2025-09-12 19:51:36 +00:00
|
|
|
using UnityEngine.UI;
|
2025-09-12 19:39:24 +00:00
|
|
|
|
|
|
|
|
public class LuckyGameObj : MonoBehaviour
|
|
|
|
|
{
|
2025-09-12 19:51:36 +00:00
|
|
|
public Image m_image;
|
|
|
|
|
public GameObject go_effect;
|
2025-09-12 20:15:49 +00:00
|
|
|
public Rigidbody2D m_Rigidbody2D;
|
2025-09-28 08:27:12 +00:00
|
|
|
public Collider2D m_Collider2D;
|
2025-09-12 19:51:36 +00:00
|
|
|
|
2025-09-28 08:27:12 +00:00
|
|
|
bool isInCup, isCollision, isRandomBlock;
|
2025-09-23 20:50:18 +00:00
|
|
|
public float velocityThreshold = 0.1f; // 이 값 이하이면 "거의 없음"으로 판단
|
|
|
|
|
float stoppedTime = 0f;
|
|
|
|
|
public float requiredStopDuration = 0.2f; // 0.2초 이상 멈춰야 인정
|
2025-09-28 00:24:49 +00:00
|
|
|
Transform tf_fallobjs;
|
2025-10-02 18:59:20 +00:00
|
|
|
eMoney m_Money;
|
2025-09-23 20:50:18 +00:00
|
|
|
|
|
|
|
|
void Update()
|
|
|
|
|
{
|
2025-09-28 00:24:49 +00:00
|
|
|
if (!isInCup && !isCollision && IsAlmostStopped())
|
2025-09-23 20:50:18 +00:00
|
|
|
{
|
2025-09-25 05:57:17 +00:00
|
|
|
//Debug.Log("움직임이 거의 없음");
|
2025-09-23 20:50:18 +00:00
|
|
|
Set_Collision(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool IsAlmostStopped()
|
|
|
|
|
{
|
|
|
|
|
bool almostStoppedNow =
|
|
|
|
|
m_Rigidbody2D.linearVelocity.sqrMagnitude < velocityThreshold * velocityThreshold &&
|
|
|
|
|
Mathf.Abs(m_Rigidbody2D.angularVelocity) < velocityThreshold;
|
|
|
|
|
|
|
|
|
|
if (almostStoppedNow)
|
|
|
|
|
stoppedTime += Time.deltaTime;
|
|
|
|
|
else
|
|
|
|
|
stoppedTime = 0f;
|
|
|
|
|
|
|
|
|
|
return stoppedTime >= requiredStopDuration;
|
|
|
|
|
}
|
2025-09-12 19:39:24 +00:00
|
|
|
|
2025-10-02 18:59:20 +00:00
|
|
|
public void Init(eMoney money, Vector3 pos, Transform tfcupin, Transform tffallobjs)
|
2025-09-12 19:39:24 +00:00
|
|
|
{
|
2025-09-28 00:24:49 +00:00
|
|
|
transform.parent = tfcupin;
|
2025-10-02 19:08:57 +00:00
|
|
|
Init_Common(money, pos, tffallobjs);
|
2025-09-12 20:15:49 +00:00
|
|
|
|
2025-09-28 08:27:12 +00:00
|
|
|
isRandomBlock = isCollision = false;
|
|
|
|
|
m_Collider2D.enabled = isInCup = m_image.enabled = true;
|
|
|
|
|
}
|
2025-10-02 19:08:57 +00:00
|
|
|
public void Init_Add(eMoney money, Vector3 pos, Transform tffallobjs)
|
|
|
|
|
{
|
|
|
|
|
transform.parent = tffallobjs;
|
|
|
|
|
Init_Common(money, pos, tffallobjs);
|
|
|
|
|
|
|
|
|
|
isInCup = isCollision = false;
|
|
|
|
|
isRandomBlock = m_Collider2D.enabled = m_image.enabled = true;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
void Init_Common(eMoney money, Vector3 pos, Transform tffallobjs)
|
2025-09-28 08:27:12 +00:00
|
|
|
{
|
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
|
|
2025-10-02 19:08:57 +00:00
|
|
|
m_Money = money;
|
2025-09-28 08:27:12 +00:00
|
|
|
transform.localPosition = pos;
|
|
|
|
|
tf_fallobjs = tffallobjs;
|
|
|
|
|
|
2025-10-02 19:08:57 +00:00
|
|
|
m_image.sprite = UIAtlasMgr.Ins.Get_Sprite(m_Money);
|
2025-09-12 19:51:36 +00:00
|
|
|
go_effect.SetActive(false);
|
2025-09-12 20:15:49 +00:00
|
|
|
m_Rigidbody2D.bodyType = RigidbodyType2D.Dynamic;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void StopObj()
|
|
|
|
|
{
|
|
|
|
|
m_Rigidbody2D.bodyType = RigidbodyType2D.Kinematic;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 00:24:49 +00:00
|
|
|
public void Set_NoInCup()
|
2025-09-12 20:15:49 +00:00
|
|
|
{
|
2025-09-28 00:24:49 +00:00
|
|
|
isInCup = false;
|
2025-09-12 19:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void OnCollisionEnter2D(Collision2D collision)
|
|
|
|
|
{
|
2025-09-28 00:24:49 +00:00
|
|
|
if (isInCup || isCollision || collision == null) return;
|
2025-09-12 19:39:24 +00:00
|
|
|
|
2025-09-23 20:50:18 +00:00
|
|
|
//Debug.Log(collision.collider.tag + " : " + collision.collider.name);
|
2025-09-12 20:15:49 +00:00
|
|
|
switch (collision.collider.tag)
|
|
|
|
|
{
|
|
|
|
|
case "Player":
|
2025-09-28 08:27:12 +00:00
|
|
|
Set_Collision(1);
|
2025-09-12 20:15:49 +00:00
|
|
|
break;
|
|
|
|
|
case "Finish":
|
|
|
|
|
Set_Collision(0);
|
|
|
|
|
break;
|
2025-09-12 19:39:24 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-12 20:15:49 +00:00
|
|
|
|
2025-09-12 20:45:21 +00:00
|
|
|
private void OnTriggerEnter2D(Collider2D collision)
|
|
|
|
|
{
|
|
|
|
|
switch (collision.tag)
|
|
|
|
|
{
|
|
|
|
|
case "RandomBlock":
|
2025-09-28 08:27:12 +00:00
|
|
|
if (!isRandomBlock)
|
|
|
|
|
{
|
|
|
|
|
isRandomBlock = true;
|
|
|
|
|
var lrb = collision.GetComponent<LuckyRandomBlock>();
|
|
|
|
|
var addAmount = lrb.Get_Value(1);
|
|
|
|
|
for (int i = 0; i < addAmount - 1; i++)
|
|
|
|
|
{ // 공 추가하기
|
2025-10-02 19:08:57 +00:00
|
|
|
LobbyUI.Ins.m_Game_Lucky.Add_Ball(m_Money, transform.localPosition);
|
2025-09-28 08:27:12 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-12 20:45:21 +00:00
|
|
|
break;
|
2025-09-28 00:24:49 +00:00
|
|
|
case "LuckyGameCupTrigger":
|
|
|
|
|
isInCup = true;
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void OnTriggerExit2D(Collider2D other)
|
|
|
|
|
{
|
2025-09-28 08:27:12 +00:00
|
|
|
switch (other.tag)
|
2025-09-28 00:24:49 +00:00
|
|
|
{
|
2025-09-28 08:27:12 +00:00
|
|
|
case "LuckyGameCupTrigger":
|
|
|
|
|
isInCup = false;
|
|
|
|
|
transform.parent = tf_fallobjs;
|
|
|
|
|
break;
|
2025-09-12 20:45:21 +00:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 20:15:49 +00:00
|
|
|
void Set_Collision(int amount)
|
|
|
|
|
{
|
2025-09-19 20:24:20 +00:00
|
|
|
SoundInfo.Ins.Play_OneShot((eSound)Random.Range(16, 19));
|
2025-10-02 19:08:57 +00:00
|
|
|
LobbyUI.Ins.m_Game_Lucky.Add_Amount(m_Money, amount);
|
2025-09-12 20:15:49 +00:00
|
|
|
m_image.enabled = false;
|
2025-09-28 08:27:12 +00:00
|
|
|
m_Collider2D.enabled = false;
|
2025-09-12 20:15:49 +00:00
|
|
|
go_effect.SetActive(true);
|
|
|
|
|
isCollision = true;
|
|
|
|
|
}
|
2025-09-12 19:39:24 +00:00
|
|
|
}
|