protected IEnumerator Transition(string newSceneName, bool resetInputValues, SceneTransitionDestination.DestinationTag destinationTag, TransitionPoint.TransitionType transitionType = TransitionPoint.TransitionType.DifferentZone) { m_Transitioning = true; PersistentDataManager.SaveAllData(); if (m_PlayerInput == null) { m_PlayerInput = FindObjectOfType <PlayerInput>(); } m_PlayerInput.ReleaseControl(resetInputValues); yield return(StartCoroutine(ScreenFader.FadeSceneOut(ScreenFader.FadeType.Loading))); PersistentDataManager.ClearPersisters(); yield return(SceneManager.LoadSceneAsync(newSceneName)); m_PlayerInput = FindObjectOfType <PlayerInput>(); m_PlayerInput.ReleaseControl(resetInputValues); PersistentDataManager.LoadAllData(); SceneTransitionDestination entrance = GetDestination(destinationTag); SetEnteringGameObjectLocation(entrance); SetupNewScene(transitionType, entrance); if (entrance != null) { entrance.OnReachDestination.Invoke(); } yield return(StartCoroutine(ScreenFader.FadeSceneIn())); m_PlayerInput.GainControl(); m_Transitioning = false; }
//Corutina de Transicion de escena lo incialisa el metodo TransitionToScene y RestartZone arriba, protected IEnumerator Transition(string newSceneName, bool resetInputValues, SceneTransitionDestination.DestinationTag destinationTag, TransitionPoint.TransitionType transitionType = TransitionPoint.TransitionType.DifferentZone) { m_Transitioning = true; PersistentDataManager.SaveAllData();//salve todos los datos //si el input esta vacio encuentrelo if (m_PlayerInput == null) { m_PlayerInput = FindObjectOfType <PlayerInput>(); } m_PlayerInput.ReleaseControl(resetInputValues); //Pierde el control del input liberelo reseteando los valores yield return(StartCoroutine(ScreenFader.FadeSceneOut(ScreenFader.FadeType.Loading))); //Llame la corutina de FadeSceneOut de tipo Loading PersistentDataManager.ClearPersisters(); yield return(SceneManager.LoadSceneAsync(newSceneName)); //carge la nueva escena asincronicamente m_PlayerInput = FindObjectOfType <PlayerInput>(); //encuentre el input m_PlayerInput.ReleaseControl(resetInputValues); //libere y resetee valores PersistentDataManager.LoadAllData(); //carge todos los datos SceneTransitionDestination entrance = GetDestination(destinationTag); //en una variable de tipo scirpt SceneTransitio...obtenga el destino llamando el metodo protegido mas abajo SetEnteringGameObjectLocation(entrance); //le paso como variable lo recogido en el metodo anterior, este nuevo metodo es llamado mas abajo SetupNewScene(transitionType, entrance); //configure la nueva escena, metodo mas abajo if (entrance != null) //en caso de que siga vacio { entrance.OnReachDestination.Invoke(); //entrance es una instancia de SceneTransitionDest... que luego llama que llama al campo OnReach.invoke que son un evento de Unity } //Es como un llamado para asegurarse que si encunter el destino, en el inpector se especifica, ademas de llamar al script CharacterStateSetter que permite configurar al personaje una vez entre(posicion, animador, etc). yield return(StartCoroutine(ScreenFader.FadeSceneIn())); //fadeIn m_PlayerInput.GainControl(); //obtenga control nuevamente m_Transitioning = false; }
protected void SetupNewScene(TransitionPoint.TransitionType transitionType, SceneTransitionDestination entrance) { if (entrance == null) { Debug.LogWarning("Restart information has not been set."); return; } if (transitionType == TransitionPoint.TransitionType.DifferentZone) { SetZoneStart(entrance); } }
protected void SetEnteringGameObjectLocation(SceneTransitionDestination entrance) { if (entrance == null) { Debug.LogWarning("Entering Transform's location has not been set."); return; } Transform entranceLocation = entrance.transform; Transform enteringTransform = entrance.transitioningGameObject.transform; enteringTransform.position = entranceLocation.position; enteringTransform.rotation = entranceLocation.rotation; }
//初始化当前关卡信息,重生点信息 protected void SetZoneStart(SceneTransitionDestination entrance) { m_CurrentZoneScene = entrance.gameObject.scene; m_ZoneRestartDestinationTag = entrance.destinationTag; }