4 개의 씬, 메뉴 씬, 로딩 씬, 2 개의 게임 씬으로 구성된 게임이 있습니다. 메뉴 씬에서 게임 씬으로 전환 할 때 모두 문제가 없지만 게임 씬에서 메뉴 씬으로 다시 전환하거나 게임 씬을 다시로드 할 때마다 로딩 씬이 응답을 멈 춥니 다. 현재 활성화 된 게임 씬을 다시로드하려고 할 때만 "NetworkManager가 편집기에서 스크립트 다시로드를 감지했습니다. 이로 인해 네트워크가 종료되었습니다" 라는 경고 메시지가 표시 됩니다. 이 문제는 빌드에서 플레이 할 때도 나타납니다! 인쇄 문을 사용하여 코드 실행이 중지 된 위치를 추적하고 게임이 멈추는 원인이 Yield Return New WaitForSeconds ()임을 알아 냈습니다. 왜 그런 겁니까?
전환을 제어하는 두 개의 스크립트가 있습니다. UIButtons에서 호출되는 하나의 간단한 스크립트는 사전로드 장면에서 호출되는 두 번째 더 복잡한 스크립트에로드하여 애니메이션을 생성해야하는 장면을로드하도록 지시합니다. 올바른 씬에로드되고 모든 씬이 내 빌드 설정에 추가되었는지 확인했습니다.
다음 그림은 로딩 장면이 응답하지 않는 것을 보여줍니다. 첫 번째 그림은 현재 게임 씬을 다시로드하려고 할 때 어떤 일이 발생하는지 보여주고 두 번째 그림은 메뉴 씬을로드하려고 할 때 어떤 일이 발생하는지 보여줍니다.
내 로딩 장면 스크립트 :
public class LoadingScreenManager : MonoBehaviour {
[Header("Loading Visuals")]
public Image loadingIcon;
public Image loadingDoneIcon;
public Text loadingText;
public Image progressBar;
public Image fadeOverlay;
[Header("Timing Settings")]
public float waitOnLoadEnd = 0.25f;
public float fadeDuration = 0.25f;
[Header("Loading Settings")]
public LoadSceneMode loadSceneMode = LoadSceneMode.Single;
public ThreadPriority loadThreadPriority;
[Header("Other")]
// If loading additive, link to the cameras audio listener, to avoid multiple active audio listeners
public AudioListener audioListener;
AsyncOperation operation;
Scene currentScene;
public static int sceneToLoad = -1;
// IMPORTANT! This is the build index of your loading scene. You need to change this to match your actual scene index
static int loadingSceneIndex = 1;
public static void LoadScene(int levelNum) {
Application.backgroundLoadingPriority = ThreadPriority.High;
sceneToLoad = levelNum;
SceneManager.LoadScene(loadingSceneIndex);
}
void Start() {
if (sceneToLoad < 0)
return;
fadeOverlay.gameObject.SetActive(true); // Making sure it's on so that we can crossfade Alpha
currentScene = SceneManager.GetActiveScene();
StartCoroutine(LoadAsync(sceneToLoad));
}
private IEnumerator LoadAsync(int levelNum) {
ShowLoadingVisuals();
yield return null;
FadeIn();
StartOperation(levelNum);
float lastProgress = 0f;
// operation does not auto-activate scene, so it's stuck at 0.9
while (DoneLoading() == false) {
yield return null;
if (Mathf.Approximately(operation.progress, lastProgress) == false) {
progressBar.fillAmount = operation.progress;
lastProgress = operation.progress;
}
}
if (loadSceneMode == LoadSceneMode.Additive)
audioListener.enabled = false;
ShowCompletionVisuals();
//THE PRINT STATEMENT WORKS FINE RIGHT HERE! The value of waitOnLoadEnd is only 1
yield return new WaitForSeconds(waitOnLoadEnd);
//THE PRINT STATEMENT STOPS RUNNING RIGHT HERE!
FadeOut();
yield return new WaitForSeconds(fadeDuration);
if (loadSceneMode == LoadSceneMode.Additive)
SceneManager.UnloadScene(currentScene.name);
else
operation.allowSceneActivation = true;
}
private void StartOperation(int levelNum) {
Application.backgroundLoadingPriority = loadThreadPriority;
operation = SceneManager.LoadSceneAsync(levelNum, loadSceneMode);
if (loadSceneMode == LoadSceneMode.Single)
operation.allowSceneActivation = false;
}
private bool DoneLoading() {
return (loadSceneMode == LoadSceneMode.Additive && operation.isDone) || (loadSceneMode == LoadSceneMode.Single && operation.progress >= 0.9f);
}
void FadeIn() {
fadeOverlay.CrossFadeAlpha(0, fadeDuration, true);
}
void FadeOut() {
fadeOverlay.CrossFadeAlpha(1, fadeDuration, true);
}
void ShowLoadingVisuals() {
loadingIcon.gameObject.SetActive(true);
loadingDoneIcon.gameObject.SetActive(false);
progressBar.fillAmount = 0f;
loadingText.text = "LOADING...";
}
void ShowCompletionVisuals() {
loadingIcon.gameObject.SetActive(false);
loadingDoneIcon.gameObject.SetActive(true);
progressBar.fillAmount = 1f;
loadingText.text = "LOADING DONE";
}
}
위 스크립트를 호출하는 UIButton의 스크립트 :
public class LoadingSceneButton : MonoBehaviour {
public void LoadSceneWithLoadingScreen(int sceneNumber){
if (sceneNumber < 0 || sceneNumber >= SceneManager.sceneCountInBuildSettings) {
Debug.LogWarning ("Can't Load Scene, because It Doesn't Exist!");
}
LoadingScreenManager.LoadScene (sceneNumber);
}
}
(1) "인쇄"를 사용하지 마십시오. 다음을 사용하십시오.
Debug.Log("fadeDuration is ....... " , fadeDuration.ToString("f4");
전화하기 직전에 해당 코드 줄을 FadeOut
추가하고 내부에 추가하십시오.FadeOut
CrossFadeAlpha
Please note that CrossFadeAlpha is extremely difficult to use! It's a real pain! It only works on UnityEngine.UI.Graphic
, and it's tricky when used with coroutines.
public static void FadeOut(this Graphic g)
{
g.GetComponent<CanvasRenderer>().SetAlpha(1f);
g.CrossFadeAlpha(0f,.15f,false);
}
Yes there is a
where it gets stuck on 0.9. Maybe this is the main problem at hand.
check out ... http://answers.unity3d.com/answers/1146173/view.html
and ... http://answers.unity3d.com/answers/1073667/view.html
Some basic working code example....
public void LaunchSoundboard()
{
StartCoroutine(_soundboard());
}
private IEnumerator _soundboard()
{
Grid.music.Duck();
yield return new WaitForSeconds(.2f);
AsyncOperation ao;
ao = UnityEngine.SceneManagement
.SceneManager.LoadSceneAsync("YourSceneName");
while (!ao.isDone)
{
yield return null;
}
// here, the new scene IS LOADED
SoundBoard soundBoard = Object.FindObjectOfType<SoundBoard>();
if(soundBoard==null) Debug.Log("WOE!");
soundBoard.SomeFunctionInSoundboardScript();
}
(4) #You actually have to have a scene called "preload", which ONLY preloads.
unfortunately the menu scene can not be your preload scene.
실제로 "사전로드"만 수행하는 별도의 사전로드 씬이 있어야합니다.
당신이 가지고있는 모든 "게임 관리자"는 프리로드 씬에 있어야합니다. 조금 성가 시지만 그게 바로 그 거예요.
"사전로드"장면의 목적은 보유한 게임 관리자를 보유하는 것입니다.
단지 당신이 "부하에 파괴하지 않는다"표시 있음 장면해야 만 은 "프리로드"장면. 그렇게 간단합니다.
약간 성가신 일이지만 매우 간단하고 신뢰할 수 있습니다.
이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.
침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제
몇 마디 만하겠습니다