You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
287 lines
8.8 KiB
287 lines
8.8 KiB
using Spine.Unity;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using DG.Tweening;
|
|
using UnityEngine;
|
|
using UnityEngine.UI;
|
|
using UnityEngine.Rendering;
|
|
using TMPro;
|
|
|
|
public class SleepModeMgr : MonoBehaviour
|
|
{
|
|
#region const
|
|
public static SleepModeMgr curMgr;
|
|
#endregion
|
|
|
|
#region UI
|
|
public Canvas canvasUI;
|
|
[SerializeField]
|
|
private TextMeshProUGUI txtMain;
|
|
private SkeletonAnimation skJelly;
|
|
private SkeletonAnimation skBackground;
|
|
private Canvas sortingCanvas;
|
|
private TextMeshProUGUI txtSleepMode;
|
|
private TextMeshProUGUI txtTime;
|
|
private TextMeshProUGUI txtCurStage;
|
|
private TextMeshProUGUI txtCurStageCount;
|
|
private TextMeshProUGUI txtSliderDesc;
|
|
private RectTransform handle;
|
|
private TextMeshProUGUI txtBattery;
|
|
private Slider sldWake;
|
|
private Image imgCover;
|
|
private Image imgBattery;
|
|
private Image imgSldHandle;
|
|
#endregion
|
|
|
|
#region Values
|
|
private bool bReLocalize = true;
|
|
private int itime = 0;
|
|
private bool isSleep;
|
|
private bool isTouch;
|
|
private int iloading = -1;
|
|
private Color colCover;
|
|
private string area;
|
|
private string stage;
|
|
public bool bAutoSleep;
|
|
#endregion
|
|
|
|
[SerializeField]
|
|
private Canvas[] openUis;
|
|
|
|
|
|
#region Base
|
|
public static void SLocalize(bool bmain)
|
|
{
|
|
if(curMgr != null)
|
|
curMgr.Localize(bmain);
|
|
}
|
|
|
|
public void Localize(bool bmain)
|
|
{
|
|
if (bmain)
|
|
{
|
|
txtMain.text = LocalizationText.GetText("sleep_title");
|
|
}
|
|
else
|
|
{
|
|
bReLocalize = false;
|
|
txtMain.text = LocalizationText.GetText("sleep_title");
|
|
sortingCanvas = canvasUI.transform.Find("SortingCanvas").GetComponent<Canvas>();
|
|
skJelly = canvasUI.transform.Find("SleepJelly").GetComponent<SkeletonAnimation>();
|
|
//skBackground = canvasUI.transform.Find("spineBackground").GetComponent<SkeletonAnimation>();
|
|
//txtSleepMode = sortingCanvas.transform.Find("txtSleepMode").GetComponent<TextMeshProUGUI>();
|
|
//txtSleepMode.text = LocalizationText.GetText("sleep_title");
|
|
txtTime = sortingCanvas.transform.Find("txtTime").GetComponent<TextMeshProUGUI>();
|
|
txtCurStageCount = sortingCanvas.transform.Find("txtCurStageCount").GetComponent<TextMeshProUGUI>();
|
|
txtCurStage = sortingCanvas.transform.Find("txtCurStage").GetComponent<TextMeshProUGUI>();
|
|
txtCurStage.text = FormatString.CombineAll(LocalizationText.GetText("all_now"), " ", LocalizationText.GetText("all_stage"));
|
|
txtSliderDesc = sortingCanvas.transform.Find("txtSlide").GetComponent<TextMeshProUGUI>();
|
|
txtSliderDesc.text = LocalizationText.GetText("sleep_slide");
|
|
sldWake = sortingCanvas.transform.Find("sldWaken").transform.GetChild(0).GetComponent<Slider>();
|
|
handle = sldWake.transform.Find("Handle Slide Area").transform.GetChild(0).GetComponent<RectTransform>();
|
|
imgCover = sortingCanvas.transform.Find("imgCover").GetComponent<Image>();
|
|
imgBattery = sortingCanvas.transform.Find("imgBattery").transform.GetChild(0).GetComponent<Image>();
|
|
txtBattery = sortingCanvas.transform.Find("txtBattery").GetComponent<TextMeshProUGUI>();
|
|
imgSldHandle = sldWake.transform.Find("Handle Slide Area").GetChild(0).GetComponent<Image>();
|
|
iloading = 0;
|
|
}
|
|
}
|
|
|
|
// 설정에서 언어 변경 시 처리.
|
|
public static void SReLocalize()
|
|
{
|
|
curMgr.Localize(true);
|
|
curMgr.bReLocalize = true;
|
|
}
|
|
|
|
// 백버튼 처리.
|
|
public static bool SCloseMenu()
|
|
{
|
|
return curMgr.CloseMenu();
|
|
}
|
|
|
|
private bool CloseMenu()
|
|
{
|
|
if (canvasUI.enabled)
|
|
{
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
#endregion
|
|
|
|
#region Static
|
|
public static void SOnSleep()
|
|
{
|
|
curMgr.OnSleep();
|
|
|
|
SoundMgr.Instance.PlaySfx(SoundName.BtnPress);
|
|
}
|
|
public static bool GetIsSleep()
|
|
{
|
|
return curMgr.isSleep;
|
|
}
|
|
#endregion
|
|
|
|
|
|
private void Awake()
|
|
{
|
|
curMgr = this;
|
|
itime = 0;
|
|
isSleep = false;
|
|
}
|
|
|
|
private void OnSleep()
|
|
{
|
|
if (bReLocalize)
|
|
Localize(false);
|
|
|
|
txtTime.text = FormatString.TextTimeSpace(itime);
|
|
area = LocalizationText.GetText(FormatString.CombineAll("stage_areaname", (DataHandler.PlayData.curStage / 100).ToString()));
|
|
stage = FormatString.CombineAll((DataHandler.PlayData.curStage / 100).ToString(), " - ", (DataHandler.PlayData.curStage % 100).ToString());
|
|
txtCurStageCount.text = stage; //
|
|
|
|
if (iloading < 0)
|
|
return;
|
|
|
|
iloading++;
|
|
isSleep = true;
|
|
setOptimization(true);
|
|
InvokeRepeating("setText", 1f,1f);
|
|
|
|
canvasUI.enabled = true;
|
|
//skBackground.gameObject.SetActive(true);
|
|
skJelly.gameObject.SetActive(true);
|
|
sortingCanvas.enabled = true;
|
|
sldWake.value = 0f;
|
|
skJelly.AnimationState.SetAnimation(0, "idle", true);
|
|
//imgSldHandle.raycastTarget = true;
|
|
//StartCoroutine(FadeCover());
|
|
}
|
|
|
|
private IEnumerator OffSleep()
|
|
{
|
|
CoverCamera.Hold();
|
|
skJelly.AnimationState.SetAnimation(0, "wakeup", false);
|
|
skJelly.timeScale = 1.5f;
|
|
yield return new WaitForSeconds(1.5f);
|
|
skJelly.timeScale = 1f;
|
|
CoverCamera.Release();
|
|
iloading--;
|
|
isSleep = false;
|
|
setOptimization(false);
|
|
CancelInvoke("setText");
|
|
//skBackground.gameObject.SetActive(false);
|
|
skJelly.gameObject.SetActive(false);
|
|
sortingCanvas.enabled = false;
|
|
canvasUI.enabled = false;
|
|
itime = 0;
|
|
}
|
|
|
|
private IEnumerator FadeCover()
|
|
{
|
|
colCover = Color.black;
|
|
colCover.a = 0f;
|
|
while (colCover.a <= 0.5f)
|
|
{
|
|
colCover.a += 0.015f;
|
|
imgCover.color = colCover;
|
|
yield return new WaitForSeconds(0.1f);
|
|
}
|
|
}
|
|
|
|
//private IEnumerator decreaseSldValue()
|
|
//{
|
|
// float fvalue = 0.4f;
|
|
// while (sldWake.value >= 0.01f && !isTouch && !isAwake)
|
|
// {
|
|
// colCover.a = 0.5f - (sldWake.value * 0.5f);
|
|
// imgCover.color = colCover;
|
|
// fvalue += 0.1f;
|
|
// sldWake.value -= fvalue;
|
|
// yield return new WaitForSeconds(0.05f);
|
|
// }
|
|
//}
|
|
|
|
public void setSlideValue()
|
|
{
|
|
//sldWake.value = fvalue;
|
|
//StopCoroutine(decreaseSldValue());
|
|
StopCoroutine(FadeCover());
|
|
colCover.a = 0.5f - (sldWake.value * 0.5f);
|
|
imgCover.color = colCover;
|
|
if (sldWake.value >= 0.95f && iloading > 0 && isSleep && isTouch)
|
|
{
|
|
isSleep = false;
|
|
StartCoroutine(OffSleep());
|
|
}
|
|
}
|
|
|
|
public void setOptimization(bool bvalue)
|
|
{
|
|
for(int i = 0; i<openUis.Length; i++)
|
|
{
|
|
if (openUis[i].enabled)
|
|
{
|
|
GameUIMgr.SSetMainUiOn(false);
|
|
}
|
|
else if(i >= openUis.Length)
|
|
GameUIMgr.SSetMainUiOn(true);
|
|
}
|
|
|
|
GameUIMgr.SSetPopupUiOn(!bvalue);
|
|
BattleMgr.Instance.SetCameraOn(!bvalue);
|
|
BattleMgr.SSetBattleUiOn(!bvalue);
|
|
BattleMgr.SSetClearFailUiOn(!bvalue);
|
|
BattleMgr.SSetOnDamageText(!bvalue);
|
|
SoundMgr.Instance.EfcOn = !bvalue;
|
|
SoundMgr.Instance.BgmOn = !bvalue;
|
|
SoundMgr.Instance.VoiceOn = !bvalue;
|
|
//SettingMgr.
|
|
}
|
|
|
|
public void setText()
|
|
{
|
|
txtTime.text = FormatString.TextTimeSpace(itime);
|
|
area = LocalizationText.GetText(FormatString.CombineAll("stage_areaname", (DataHandler.PlayData.curStage / 100).ToString()));
|
|
stage = FormatString.CombineAll((DataHandler.PlayData.curStage / 100).ToString(), " - ", (DataHandler.PlayData.curStage % 100).ToString());
|
|
txtCurStageCount.text = stage;
|
|
imgBattery.fillAmount = SystemInfo.batteryLevel;
|
|
txtBattery.text = FormatString.CombineAll((SystemInfo.batteryLevel * 100).ToString(),FormatString.C_Percent);
|
|
itime++;
|
|
}
|
|
|
|
public void OnPointerUp()
|
|
{
|
|
isTouch = false;
|
|
imgSldHandle.raycastTarget = true;
|
|
if (sldWake.value < 0.95f)
|
|
{
|
|
sldWake.value = 0f;
|
|
colCover.a = 0.5f - (sldWake.value * 0.5f);
|
|
imgCover.color = colCover;
|
|
}
|
|
//if(sldWake.value > 0.95f)
|
|
// sldWake.value = 0.95f;
|
|
//StopCoroutine(decreaseSldValue());
|
|
//StartCoroutine(decreaseSldValue());
|
|
}
|
|
|
|
public void OnPointerDown()
|
|
{
|
|
isTouch = true;
|
|
//imgSldHandle.raycastTarget = false;
|
|
sldWake.value = 0f;
|
|
colCover.a = 0.5f - (sldWake.value * 0.5f);
|
|
}
|
|
|
|
public static void SSetAutoSleep(bool bvalue)
|
|
{
|
|
curMgr.bAutoSleep = bvalue;
|
|
}
|
|
|
|
public static bool SGetAutoSleep()
|
|
{
|
|
return curMgr.bAutoSleep;
|
|
}
|
|
}
|