using GUPS.AntiCheat.Protected; using System.Collections; using System.Collections.Generic; using UnityEngine; using UnityEngine.ResourceManagement.AsyncOperations; using UnityEngine.UI; public class Game_Mini : MonoBehaviour { public Image i_girl, i_girlsd; public MiniGameItemCard[] items; public Slider slider_hp; public Transform tf_obtacleParent; public GameObject go_Obtacle; public GameObject[] gos_hiteffect; public RectTransform tf_pc; public Joystick m_Joystick; // 1 평소, 2 맞았을 때 AsyncOperationHandle m_Handle1, m_Handle2, m_HandleSD; ProtectedInt32 m_HP; bool bStartGame; float PcPosLimit; Dictionary dic_weight = new Dictionary(); List list_MiniGameObtacle = new List(); private void Awake() { PcPosLimit = (Screen.width >> 1) - 70f; } public void Set() { if (dic_weight.Count == 0) { dic_weight.Add(eMiniGameObtacleType.White, table_GlobalValue.Ins.Get_Int("MiniGameWeight_White")); dic_weight.Add(eMiniGameObtacleType.Red, table_GlobalValue.Ins.Get_Int("MiniGameWeight_Red")); dic_weight.Add(eMiniGameObtacleType.AlbumOpen, table_GlobalValue.Ins.Get_Int("MiniGameWeight_AlbumOpen")); dic_weight.Add(eMiniGameObtacleType.ChatCoin, table_GlobalValue.Ins.Get_Int("MiniGameWeight_ChatCoin")); dic_weight.Add(eMiniGameObtacleType.GachaCoin, table_GlobalValue.Ins.Get_Int("MiniGameWeight_GachaCoin")); dic_weight.Add(eMiniGameObtacleType.HpHeal, table_GlobalValue.Ins.Get_Int("MiniGameWeight_HpHeal")); } gameObject.SetActive(true); tf_pc.anchoredPosition = new Vector2(0f, 325f); DSUtil.InActivateGameObjects(gos_hiteffect); for (int i = 0; i < items.Length; i++) items[i].Set(); i_girl.enabled = false; AddrResourceMgr.Ins.LoadObject($"Girl_Game/{SaveMgr.Ins.Get_SelectGirlID()}-1.png", handle => { m_Handle1 = handle; i_girl.enabled = true; i_girl.sprite = handle.Result; }); AddrResourceMgr.Ins.LoadObject($"Girl_Game/{SaveMgr.Ins.Get_SelectGirlID()}-2.png", handle => { m_Handle2 = handle; }); i_girlsd.enabled = false; AddrResourceMgr.Ins.LoadObject($"Girl_Game/{SaveMgr.Ins.Get_SelectGirlID()}sd.png", handle => { m_HandleSD = handle; i_girlsd.enabled = true; i_girlsd.sprite = handle.Result; }); slider_hp.value = 1f; m_HP = table_GlobalValue.Ins.Get_Int("MiniGameHP"); m_HP.Obfuscate(); StartCoroutine(Co_Update()); } IEnumerator Co_Update() { bStartGame = false; yield return new WaitForSeconds(3f); bStartGame = true; float gap = 0.5f; list_MiniGameObtacle.ForEach(f => f.gameObject.SetActive(false)); while (true) { if (m_HP <= 0) break; var obtacle = list_MiniGameObtacle.Find(f => !f.gameObject.activeInHierarchy); if (obtacle == null) { obtacle = DSUtil.Get_Clone(go_Obtacle, tf_obtacleParent); list_MiniGameObtacle.Add(obtacle); } obtacle.Set(dic_weight); yield return new WaitForSeconds(gap); gap -= Time.deltaTime; if (gap < 0.1f) gap = 0.1f; } } private void Update() { if (bStartGame) { if (m_HP <= 0) return; var PcSpeed = table_GlobalValue.Ins.Get_Float("MiniGamePCSpeed"); if (m_Joystick.Direction.x < 0f) { tf_pc.anchoredPosition = new Vector2(tf_pc.anchoredPosition.x - Time.deltaTime * PcSpeed, tf_pc.anchoredPosition.y); if (tf_pc.anchoredPosition.x < -PcPosLimit) tf_pc.anchoredPosition = new Vector2(-PcPosLimit, tf_pc.anchoredPosition.y); } else if (m_Joystick.Direction.x > 0f) { tf_pc.anchoredPosition = new Vector2(tf_pc.anchoredPosition.x + Time.deltaTime * PcSpeed, tf_pc.anchoredPosition.y); if (tf_pc.anchoredPosition.x > PcPosLimit) tf_pc.anchoredPosition = new Vector2(PcPosLimit, tf_pc.anchoredPosition.y); } } } Coroutine cohit; public void Hit() { if (cohit != null) StopCoroutine(cohit); cohit = StartCoroutine(Co_Hit()); } IEnumerator Co_Hit() { --m_HP; m_HP.Obfuscate(); slider_hp.value = m_HP / table_GlobalValue.Ins.Get_Float("MiniGameHP"); if (m_HP <= 0) GameOver(); i_girl.sprite = m_Handle2.Result; yield return new WaitForSeconds(0.5f); i_girl.sprite = m_Handle1.Result; } void GameOver() { } public void Show_HitEffect(Vector3 pos) { for (int i = 0; i < gos_hiteffect.Length; i++) { if (!gos_hiteffect[i].activeInHierarchy) { StartCoroutine(Co_HitEffect(gos_hiteffect[i], pos)); break; } } } IEnumerator Co_HitEffect(GameObject effect, Vector3 pos) { effect.SetActive(true); effect.GetComponent().position = pos; yield return new WaitForSeconds(1.5f); effect.SetActive(false); } }