Exemplo n.º 1
0
    IEnumerator GoToScreenCallback(MenuScreen newScr, IEnumerator callback)
    {
        IsChangingScreens = true;

        //Ready the next screen
        Debug.Log( "Ending current screen" );

        OnPreScreenChange.Invoke( );
        yield return StartCoroutine( callback );

        //Then fade out the current screen
        if ( CurrentScreenObject != null )
        {
            CurrentScreenObject.gameObject.SetActive( false );
        }

        Debug.Log( "Lerping" );

        //Lerp to new position
        if ( CameraPositions.ContainsKey(newScr.ToString( ) ) )
        {
            while ( Vector3.Distance( Camera.main.transform.position, CameraPositions[ newScr.ToString( ) ] ) > 0.1f )
            {
                Camera.main.transform.position =
                    Vector3.Slerp( Camera.main.transform.position, CameraPositions[ newScr.ToString( ) ], CameraTweenSpeed );

                yield return null;
            }
        }

        Debug.Log( "Opening new screen" );

        if ( newScr != MenuScreen.NONE )
        {
            //Open new screen and record it as the current object
            foreach ( Transform scrObj in ScreenObjects )
            {
                var bSetActive = scrObj.name.Contains( newScr.ToString( ) );

                //print( scrObj.name + ": " + newScr.ToString( ) );

                if ( bSetActive )
                {
                    scrObj.gameObject.SetActive( true );
                    CurrentScreenObject = scrObj;
                    OnScreenChanged.Invoke( );
                }
                else
                    scrObj.gameObject.SetActive( false );
            }
        }

        //Assign the current screen
        CurrentScreen = newScr;

        IsChangingScreens = false;

        yield return null;
    }