2025-09-12 19:39:24 +00:00
|
|
|
using GUPS.AntiCheat.Protected;
|
2025-09-12 20:15:49 +00:00
|
|
|
using System.Collections;
|
2025-09-12 12:48:21 +00:00
|
|
|
using System.Collections.Generic;
|
2025-09-12 19:39:24 +00:00
|
|
|
using TMPro;
|
2025-09-12 12:48:21 +00:00
|
|
|
using UnityEngine;
|
|
|
|
|
|
|
|
|
|
public class Game_Lucky : MonoBehaviour
|
|
|
|
|
{
|
2025-09-12 19:39:24 +00:00
|
|
|
public TextMeshProUGUI[] texts; // 0 시간, 1 획득 재화
|
2025-09-12 12:48:21 +00:00
|
|
|
public GameObject go_dropobj; // 떨어질 공 prefab
|
|
|
|
|
public Transform tf_cup; // 컵 (움직이고 회전하는 부분)
|
|
|
|
|
public Transform tf_cupin; // 컵 안 (공들이 들어가는 위치 부모)
|
|
|
|
|
|
|
|
|
|
List<GameObject> list_dropobj = new List<GameObject>();
|
2025-09-12 20:45:21 +00:00
|
|
|
public LuckyRandomBlock temp;
|
2025-09-12 12:48:21 +00:00
|
|
|
|
|
|
|
|
// 회전 관련 변수
|
|
|
|
|
private bool isRotating = false;
|
|
|
|
|
private float targetZ = 0f;
|
|
|
|
|
private float rotateSpeed = 150f; // 초당 몇 도 회전할지
|
|
|
|
|
|
|
|
|
|
bool bRotCup = false;
|
2025-09-12 19:39:24 +00:00
|
|
|
ProtectedFloat m_Time;
|
|
|
|
|
ProtectedInt32 _get; public int m_Amount { get { return _get; } set { _get = value; _get.Obfuscate(); } }
|
2025-09-12 20:15:49 +00:00
|
|
|
ProtectedInt32 _bb; public int m_BubbleAmount { get { return _bb; } set { _bb = value; _bb.Obfuscate(); } }
|
|
|
|
|
ProtectedInt32 TotalBubbleAmount = 50;
|
2025-09-12 12:48:21 +00:00
|
|
|
|
|
|
|
|
public void Set()
|
|
|
|
|
{
|
|
|
|
|
gameObject.SetActive(true);
|
|
|
|
|
|
|
|
|
|
bRotCup = false;
|
|
|
|
|
|
2025-09-12 19:39:24 +00:00
|
|
|
// tf_cup 초기화
|
|
|
|
|
tf_cup.localPosition = Vector3.zero;
|
2025-09-12 12:48:21 +00:00
|
|
|
tf_cup.rotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
|
|
|
|
|
|
// list_dropobj.Count 가 0 이면 50개 생성해서 tf_cupin 안에 넣기
|
|
|
|
|
if (list_dropobj.Count == 0)
|
|
|
|
|
{
|
2025-09-12 20:15:49 +00:00
|
|
|
TotalBubbleAmount.Obfuscate();
|
|
|
|
|
for (int i = 0; i < TotalBubbleAmount; i++)
|
2025-09-12 12:48:21 +00:00
|
|
|
{
|
|
|
|
|
GameObject obj = Instantiate(go_dropobj, tf_cupin);
|
|
|
|
|
obj.transform.localPosition = Get_CupInLocalPos();
|
|
|
|
|
list_dropobj.Add(obj);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 20:45:21 +00:00
|
|
|
temp.Set();
|
|
|
|
|
|
2025-09-12 12:48:21 +00:00
|
|
|
Set_Ball();
|
2025-09-12 19:39:24 +00:00
|
|
|
Init_game();
|
|
|
|
|
Set_Texts();
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Set_Ball()
|
|
|
|
|
{
|
2025-09-12 19:39:24 +00:00
|
|
|
list_dropobj.ForEach(f => f.GetComponent<LuckyGameObj>().Init(Get_CupInLocalPos())); // 컵 안에서 시작
|
2025-09-12 12:48:21 +00:00
|
|
|
//list_dropobj.ForEach(f => f.GetComponent<Rigidbody2D>().gravityScale = Random.Range(0.01f, 0.3f));
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 19:39:24 +00:00
|
|
|
void Init_game()
|
|
|
|
|
{
|
|
|
|
|
Time.timeScale = 1f;
|
|
|
|
|
m_Time = 30f; m_Time.Obfuscate();
|
|
|
|
|
m_Amount = 0;
|
2025-09-12 20:15:49 +00:00
|
|
|
m_BubbleAmount = 0;
|
2025-09-12 19:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void Set_Texts()
|
|
|
|
|
{
|
|
|
|
|
texts[0].text = m_Time.Value.ToString("N0");
|
|
|
|
|
texts[1].text = m_Amount.ToString();
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 20:15:49 +00:00
|
|
|
public void Add_Amount(int amout)
|
|
|
|
|
{
|
|
|
|
|
m_Amount += amout;
|
|
|
|
|
Set_Texts();
|
|
|
|
|
|
|
|
|
|
++m_BubbleAmount;
|
|
|
|
|
if (m_BubbleAmount >= TotalBubbleAmount)
|
|
|
|
|
GameOver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameOver()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(Co_GameOver());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator Co_GameOver()
|
|
|
|
|
{
|
|
|
|
|
list_dropobj.ForEach(f => f.GetComponent<LuckyGameObj>().StopObj());
|
|
|
|
|
yield return new WaitForSecondsRealtime(3f);
|
|
|
|
|
// TODO : 결과 보여주기 (결과 화면 나갈 때, Time.timeScale = 1f; 필수)
|
|
|
|
|
gameObject.SetActive(false); // 지금은 그냥 나가기
|
|
|
|
|
}
|
2025-09-12 19:39:24 +00:00
|
|
|
|
2025-09-12 12:48:21 +00:00
|
|
|
Vector3 Get_CupInLocalPos()
|
|
|
|
|
{
|
|
|
|
|
return new Vector3(Random.Range(-50f, 50f), 30f + Random.Range(-50f, 50f), 0f);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMyDrag()
|
|
|
|
|
{
|
|
|
|
|
if (!bRotCup)
|
|
|
|
|
{
|
|
|
|
|
// 마우스/터치 입력 위치 → 월드 좌표 변환
|
|
|
|
|
Vector3 mousePos = Input.mousePosition;
|
|
|
|
|
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
|
|
|
|
|
|
|
|
|
|
// tf_cup을 터치한 위치의 x 값만 받아서 거기에 위치시킴
|
|
|
|
|
Vector3 cupPos = tf_cup.position;
|
|
|
|
|
cupPos.x = worldPos.x;
|
|
|
|
|
tf_cup.position = cupPos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnClick_Screen()
|
|
|
|
|
{
|
|
|
|
|
if (bRotCup)
|
|
|
|
|
{
|
|
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bRotCup = true;
|
|
|
|
|
|
|
|
|
|
// 마우스/터치 입력 위치 → 월드 좌표 변환
|
|
|
|
|
Vector3 mousePos = Input.mousePosition;
|
|
|
|
|
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
|
|
|
|
|
|
|
|
|
|
// tf_cup을 터치한 위치의 x 값만 받아서 거기에 위치시킴
|
|
|
|
|
Vector3 cupPos = tf_cup.position;
|
|
|
|
|
cupPos.x = worldPos.x;
|
|
|
|
|
tf_cup.position = cupPos;
|
|
|
|
|
|
|
|
|
|
// 회전 시작 (목표: -150도)
|
|
|
|
|
targetZ = -150f;
|
|
|
|
|
isRotating = true;
|
2025-09-12 20:15:49 +00:00
|
|
|
|
|
|
|
|
list_dropobj.ForEach(f => f.GetComponent<LuckyGameObj>().Tilt_Cup());
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private void Update()
|
|
|
|
|
{
|
|
|
|
|
if (isRotating)
|
|
|
|
|
{
|
|
|
|
|
// 현재 z 회전값
|
|
|
|
|
float currentZ = tf_cup.eulerAngles.z;
|
|
|
|
|
if (currentZ > 180f) currentZ -= 360f; // -180~180 범위로 맞추기
|
|
|
|
|
|
|
|
|
|
// 목표 각도로 부드럽게 이동
|
|
|
|
|
float newZ = Mathf.MoveTowards(currentZ, targetZ, rotateSpeed * Time.deltaTime);
|
|
|
|
|
tf_cup.rotation = Quaternion.Euler(0, 0, newZ);
|
|
|
|
|
|
|
|
|
|
// 목표 각도 도달했으면 정지
|
|
|
|
|
if (Mathf.Approximately(newZ, targetZ))
|
|
|
|
|
{
|
|
|
|
|
isRotating = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-12 19:39:24 +00:00
|
|
|
|
|
|
|
|
if (m_Time > 0f)
|
|
|
|
|
{
|
|
|
|
|
m_Time -= Time.deltaTime;
|
|
|
|
|
Debug.Log(m_Time);
|
|
|
|
|
Set_Texts();
|
|
|
|
|
if (m_Time <= 0f)
|
2025-09-12 20:15:49 +00:00
|
|
|
GameOver();
|
2025-09-12 19:39:24 +00:00
|
|
|
}
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|
|
|
|
|
}
|