367 lines
11 KiB
C#
367 lines
11 KiB
C#
using System;
|
|
using System.Collections;
|
|
using System.Collections.Generic;
|
|
using System.Diagnostics.Contracts;
|
|
using BansheeGz.BGDatabase;
|
|
using TMPro;
|
|
using UnityEngine;
|
|
using UnityEngine.AddressableAssets;
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|
using UnityEngine.UI;
|
|
|
|
public class HuntingScript : MonoBehaviour
|
|
{
|
|
[SerializeField] private Image AIImage;
|
|
[SerializeField] private GameObject ScriptPanel;
|
|
[SerializeField] private TextMeshProUGUI ScriptTMP;
|
|
[SerializeField] private TextMeshProUGUI CharacterNameTMP;
|
|
[SerializeField] private GameObject scriptEndPoint = null;
|
|
[SerializeField] private CanvasGroup cg;
|
|
[SerializeField] private GameObject Bottom_Panel;
|
|
|
|
[SerializeField] private GameObject NextScriptButton;
|
|
[SerializeField] private GameObject PrevScriptButton;
|
|
[SerializeField] private GameObject GameButton;
|
|
|
|
private DB_HuntingData huntingData;
|
|
private DB_Script scriptData;
|
|
private int scriptIndex = 0;
|
|
private int scriptArraySize = 0;
|
|
private IEnumerator typingCoroutine = null;
|
|
private IEnumerator checkFailLoadImageCoroutine = null;
|
|
private AsyncOperationHandle<Sprite> spriteHandle;
|
|
|
|
private BGId huntingID;
|
|
private BGId huntingListID;
|
|
private bool isFirstHuntingData = false;
|
|
|
|
WaitForSeconds typingSecond = new WaitForSeconds(0.008f);
|
|
|
|
private void Awake()
|
|
{
|
|
if (GameManager.Instance != null)
|
|
{
|
|
GameManager.Event.RegistEvent(EEventType.OnClickFullView, this.OnClickFullView);
|
|
GameManager.Event.RegistEvent(EEventType.OnReturnFullView, this.OnReturnFullView);
|
|
}
|
|
|
|
cg.alpha = 0f;
|
|
cg.interactable = false;
|
|
cg.blocksRaycasts = false;
|
|
}
|
|
|
|
private void OnDestroy()
|
|
{
|
|
if (GameManager.Instance != null)
|
|
{
|
|
GameManager.Event.RemoveEvent(EEventType.OnClickFullView, this.OnClickFullView);
|
|
GameManager.Event.RemoveEvent(EEventType.OnReturnFullView, this.OnReturnFullView);
|
|
}
|
|
|
|
if (spriteHandle.IsValid())
|
|
{
|
|
Addressables.Release(spriteHandle);
|
|
}
|
|
}
|
|
|
|
// 헌팅 스크립트를 켰을 때의 이벤트
|
|
private void OnClickFullView(object huntingDataID, object huntingListDataID)
|
|
{
|
|
InitHuntingScript((BGId)huntingDataID, (BGId)huntingListDataID);
|
|
}
|
|
|
|
private void InitHuntingScript(BGId huntingID, BGId huntingListID)
|
|
{
|
|
this.huntingID = huntingID;
|
|
this.huntingListID = huntingListID;
|
|
|
|
isFirstHuntingData = GameManager.BGDatabase.IsFirstHuntingData(huntingListID, huntingID);
|
|
if(isFirstHuntingData)
|
|
{
|
|
GameManager.Sound.PlayBGM(EBGMType.BGM_HUNT_1);
|
|
}
|
|
else
|
|
{
|
|
GameManager.Sound.PlayBGM(EBGMType.BGM_HUNT_2);
|
|
}
|
|
|
|
PrevScriptButton.gameObject.SetActive(false);
|
|
NextScriptButton.gameObject.SetActive(false);
|
|
GameButton.gameObject.SetActive(false);
|
|
|
|
if (checkFailLoadImageCoroutine != null)
|
|
{
|
|
StopCoroutine(checkFailLoadImageCoroutine);
|
|
checkFailLoadImageCoroutine = null;
|
|
}
|
|
|
|
checkFailLoadImageCoroutine = CheckFailLoadImage();
|
|
StartCoroutine(CheckFailLoadImage());
|
|
|
|
huntingData = DB_HuntingData.GetEntity(huntingID);
|
|
if (huntingData != null)
|
|
{
|
|
spriteHandle = Addressables.LoadAssetAsync<Sprite>(huntingData.GetDBF_HuntingImageAddressablesAddress());
|
|
if (!spriteHandle.IsDone)
|
|
{
|
|
spriteHandle.Completed += handle =>
|
|
{
|
|
if (checkFailLoadImageCoroutine != null)
|
|
{
|
|
StopCoroutine(checkFailLoadImageCoroutine);
|
|
checkFailLoadImageCoroutine = null;
|
|
}
|
|
|
|
GameManager.UI.DeactivateLoadingPage();
|
|
|
|
if (handle.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
AIImage.sprite = handle.Result;
|
|
ActivateHuntingScript();
|
|
}
|
|
else
|
|
{
|
|
//Logging.LogWarning("huntingImage sprite is not Load");
|
|
}
|
|
};
|
|
}
|
|
else
|
|
{
|
|
if (checkFailLoadImageCoroutine != null)
|
|
{
|
|
StopCoroutine(checkFailLoadImageCoroutine);
|
|
checkFailLoadImageCoroutine = null;
|
|
}
|
|
|
|
GameManager.UI.DeactivateLoadingPage();
|
|
|
|
if (spriteHandle.Status == AsyncOperationStatus.Succeeded)
|
|
{
|
|
AIImage.sprite = spriteHandle.Result;
|
|
ActivateHuntingScript();
|
|
}
|
|
else
|
|
{
|
|
//Logging.LogWarning("huntingImage sprite is not Load");
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
private void OnReturnFullView()
|
|
{
|
|
cg.alpha = 0f;
|
|
cg.interactable = false;
|
|
cg.blocksRaycasts = false;
|
|
|
|
Bottom_Panel.SetActive(true);
|
|
|
|
if (spriteHandle.IsValid())
|
|
{
|
|
Addressables.Release(spriteHandle);
|
|
}
|
|
}
|
|
|
|
private void ActivateHuntingScript()
|
|
{
|
|
cg.alpha = 1f;
|
|
cg.interactable = true;
|
|
cg.blocksRaycasts = true;
|
|
|
|
Bottom_Panel.SetActive(false);
|
|
|
|
// 대사 시작하기
|
|
scriptIndex = 0;
|
|
scriptArraySize = huntingData.DBF_Script.Count;
|
|
|
|
ScriptPanel.gameObject.SetActive(true);
|
|
PlayTypingScript();
|
|
}
|
|
|
|
// 버튼 클릭
|
|
public void ClickReturnFullView()
|
|
{
|
|
GameManager.Sound.PlayBGM(EBGMType.BGM_1);
|
|
GameManager.Event.InvokeEvent(EEventType.OnReturnFullView);
|
|
}
|
|
|
|
public void ClickPlaySciprt()
|
|
{
|
|
if (typingCoroutine != null)
|
|
{
|
|
StopCoroutine(typingCoroutine);
|
|
typingCoroutine = null;
|
|
|
|
PlayScript();
|
|
}
|
|
else
|
|
{
|
|
if (scriptArraySize > scriptIndex + 1)
|
|
{
|
|
scriptIndex++;
|
|
PlayTypingScript();
|
|
}
|
|
else
|
|
{
|
|
// 다음 에피소드 버튼 나오게 하기
|
|
ScriptPanel.gameObject.SetActive(false);
|
|
|
|
if (GameManager.BGDatabase.GetHuntingDataIndex(huntingID) < DB_HuntingData.CountEntities - 1)
|
|
{
|
|
if (GameManager.BGDatabase.GetLastUnolockHuntingDataID() == huntingID)
|
|
{
|
|
GameButton.gameObject.SetActive(true);
|
|
NextScriptButton.gameObject.SetActive(false);
|
|
PrevScriptButton.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
NextScriptButton.gameObject.SetActive(true);
|
|
|
|
PrevScriptButton.gameObject.SetActive(false);
|
|
GameButton.gameObject.SetActive(false);
|
|
}
|
|
}
|
|
/*else
|
|
{
|
|
if (PrevScriptButton != null)
|
|
{
|
|
PrevScriptButton.gameObject.SetActive(true);
|
|
|
|
NextScriptButton.gameObject.SetActive(false);
|
|
GameButton.gameObject.SetActive(false);
|
|
}
|
|
}*/
|
|
}
|
|
}
|
|
}
|
|
|
|
public void ClickReturnScript()
|
|
{
|
|
if (typingCoroutine != null)
|
|
{
|
|
StopCoroutine(typingCoroutine);
|
|
typingCoroutine = null;
|
|
}
|
|
|
|
ScriptPanel.gameObject.SetActive(true);
|
|
|
|
scriptIndex = 0;
|
|
ScriptTMP.text = String.Empty;
|
|
CharacterNameTMP.text = String.Empty;
|
|
|
|
PlayTypingScript();
|
|
}
|
|
|
|
public void ClickNextScript()
|
|
{
|
|
NextScriptButton.gameObject.SetActive(false);
|
|
if(isFirstHuntingData == true)
|
|
{
|
|
InitHuntingScript(GameManager.BGDatabase.GetSecondHuntingData(huntingListID), huntingListID);
|
|
}
|
|
else
|
|
{
|
|
BGId nextDataID = GameManager.BGDatabase.GetNextHuntingListData(huntingListID);
|
|
InitHuntingScript(GameManager.BGDatabase.GetFirstHuntingData(nextDataID), nextDataID);
|
|
}
|
|
}
|
|
|
|
public void ClickPrevScript()
|
|
{
|
|
PrevScriptButton.gameObject.SetActive(false);
|
|
InitHuntingScript(GameManager.BGDatabase.GetFirstHuntingData(huntingListID), huntingListID);
|
|
}
|
|
|
|
public void ClickPlayGame()
|
|
{
|
|
GameButton.gameObject.SetActive(false);
|
|
GameManager.Event.InvokeEvent(EEventType.OnReturnFullView);
|
|
|
|
GameManager.Sound.PlaySFX(ESFXType.Button_Hit);
|
|
|
|
if (GameManager.DB.IsAllUnlocked(true) == false)
|
|
{
|
|
if (GameManager.DB.Heart > 0)
|
|
{
|
|
if (GameManager.DB.Gold > 0)
|
|
{
|
|
GameManager.DB.SubHeart(1, this.name);
|
|
GameManager.Event.InvokeEvent(EEventType.OnChallengeStart);
|
|
}
|
|
else
|
|
{
|
|
GameManager.UI.ShowNStackPopup(EPopupType.GoldChargePopup);
|
|
}
|
|
}
|
|
else
|
|
GameManager.UI.ShowNStackPopup(EPopupType.HeartChargePopup);
|
|
}
|
|
}
|
|
|
|
private void PlayTypingScript()
|
|
{
|
|
scriptData = huntingData.DBF_Script[scriptIndex] as DB_Script;
|
|
if (scriptData != null)
|
|
{
|
|
scriptEndPoint.gameObject.SetActive(false);
|
|
|
|
if (scriptData.DBF_CharacterName == null)
|
|
{
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(true);
|
|
CharacterNameTMP.text = scriptData.DBF_CharacterName;
|
|
}
|
|
|
|
typingCoroutine = Typing(scriptData.DBF_HuntingScript);
|
|
StartCoroutine(typingCoroutine);
|
|
}
|
|
}
|
|
|
|
private void PlayScript()
|
|
{
|
|
scriptData = huntingData.DBF_Script[scriptIndex];
|
|
if (scriptData != null)
|
|
{
|
|
scriptEndPoint.gameObject.SetActive(true);
|
|
|
|
if (scriptData.DBF_CharacterName == null)
|
|
{
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(false);
|
|
}
|
|
else
|
|
{
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(true);
|
|
CharacterNameTMP.text = scriptData.DBF_CharacterName;
|
|
}
|
|
|
|
ScriptTMP.text = String.Empty;
|
|
ScriptTMP.text = scriptData.DBF_HuntingScript;
|
|
}
|
|
}
|
|
|
|
IEnumerator Typing(string script)
|
|
{
|
|
ScriptTMP.text = String.Empty;
|
|
|
|
for (int i = 0; i < script.Length; i++)
|
|
{
|
|
ScriptTMP.text += script[i];
|
|
yield return typingSecond;
|
|
}
|
|
|
|
scriptEndPoint.gameObject.SetActive(true);
|
|
typingCoroutine = null;
|
|
}
|
|
|
|
private IEnumerator CheckFailLoadImage()
|
|
{
|
|
GameManager.UI.ActivateLoadingPage();
|
|
yield return new WaitForSeconds(3.0f);
|
|
GameManager.UI.DeactivateLoadingPage();
|
|
}
|
|
}
|