320 lines
9.3 KiB
C#
320 lines
9.3 KiB
C#
|
|
using System;
|
|||
|
|
using System.Collections;
|
|||
|
|
using System.Collections.Generic;
|
|||
|
|
using System.Diagnostics.Contracts;
|
|||
|
|
using BansheeGz.BGDatabase;
|
|||
|
|
using TMPro;
|
|||
|
|
//using Unity.Android.Gradle;
|
|||
|
|
using UnityEngine;
|
|||
|
|
using UnityEngine.AddressableAssets;
|
|||
|
|
using UnityEngine.ResourceManagement.AsyncOperations;
|
|||
|
|
using UnityEngine.UI;
|
|||
|
|
|
|||
|
|
public class EventScript : 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;
|
|||
|
|
|
|||
|
|
private DB_EventData eventData;
|
|||
|
|
private DB_EventScript eventScriptData;
|
|||
|
|
private int scriptIndex = 0;
|
|||
|
|
private int scriptArraySize = 0;
|
|||
|
|
private IEnumerator typingCoroutine = null;
|
|||
|
|
private IEnumerator checkFailLoadImageCoroutine = null;
|
|||
|
|
|
|||
|
|
private AsyncOperationHandle<Sprite> spriteHandle;
|
|||
|
|
private AsyncOperationHandle<Sprite> beforeSpriteHandle;
|
|||
|
|
private string currentSpriteLoadAdress;
|
|||
|
|
|
|||
|
|
private BGId eventID;
|
|||
|
|
private bool isFirstHuntingData = false;
|
|||
|
|
|
|||
|
|
private string BGMtypeName;
|
|||
|
|
|
|||
|
|
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);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void InitEventScript(BGId eventID)
|
|||
|
|
{
|
|||
|
|
this.eventID = eventID;
|
|||
|
|
|
|||
|
|
if (spriteHandle.IsValid() == true)
|
|||
|
|
{
|
|||
|
|
Addressables.Release(spriteHandle);
|
|||
|
|
}
|
|||
|
|
if (beforeSpriteHandle.IsValid() == true)
|
|||
|
|
{
|
|||
|
|
Addressables.Release(beforeSpriteHandle);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (checkFailLoadImageCoroutine != null)
|
|||
|
|
{
|
|||
|
|
StopCoroutine(checkFailLoadImageCoroutine);
|
|||
|
|
checkFailLoadImageCoroutine = null;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
checkFailLoadImageCoroutine = CheckFailLoadImage();
|
|||
|
|
StartCoroutine(CheckFailLoadImage());
|
|||
|
|
|
|||
|
|
eventData = DB_EventData.GetEntity(eventID);
|
|||
|
|
if (eventData != null)
|
|||
|
|
{
|
|||
|
|
spriteHandle = Addressables.LoadAssetAsync<Sprite>(eventData.DBF_EventScript[0].GetDBF_ImageAddressablesAddress());
|
|||
|
|
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;
|
|||
|
|
ActivateEventScript();
|
|||
|
|
}
|
|||
|
|
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;
|
|||
|
|
ActivateEventScript();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//Logging.LogWarning("huntingImage sprite is not Load");
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void OnReturnFullView()
|
|||
|
|
{
|
|||
|
|
GameManager.Sound.PlayBGM(EBGMType.BGM_1);
|
|||
|
|
|
|||
|
|
cg.alpha = 0f;
|
|||
|
|
cg.interactable = false;
|
|||
|
|
cg.blocksRaycasts = false;
|
|||
|
|
|
|||
|
|
if (spriteHandle.IsValid() == true)
|
|||
|
|
{
|
|||
|
|
Addressables.Release(spriteHandle);
|
|||
|
|
}
|
|||
|
|
if (beforeSpriteHandle.IsValid() == true)
|
|||
|
|
{
|
|||
|
|
Addressables.Release(beforeSpriteHandle);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
GameObject.Destroy(gameObject);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void ActivateEventScript()
|
|||
|
|
{
|
|||
|
|
cg.alpha = 1f;
|
|||
|
|
cg.interactable = true;
|
|||
|
|
cg.blocksRaycasts = true;
|
|||
|
|
|
|||
|
|
// <20><><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD>ϱ<EFBFBD>
|
|||
|
|
scriptIndex = 0;
|
|||
|
|
scriptArraySize = eventData.DBF_EventScript.Count;
|
|||
|
|
|
|||
|
|
ScriptPanel.gameObject.SetActive(true);
|
|||
|
|
PlayTypingScript();
|
|||
|
|
|
|||
|
|
string bgmName = eventData.DBF_EventScript[scriptIndex].DBF_BGM;
|
|||
|
|
if (bgmName != null && bgmName != BGMtypeName)
|
|||
|
|
{
|
|||
|
|
BGMtypeName = bgmName;
|
|||
|
|
GameManager.Sound.PlayBGM((EBGMType)Enum.Parse(typeof(EBGMType), BGMtypeName));
|
|||
|
|
}
|
|||
|
|
BGMtypeName = eventData.DBF_EventScript[scriptIndex].DBF_BGM;
|
|||
|
|
GameManager.Sound.PlayBGM((EBGMType)Enum.Parse(typeof(EBGMType), BGMtypeName));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
// <20><>ư Ŭ<><C5AC>
|
|||
|
|
public void ClickReturnFullView()
|
|||
|
|
{
|
|||
|
|
OnReturnFullView();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
public void ClickPlaySciprt()
|
|||
|
|
{
|
|||
|
|
if (typingCoroutine != null)
|
|||
|
|
{
|
|||
|
|
StopCoroutine(typingCoroutine);
|
|||
|
|
typingCoroutine = null;
|
|||
|
|
|
|||
|
|
PlayScript();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
if (scriptArraySize > scriptIndex + 1)
|
|||
|
|
{
|
|||
|
|
scriptIndex++;
|
|||
|
|
|
|||
|
|
SetEventImage();
|
|||
|
|
|
|||
|
|
string bgmName = eventData.DBF_EventScript[scriptIndex].DBF_BGM;
|
|||
|
|
if (bgmName != null && bgmName != BGMtypeName)
|
|||
|
|
{
|
|||
|
|
BGMtypeName = bgmName;
|
|||
|
|
GameManager.Sound.PlayBGM((EBGMType)Enum.Parse(typeof(EBGMType), BGMtypeName));
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
PlayTypingScript();
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
//GameManager.Event.InvokeEvent(EEventType.OnReturnFullView);
|
|||
|
|
OnReturnFullView();
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void PlayTypingScript()
|
|||
|
|
{
|
|||
|
|
eventScriptData = eventData.DBF_EventScript[scriptIndex] as DB_EventScript;
|
|||
|
|
if (eventScriptData != null)
|
|||
|
|
{
|
|||
|
|
scriptEndPoint.gameObject.SetActive(false);
|
|||
|
|
|
|||
|
|
if (eventScriptData.DBF_CharacterName == null)
|
|||
|
|
{
|
|||
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(true);
|
|||
|
|
CharacterNameTMP.text = eventScriptData.DBF_CharacterName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
typingCoroutine = Typing(eventScriptData.DBF_EventScript);
|
|||
|
|
StartCoroutine(typingCoroutine);
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void PlayScript()
|
|||
|
|
{
|
|||
|
|
eventScriptData = eventData.DBF_EventScript[scriptIndex] as DB_EventScript;
|
|||
|
|
if (eventScriptData != null)
|
|||
|
|
{
|
|||
|
|
scriptEndPoint.gameObject.SetActive(true);
|
|||
|
|
|
|||
|
|
if (eventScriptData.DBF_CharacterName == null)
|
|||
|
|
{
|
|||
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(false);
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
CharacterNameTMP.transform.parent.gameObject.SetActive(true);
|
|||
|
|
CharacterNameTMP.text = eventScriptData.DBF_CharacterName;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
ScriptTMP.text = String.Empty;
|
|||
|
|
ScriptTMP.text = eventScriptData.DBF_EventScript;
|
|||
|
|
}
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
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();
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
private void SetEventImage()
|
|||
|
|
{
|
|||
|
|
currentSpriteLoadAdress = eventData.DBF_EventScript[scriptIndex].GetDBF_ImageAddressablesAddress();
|
|||
|
|
if (currentSpriteLoadAdress == null)
|
|||
|
|
{
|
|||
|
|
return;
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
if (beforeSpriteHandle.IsValid() == true)
|
|||
|
|
{
|
|||
|
|
Addressables.Release(beforeSpriteHandle);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
beforeSpriteHandle = spriteHandle;
|
|||
|
|
|
|||
|
|
spriteHandle = Addressables.LoadAssetAsync<Sprite>(currentSpriteLoadAdress);
|
|||
|
|
spriteHandle.Completed += handle =>
|
|||
|
|
{
|
|||
|
|
if (handle.Status == AsyncOperationStatus.Succeeded)
|
|||
|
|
{
|
|||
|
|
if (beforeSpriteHandle.IsValid() == true)
|
|||
|
|
{
|
|||
|
|
Addressables.Release(beforeSpriteHandle);
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
AIImage.sprite = handle.Result;
|
|||
|
|
}
|
|||
|
|
else
|
|||
|
|
{
|
|||
|
|
Debug.LogWarning("huntingImage sprite is not Load");
|
|||
|
|
}
|
|||
|
|
};
|
|||
|
|
}
|
|||
|
|
}
|