Exemplo n.º 1
0
        // Flow of transition when previous and new scenes zoom in and out at the same time e.g when going to a planet or when leaving a planet
        private IEnumerator ZoomInOutSimultaneouslyFlow(SceneTransition previousTransition, SceneTransition newTransition)
        {
            GameObject singlePlanet  = null;
            GameObject relatedPlanet = null;

            GetRelatedPlanets(out relatedPlanet, out singlePlanet);

            // In previous scene, fade out pois and then fade the rest of the scene
            if (previousTransition)
            {
                if (introStage == IntroStage.kInactiveIntro)
                {
                    isFading = true;
                    GalaxyExplorerManager.Instance.GeFadeManager.Fade(previousTransition.GetComponentInChildren <POIMaterialsFader>(), GEFadeManager.FadeType.FadeOut, PoiFadeOutDuration, POIOpacityCurveStartTransition);
                    while (isFading)
                    {
                        yield return(null);
                    }
                }

                isFading = true;
                float fadeTime = GetClosingSceneVisibilityTime();
                GalaxyExplorerManager.Instance.GeFadeManager.FadeExcept(previousTransition.GetComponentsInChildren <Fader>(), typeof(POIMaterialsFader), null, GEFadeManager.FadeType.FadeOut, fadeTime, OpacityCurveClosingScene);
            }

            PlayTransitionAudio(newTransition.transform, inForwardTransition);

            // Make invisible one of the two planets that represent the same entity in both scenes
            if (relatedPlanet && singlePlanet)
            {
                SetRenderersVisibility(newTransition.IsSinglePlanetTransition ? relatedPlanet.transform.parent.gameObject : singlePlanet.transform.parent.gameObject, false);
            }

            // make alpha of pois of next scene equal to zero so they arent visible
            GalaxyExplorerManager.Instance.GeFadeManager.SetAlphaOnFader(newTransition.GetComponentInChildren <POIMaterialsFader>(), 0.0f);
            var faderToExclude = default(Fader);

            // if going back to solar system from a planet then fade in solar system
            // Dont fade the material of the selected/related planet in the next scene or any poi
            if (previousTransition && previousTransition.IsSinglePlanetTransition)
            {
                Fader[] allFaders = newTransition.GetComponentsInChildren <Fader>();
                GalaxyExplorerManager.Instance.GeFadeManager.SetAlphaOnFaderExcept(allFaders, typeof(POIMaterialsFader), 0.0f);

                if (relatedPlanet)
                {
                    GalaxyExplorerManager.Instance.GeFadeManager.SetAlphaOnFader(relatedPlanet.GetComponent <Fader>(), 1.0f);
                }

                isFading = true;
                AnimationCurve opacityCurve = newTransition.gameObject.name.Contains("solar_system") ? PlanetToSSTransitionOpacityCurveContentChange : OpacityCurveEnteringScene;
                GalaxyExplorerManager.Instance.GeFadeManager.FadeExcept(allFaders, typeof(POIMaterialsFader), relatedPlanet, GEFadeManager.FadeType.FadeIn, TransitionTimeOpeningScene, opacityCurve);
            }
            else if ((previousTransition && !previousTransition.IsSinglePlanetTransition && newTransition && !newTransition.IsSinglePlanetTransition))
            {
                if (newTransition.gameObject.name.Contains("SolarSystem"))
                {
                    var sun      = GameObject.Find("poi_sun_prefab");
                    var sunFader = sun.GetComponentInChildren <Fader>(true);
                    faderToExclude = sunFader;
                }
                Fader[] allFaders = newTransition.GetComponentsInChildren <Fader>();
                GalaxyExplorerManager.Instance.GeFadeManager.SetAlphaOnFaderExcept(allFaders, typeof(POIMaterialsFader), 0.0f);
                allFaders = allFaders.Where(f => f != faderToExclude).ToArray();

                isFading = true;
                GalaxyExplorerManager.Instance.GeFadeManager.FadeExcept(allFaders, typeof(POIMaterialsFader), null, GEFadeManager.FadeType.FadeIn, TransitionTimeOpeningScene, OpacityCurveEnteringScene);
                GalaxyExplorerManager.Instance.GeFadeManager.Fade(faderToExclude, GEFadeManager.FadeType.FadeIn, 1, POIOpacityCurveStartTransition, 3f);
            }

            if (newTransition.gameObject.scene.name.Contains("galaxy_view_scene"))
            {
                StartCoroutine(ZoomInOutBehaviour.ZoomInOutCoroutine(TransitionTimeOpeningScene, GetContentTransitionCurve(newTransition.gameObject.scene.name), GetContentRotationCurve(newTransition.gameObject.scene.name), GetContentTransitionCurve(newTransition.gameObject.scene.name), BackToGalaxyPositionTransitionCurveContentChange, offset: newTransition.scenePositionOffset));
            }
            else if (previousTransition && previousTransition.IsSinglePlanetTransition)
            {
                StartCoroutine(ZoomInOutBehaviour.ZoomInOutCoroutine(TransitionTimeOpeningScene, GetContentTransitionCurve(newTransition.gameObject.scene.name), GetContentRotationCurve(newTransition.gameObject.scene.name), PlanetToSSScaleCurveContentChange, offset: newTransition.scenePositionOffset));
            }
            else
            {
                StartCoroutine(ZoomInOutBehaviour.ZoomInOutCoroutine(TransitionTimeOpeningScene, GetContentTransitionCurve(newTransition.gameObject.scene.name), GetContentRotationCurve(newTransition.gameObject.scene.name), GetContentTransitionCurve(newTransition.gameObject.scene.name), offset: newTransition.scenePositionOffset));
            }

            StartCoroutine(LightTransitions(previousTransition, newTransition));

            yield return(null);
        }
Exemplo n.º 2
0
        // Light transition is necessary in case of Simultaneous transitions in order for sun light position to be the same and transition to look good
        private IEnumerator LightTransitions(SceneTransition previousTransition, SceneTransition newTransition)
        {
            if (previousTransition == null || newTransition == null)
            {
                yield break;
            }

            GameObject singlePlanet  = null;
            GameObject relatedPlanet = null;

            GetRelatedPlanets(out relatedPlanet, out singlePlanet);

            // if next scene is a planet then position its light to where sun of previous scene is and move it towards its initial position
            if (newTransition && newTransition.IsSinglePlanetTransition)
            {
                SunLightReceiver sunLight    = newTransition.GetComponentInChildren <SunLightReceiver>();
                Transform        previousSun = FindByName(previousTransition.transform, "Sun");
                //previousTransition.transform.Find("Sun");
                Vector3 initialSunPosition = Vector3.zero;
                if (sunLight && sunLight.Sun && previousSun)
                {
                    initialSunPosition = sunLight.Sun.transform.localPosition;
                    sunLight.Sun.transform.position = singlePlanet.transform.position - (relatedPlanet.transform.position - previousSun.position);

                    float delta = 0.0f;
                    do
                    {
                        delta += Time.deltaTime / TransitionTimeOpeningScene;
                        delta  = Mathf.Clamp(delta, 0.0f, 1.0f);
                        sunLight.Sun.transform.localPosition = Vector3.Lerp(sunLight.Sun.transform.localPosition, initialSunPosition, delta);
                        yield return(null);
                    } while (delta < 1.0f);
                }
            }
            // in case of previous scene is a single planet scene, find the new scene related planet's SunLightReceivers
            // and replace their sun to a new gameobject pretending to be a sun. This sun;s starting position is
            // same as the old scene's sun position and transition to new sun's position
            else if (previousTransition && previousTransition.IsSinglePlanetTransition)
            {
                SunLightReceiver[] allLightReceivers = relatedPlanet.GetComponentsInChildren <SunLightReceiver>();
                Transform          newSun            = FindByName(newTransition.transform, "Sun");
                if (allLightReceivers.Length > 0 && newSun)
                {
                    GameObject lightPlaceholder = new GameObject();
                    lightPlaceholder.transform.parent = newTransition.ThisSceneObject.transform;

                    // Old scene's light position
                    SunLightReceiver oldLight = previousTransition.GetComponentInChildren <SunLightReceiver>();
                    lightPlaceholder.transform.position = (oldLight && oldLight.Sun) ? oldLight.Sun.transform.position : Vector3.zero;

                    // Replace sun to the placeholder object
                    foreach (var light in allLightReceivers)
                    {
                        light.Sun = lightPlaceholder.transform;
                    }

                    // Move placeholder light position towards sun's position
                    float delta = 0.0f;
                    do
                    {
                        delta += Time.deltaTime / TransitionTimeOpeningScene;
                        delta  = Mathf.Clamp(delta, 0.0f, 1.0f);
                        lightPlaceholder.transform.position = Vector3.Lerp(lightPlaceholder.transform.position, newSun.transform.position, delta);
                        yield return(null);
                    } while (delta < 1.0f);

                    Destroy(lightPlaceholder);
                }
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Callback when next scene is loaded
        /// Has the logic of the flow related to previous and next scene
        /// </summary>
        private IEnumerator NextSceneLoadedCoroutine()
        {
            GameObject nextSceneContent = FindContent();

            ZoomInOutBehaviour.ZoomInIsDone  = false;
            ZoomInOutBehaviour.ZoomOutIsDone = false;

            SceneTransition previousTransition = (prevSceneLoaded) ? prevSceneLoaded.GetComponentInChildren <SceneTransition>() : null;
            SceneTransition newTransition      = nextSceneContent.GetComponentInChildren <SceneTransition>();

            CurrentActiveScene = nextSceneContent;

            SetActivationOfTouchscript(false);
            DeactivateOrbitUpdater(newTransition, previousTransition, false);
            SetActivePOIRotationAnimator(false, previousTransition, newTransition);
            UpdateActivationOfPOIs(newTransition, false);
            UpdateActivationOfPOIs(previousTransition, false);

            // Scale new scene to fit inside the volume
            float scaleToFill = transformSource.transform.lossyScale.x;
            float targetSize  = newTransition.GetScalar(scaleToFill);

            newTransition.transform.GetChild(0).localScale = Vector3.one * targetSize;

            // Initialize zoom in and out transition properties
            StartCoroutine(ZoomInOutBehaviour.ZoomInOutInitialization(nextSceneContent, prevSceneLoaded));

            // In order for the next scene not being visible while the previous is fading, set scale to zero and deactivate all its colliders
            if (ZoomInOutBehaviour.GetNextScene)
            {
                ZoomInOutBehaviour.GetNextScene.transform.localScale = Vector3.zero;
                SetCollidersActivation(ZoomInOutBehaviour.GetNextScene.GetComponentsInChildren <Collider>(), false);
            }

            // Deactivate previous scene's colliders
            if (previousTransition)
            {
                SetCollidersActivation(previousTransition.GetComponentsInChildren <Collider>(), false);
            }

            yield return(new WaitForEndOfFrame());

            StartCoroutine(ZoomInOutSimultaneouslyFlow(previousTransition, newTransition));

            // wait until prev scene transition finishes
            while (!ZoomInOutBehaviour.ZoomOutIsDone)
            {
                yield return(null);
            }

            DeactivateOrbitUpdater(newTransition, previousTransition, true);
            UpdateActivationOfPOIs(newTransition, true);

            // Unload previous scene
            if (prevSceneLoaded != null)
            {
                UnloadScene(prevSceneLoaded.scene.name, true);
            }

            // Wait until next scene transition is done
            while (!ZoomInOutBehaviour.ZoomInIsDone)
            {
                yield return(null);
            }

            SetActivePOIRotationAnimator(true, previousTransition, newTransition);

            // Fade in pois of next scene
            if (introStage != IntroStage.kActiveIntro)
            {
                isFading = true;
                GalaxyExplorerManager.Instance.GeFadeManager.Fade(newTransition.GetComponentInChildren <POIMaterialsFader>(), GEFadeManager.FadeType.FadeIn, PoiFadeInDuration, POIOpacityCurveEndTransition);
            }

            while (isFading)
            {
                yield return(null);
            }

            yield return(new WaitForEndOfFrame());

            while (GalaxyExplorerManager.Instance.VoManager.ShouldAudioBlockProgress)
            {
                yield return(null);
            }

            // Activate colliders of next scene
            if (ZoomInOutBehaviour.GetNextScene && introStage != IntroStage.kActiveIntro)
            {
                SetCollidersActivation(ZoomInOutBehaviour.GetNextScene.GetComponentsInChildren <Collider>(), true);
            }

            SetActivationOfTouchscript(true);

            inTransition = false;
            introStage   = (introStage == IntroStage.kLastStageIntro) ? IntroStage.kInactiveIntro : introStage;

            yield return(null);
        }