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;
|
2025-09-13 04:33:26 +00:00
|
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
|
|
|
using UnityEngine.UI;
|
2025-09-12 12:48:21 +00:00
|
|
|
|
|
|
|
|
public class Game_Lucky : MonoBehaviour
|
|
|
|
|
{
|
2025-09-27 23:40:31 +00:00
|
|
|
public LuckyGameCupCounter m_LuckyGameCupCounter;
|
2025-09-13 02:32:17 +00:00
|
|
|
public Game_Lucky_Result m_Game_Lucky_Result;
|
2025-09-28 03:00:09 +00:00
|
|
|
public Image i_girl, i_girlsd, i_refillbtn;
|
2025-09-13 04:40:43 +00:00
|
|
|
public GameObject[] gos_boobs;
|
2025-09-28 04:41:35 +00:00
|
|
|
public TextMeshProUGUI[] texts; // 0 시간, 1 획득 재화, 2 컵안 오브젝트 갯수, 3 리필 횟수, 4 리필 갯수
|
2025-09-12 12:48:21 +00:00
|
|
|
public GameObject go_dropobj; // 떨어질 공 prefab
|
|
|
|
|
public Transform tf_cup; // 컵 (움직이고 회전하는 부분)
|
|
|
|
|
public Transform tf_cupin; // 컵 안 (공들이 들어가는 위치 부모)
|
2025-09-28 00:24:49 +00:00
|
|
|
public Transform tf_fallobjs; // 컵 안에서 밖으로 떨어지는 공들의 부모
|
2025-09-28 04:41:35 +00:00
|
|
|
public Transform tf_refillobjs; // 리필 공들
|
2025-09-12 12:48:21 +00:00
|
|
|
|
|
|
|
|
List<GameObject> list_dropobj = new List<GameObject>();
|
2025-09-13 00:22:48 +00:00
|
|
|
public List<LuckyRandomBlock> list_randomblock;
|
2025-09-12 12:48:21 +00:00
|
|
|
|
|
|
|
|
// 회전 관련 변수
|
|
|
|
|
private bool isRotating = false;
|
2025-09-28 00:24:49 +00:00
|
|
|
private float targetZ = -150f;
|
|
|
|
|
private float originalZ = 0f;
|
2025-09-12 12:48:21 +00:00
|
|
|
private float rotateSpeed = 150f; // 초당 몇 도 회전할지
|
2025-09-18 06:55:43 +00:00
|
|
|
float Cup_minX, Cup_maxX;
|
|
|
|
|
[SerializeField] private float cupMargin = 128.5f; // 간격
|
2025-09-12 12:48:21 +00:00
|
|
|
|
2025-09-28 04:41:35 +00:00
|
|
|
bool bRotCup = false, updateTime = false, isRefill = 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(); } }
|
2025-09-28 03:00:09 +00:00
|
|
|
ProtectedInt32 TotalBubbleAmount = 50, m_RefillCount = 0;
|
2025-09-27 23:40:31 +00:00
|
|
|
int CupInAmount = 0; // 컵 안에 있는 오브젝트 갯수
|
2025-09-12 12:48:21 +00:00
|
|
|
|
2025-09-18 07:13:50 +00:00
|
|
|
AsyncOperationHandle m_Handle, m_HandleSD;
|
2025-09-26 00:14:43 +00:00
|
|
|
int curGirl;
|
2025-09-13 04:33:26 +00:00
|
|
|
|
2025-09-18 06:55:43 +00:00
|
|
|
private void Awake()
|
|
|
|
|
{
|
|
|
|
|
// 화면 좌표 (0,0) → 월드 좌표
|
|
|
|
|
Vector3 leftWorld = Camera.main.ScreenToWorldPoint(
|
|
|
|
|
new Vector3(0 + cupMargin, Screen.height / 2f, Camera.main.nearClipPlane));
|
|
|
|
|
|
|
|
|
|
// 화면 좌표 (Screen.width,0) → 월드 좌표
|
|
|
|
|
Vector3 rightWorld = Camera.main.ScreenToWorldPoint(
|
|
|
|
|
new Vector3(Screen.width - cupMargin, Screen.height / 2f, Camera.main.nearClipPlane));
|
|
|
|
|
|
|
|
|
|
Cup_minX = leftWorld.x;
|
|
|
|
|
Cup_maxX = rightWorld.x;
|
2025-09-28 04:41:35 +00:00
|
|
|
|
|
|
|
|
var refill = table_GlobalValue.Ins.Get_Int("LuckyGame_RefillAmount") << 1;
|
|
|
|
|
for (int i = 0; i < refill; i++)
|
|
|
|
|
{
|
|
|
|
|
var obj = DSUtil.Get_Clone(go_dropobj, tf_refillobjs);
|
|
|
|
|
obj.gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
texts[4].text = $"x{table_GlobalValue.Ins.Get_Int("LuckyGame_RefillAmount")}";
|
2025-09-18 06:55:43 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 12:48:21 +00:00
|
|
|
public void Set()
|
|
|
|
|
{
|
|
|
|
|
gameObject.SetActive(true);
|
2025-09-19 19:31:06 +00:00
|
|
|
SoundInfo.Ins.Play_BGM(eBGM.b007_LuckyGame);
|
2025-09-27 23:40:31 +00:00
|
|
|
m_LuckyGameCupCounter.Set(count => { texts[2].text = count.ToString(); });
|
2025-09-13 02:32:17 +00:00
|
|
|
m_Game_Lucky_Result.gameObject.SetActive(false);
|
2025-09-18 06:55:43 +00:00
|
|
|
ADInfo.Ins.Set_Banner(false);
|
2025-09-12 12:48:21 +00:00
|
|
|
|
2025-09-28 04:41:35 +00:00
|
|
|
isRefill = bRotCup = false;
|
2025-09-26 00:14:43 +00:00
|
|
|
curGirl = Random.Range(1, 9);
|
2025-09-12 12:48:21 +00:00
|
|
|
|
2025-09-13 04:33:26 +00:00
|
|
|
i_girl.enabled = false;
|
2025-09-26 00:14:43 +00:00
|
|
|
AddrResourceMgr.Ins.LoadObject<Sprite>($"Girl_LuckyGame/{curGirl}.png", handle =>
|
2025-09-13 04:33:26 +00:00
|
|
|
{
|
|
|
|
|
m_Handle = handle;
|
|
|
|
|
i_girl.enabled = true;
|
|
|
|
|
i_girl.sprite = handle.Result;
|
|
|
|
|
});
|
2025-09-18 07:13:50 +00:00
|
|
|
i_girlsd.enabled = false;
|
2025-09-26 00:14:43 +00:00
|
|
|
AddrResourceMgr.Ins.LoadObject<Sprite>($"Girl_Game/{curGirl}sd.png", handle =>
|
2025-09-18 07:13:50 +00:00
|
|
|
{
|
|
|
|
|
m_HandleSD = handle;
|
|
|
|
|
i_girlsd.enabled = true;
|
|
|
|
|
i_girlsd.sprite = handle.Result;
|
|
|
|
|
});
|
|
|
|
|
|
2025-09-28 03:00:09 +00:00
|
|
|
m_RefillCount = SaveMgr.Ins.Get_LuckyGameRefill();
|
|
|
|
|
m_RefillCount.Obfuscate();
|
|
|
|
|
|
2025-09-26 00:14:43 +00:00
|
|
|
DSUtil.InActivateGameObjects(gos_boobs, curGirl - 1);
|
2025-09-13 04:33:26 +00:00
|
|
|
|
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);
|
2025-09-28 00:24:49 +00:00
|
|
|
originalZ = tf_cup.eulerAngles.z;
|
2025-09-12 12:48:21 +00:00
|
|
|
|
|
|
|
|
// 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-28 04:41:35 +00:00
|
|
|
if (list_dropobj.Count > TotalBubbleAmount)
|
|
|
|
|
{
|
|
|
|
|
var moveCount = list_dropobj.Count - TotalBubbleAmount;
|
|
|
|
|
for (int i = 0; i < moveCount; i++)
|
|
|
|
|
{
|
|
|
|
|
list_dropobj[0].transform.SetParent(tf_refillobjs);
|
|
|
|
|
list_dropobj[0].gameObject.SetActive(false);
|
|
|
|
|
list_dropobj.RemoveAt(0);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-13 00:22:48 +00:00
|
|
|
StartCoroutine(Co_Block());
|
2025-09-12 20:45:21 +00:00
|
|
|
|
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-27 23:40:31 +00:00
|
|
|
CupInAmount = TotalBubbleAmount;
|
|
|
|
|
texts[2].text = CupInAmount.ToString();
|
2025-09-28 00:24:49 +00:00
|
|
|
list_dropobj.ForEach(f => f.GetComponent<LuckyGameObj>().Init(Get_CupInLocalPos(), tf_cupin, tf_fallobjs)); // 컵 안에서 시작
|
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()
|
|
|
|
|
{
|
2025-09-13 00:22:48 +00:00
|
|
|
updateTime = true;
|
2025-09-12 19:39:24 +00:00
|
|
|
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-28 03:00:09 +00:00
|
|
|
|
|
|
|
|
i_refillbtn.sprite = UIAtlasMgr.Ins.Get_Sprite(m_RefillCount > 0 ? "refill btn_lucky mini game" : "refill btn lock_lucky mini game");
|
|
|
|
|
texts[3].text = m_RefillCount.ToString();
|
2025-09-12 19:39:24 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-12 20:15:49 +00:00
|
|
|
public void Add_Amount(int amout)
|
|
|
|
|
{
|
|
|
|
|
m_Amount += amout;
|
|
|
|
|
Set_Texts();
|
|
|
|
|
|
|
|
|
|
++m_BubbleAmount;
|
2025-09-28 04:41:35 +00:00
|
|
|
if (m_BubbleAmount >= list_dropobj.Count)
|
2025-09-12 20:15:49 +00:00
|
|
|
GameOver();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void GameOver()
|
|
|
|
|
{
|
|
|
|
|
StartCoroutine(Co_GameOver());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
IEnumerator Co_GameOver()
|
|
|
|
|
{
|
2025-09-13 00:22:48 +00:00
|
|
|
updateTime = false;
|
2025-09-12 20:15:49 +00:00
|
|
|
list_dropobj.ForEach(f => f.GetComponent<LuckyGameObj>().StopObj());
|
2025-09-23 20:50:18 +00:00
|
|
|
yield return new WaitForSecondsRealtime(0.5f);
|
2025-09-13 02:32:17 +00:00
|
|
|
m_Game_Lucky_Result.Set(m_Amount);
|
2025-09-13 00:22:48 +00:00
|
|
|
StopAllCoroutines();
|
2025-09-12 20:15:49 +00:00
|
|
|
}
|
2025-09-12 19:39:24 +00:00
|
|
|
|
2025-09-13 04:33:26 +00:00
|
|
|
public void ReleaseImage()
|
|
|
|
|
{
|
|
|
|
|
AddrResourceMgr.Ins.Relese(m_Handle);
|
|
|
|
|
i_girl.sprite = null;
|
2025-09-18 07:13:50 +00:00
|
|
|
AddrResourceMgr.Ins.Relese(m_HandleSD);
|
|
|
|
|
i_girlsd.sprite = null;
|
|
|
|
|
|
2025-09-13 04:33:26 +00:00
|
|
|
gameObject.SetActive(false);
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-28 04:41:35 +00:00
|
|
|
Vector3 Get_CupInLocalPos(float addy = 0f)
|
2025-09-12 12:48:21 +00:00
|
|
|
{
|
2025-09-28 04:41:35 +00:00
|
|
|
return new Vector3(Random.Range(-50f, 50f), Random.Range(-50f, 50f) + addy, 0f);
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnMyDrag()
|
|
|
|
|
{
|
|
|
|
|
if (!bRotCup)
|
|
|
|
|
{
|
|
|
|
|
Vector3 mousePos = Input.mousePosition;
|
2025-09-18 06:55:43 +00:00
|
|
|
Vector3 worldPos = Camera.main.ScreenToWorldPoint(new Vector3(mousePos.x, mousePos.y, Camera.main.nearClipPlane));
|
2025-09-12 12:48:21 +00:00
|
|
|
|
2025-09-18 06:55:43 +00:00
|
|
|
// 컵의 x 위치를 화면 경계 안으로 Clamp
|
2025-09-12 12:48:21 +00:00
|
|
|
Vector3 cupPos = tf_cup.position;
|
2025-09-18 06:55:43 +00:00
|
|
|
cupPos.x = Mathf.Clamp(worldPos.x, Cup_minX, Cup_maxX);
|
2025-09-12 12:48:21 +00:00
|
|
|
tf_cup.position = cupPos;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public void OnClick_Screen()
|
|
|
|
|
{
|
|
|
|
|
if (bRotCup)
|
|
|
|
|
{
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
bRotCup = true;
|
|
|
|
|
|
|
|
|
|
// 마우스/터치 입력 위치 → 월드 좌표 변환
|
|
|
|
|
Vector3 mousePos = Input.mousePosition;
|
|
|
|
|
Vector3 worldPos = Camera.main.ScreenToWorldPoint(mousePos);
|
|
|
|
|
|
|
|
|
|
// tf_cup을 터치한 위치의 x 값만 받아서 거기에 위치시킴
|
|
|
|
|
Vector3 cupPos = tf_cup.position;
|
2025-09-23 20:50:18 +00:00
|
|
|
cupPos.x = Mathf.Clamp(worldPos.x, Cup_minX, Cup_maxX);
|
2025-09-12 12:48:21 +00:00
|
|
|
tf_cup.position = cupPos;
|
|
|
|
|
|
|
|
|
|
// 회전 시작 (목표: -150도)
|
|
|
|
|
targetZ = -150f;
|
|
|
|
|
isRotating = true;
|
2025-09-12 20:15:49 +00:00
|
|
|
|
2025-09-19 20:24:20 +00:00
|
|
|
SoundInfo.Ins.Play_OneShot((eSound)Random.Range(14, 16));
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|
|
|
|
|
|
2025-09-28 00:24:49 +00:00
|
|
|
public void OnPointerDown()
|
|
|
|
|
{
|
|
|
|
|
isRotating = true;
|
|
|
|
|
}
|
|
|
|
|
public void OnPointerUp()
|
|
|
|
|
{
|
|
|
|
|
isRotating = false;
|
|
|
|
|
}
|
|
|
|
|
|
2025-09-12 12:48:21 +00:00
|
|
|
private void Update()
|
|
|
|
|
{
|
2025-09-28 04:41:35 +00:00
|
|
|
if (isRefill) return;
|
|
|
|
|
|
2025-09-28 00:24:49 +00:00
|
|
|
float currentZ = tf_cup.eulerAngles.z;
|
|
|
|
|
if (currentZ > 180f) currentZ -= 360f; // -180~180 범위 보정
|
|
|
|
|
|
2025-09-12 12:48:21 +00:00
|
|
|
if (isRotating)
|
|
|
|
|
{
|
2025-09-28 00:24:49 +00:00
|
|
|
// 목표 각도로 이동
|
2025-09-12 12:48:21 +00:00
|
|
|
float newZ = Mathf.MoveTowards(currentZ, targetZ, rotateSpeed * Time.deltaTime);
|
|
|
|
|
tf_cup.rotation = Quaternion.Euler(0, 0, newZ);
|
2025-09-28 00:24:49 +00:00
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
// 손을 뗐을 때 원래 각도로 복귀
|
|
|
|
|
float newZ = Mathf.MoveTowards(currentZ, originalZ, rotateSpeed * Time.deltaTime);
|
|
|
|
|
tf_cup.rotation = Quaternion.Euler(0, 0, newZ);
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|
2025-09-12 19:39:24 +00:00
|
|
|
|
2025-09-13 00:22:48 +00:00
|
|
|
if (updateTime && m_Time > 0f)
|
2025-09-12 19:39:24 +00:00
|
|
|
{
|
|
|
|
|
m_Time -= Time.deltaTime;
|
|
|
|
|
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
|
|
|
}
|
2025-09-13 00:22:48 +00:00
|
|
|
|
|
|
|
|
IEnumerator Co_Block()
|
|
|
|
|
{
|
|
|
|
|
list_randomblock.ForEach(f => f.Init());
|
|
|
|
|
LuckyRandomBlock PreBlock = null;
|
|
|
|
|
|
|
|
|
|
while (true)
|
|
|
|
|
{
|
|
|
|
|
for (int i = 0; i < list_randomblock.Count; i++)
|
|
|
|
|
{
|
2025-09-28 03:00:09 +00:00
|
|
|
if (!list_randomblock[i].IsMoving() && (PreBlock == null || PreBlock.IsCrossTwoThirds()))
|
2025-09-13 00:22:48 +00:00
|
|
|
{
|
|
|
|
|
PreBlock = list_randomblock[i];
|
|
|
|
|
PreBlock.Move();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
yield return null;
|
|
|
|
|
}
|
|
|
|
|
}
|
2025-09-28 03:00:09 +00:00
|
|
|
|
|
|
|
|
public void OnClick_Refill()
|
|
|
|
|
{
|
|
|
|
|
if (m_RefillCount > 0)
|
|
|
|
|
{
|
|
|
|
|
--m_RefillCount;
|
|
|
|
|
m_RefillCount.Obfuscate();
|
|
|
|
|
Set_Texts();
|
2025-09-28 04:41:35 +00:00
|
|
|
StartCoroutine(Co_Refill());
|
2025-09-28 03:00:09 +00:00
|
|
|
}
|
|
|
|
|
}
|
2025-09-28 04:41:35 +00:00
|
|
|
|
|
|
|
|
IEnumerator Co_Refill()
|
|
|
|
|
{
|
|
|
|
|
isRefill = true;
|
|
|
|
|
tf_cup.rotation = Quaternion.Euler(0, 0, 0);
|
|
|
|
|
|
|
|
|
|
for (int i = 0; i < table_GlobalValue.Ins.Get_Int("LuckyGame_RefillAmount"); i++)
|
|
|
|
|
{
|
|
|
|
|
for (int j = 0; j < tf_refillobjs.childCount; j++)
|
|
|
|
|
{
|
|
|
|
|
var child = tf_refillobjs.GetChild(j);
|
|
|
|
|
if (!child.gameObject.activeInHierarchy)
|
|
|
|
|
{
|
|
|
|
|
list_dropobj.Add(child.gameObject);
|
|
|
|
|
child.GetComponent<LuckyGameObj>().Init(Get_CupInLocalPos(100f), tf_cupin, tf_fallobjs);
|
|
|
|
|
yield return new WaitForSeconds(0.5f);
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
isRefill = false;
|
|
|
|
|
}
|
2025-09-12 12:48:21 +00:00
|
|
|
}
|