Exemple #1
0
    /// <summary>
    /// Coroutine that carries our our scene transition
    /// </summary>
    /// <param name="PlayerCharacter"></param>
    /// <param name="DoorToLoad"></param>
    /// <returns></returns>
    private IEnumerator SceneTransitionCoroutine(EHPlayerCharacter PlayerCharacter, DoorData DoorToLoad)
    {
        if (!PlayerCharacter)
        {
            Debug.LogWarning("The player that was passed in was null");
            yield break;
        }
        if (!DoorToLoad)
        {
            Debug.LogWarning("The Door to load was null");
            yield break;
        }
        bIsExecutingSceneTransition = true;
        Image_BlackScreen.color     = Color.clear;
        Image_BlackScreen.gameObject.SetActive(true);

        PlayerCharacter.GetComponent <EHPlayerController>().enabled = false;
        float TimeThatHasPassed = 0;

        while (TimeThatHasPassed < TransitionTimeSeconds)
        {
            yield return(null);

            TimeThatHasPassed      += EHTime.RealDeltaTime;
            Image_BlackScreen.color = new Color(0, 0, 0, TimeThatHasPassed / TransitionTimeSeconds);
        }
        Image_BlackScreen.color = Color.black;

        RoomActor CurrentlyLoadedRoom = BaseGameOverseer.Instance.CurrentlyLoadedRoom;

        if (CurrentlyLoadedRoom.GetAssociatedRoomData() != DoorToLoad.GetDoorRoom())
        {
            if (CurrentlyLoadedRoom && CurrentlyLoadedRoom.GetAssociatedRoomData())
            {
                print(CurrentlyLoadedRoom.GetAssociatedRoomData().RoomScene);
                yield return(SceneManager.UnloadSceneAsync(CurrentlyLoadedRoom.GetAssociatedRoomData().RoomScene));
            }
            yield return(SceneManager.LoadSceneAsync(DoorToLoad.GetDoorRoom().RoomScene, LoadSceneMode.Additive));
        }
        yield return(new WaitForSecondsRealtime(0.5f));

        DoorActor DoorToSpawnFrom        = BaseGameOverseer.Instance.CurrentlyLoadedRoom.GetRoomDoorTriggerFromDoorData(DoorToLoad);
        Vector3   CharacterSpawnPosition = Vector3.zero;

        if (DoorToSpawnFrom == null)
        {
            Debug.LogError("There was no associated door actor to spawn our character");
        }
        else
        {
            CharacterSpawnPosition = DoorToSpawnFrom.GetSpawnPosition();
        }

        PlayerCharacter.SetCharacterAtPosition(CharacterSpawnPosition);
        EHPhysics2D Physics2D = PlayerCharacter.GetComponent <EHPhysics2D>();

        if (Physics2D)
        {
            Physics2D.Velocity = Vector2.zero;
        }
        BaseGameOverseer.Instance.MainGameCamera.FocusCameraImmediate();
        PlayerCharacter.GetComponent <EHPlayerController>().enabled = true;
        TimeThatHasPassed           = 0;
        bIsExecutingSceneTransition = false;
        while (TimeThatHasPassed < TransitionTimeSeconds && !bIsExecutingSceneTransition)
        {
            yield return(null);

            TimeThatHasPassed      += EHTime.RealDeltaTime;
            Image_BlackScreen.color = new Color(0, 0, 0, 1 - (TimeThatHasPassed / TransitionTimeSeconds));
        }

        Image_BlackScreen.color = Color.clear;
    }