Ejemplo n.º 1
0
    //  Switch dimensions without the transition
    private IEnumerator SwitchDimensionImmediateCoroutine(Dimension newDimension, Dimension fromDimension)
    {
        m_switchingDimensions  = true;
        m_switchingToDimension = newDimension;
        int numberOfDimensions = Dimension.GetNames(typeof(Dimension)).Length;

        DimensionTransitionEffect effect = m_cameras[numberOfDimensions].GetComponent <DimensionTransitionEffect>();

        effect.intensity = 0.0f;

        //  Switch render textures
        for (int i = 0; i < numberOfDimensions; i++)
        {
            Camera cam = m_cameras[i];

            if (i == (int)m_switchingToDimension)
            {
                cam.targetTexture = null;
                cam.depth         = 0;
            }
            else
            {
                m_cameras[i].targetTexture = m_renderTextures[i];
                cam.depth = -1;
            }

            if (i == (int)m_switchingToDimension)
            {
                m_audioSources[i].volume = 1;
            }
            else
            {
                m_audioSources[i].volume = 0;
            }
        }

        //  Set the new render texture
        Shader.SetGlobalTexture("_DimensionPrevewTex", m_renderTextures[(int)GetNextDimension(m_switchingToDimension)]);

        //  Switch the collider's layers
        m_groundMask = 0;
        if (m_switchingToDimension == Dimension.Default)
        {
            m_col.gameObject.layer               = LayerMask.NameToLayer("PlayerSelf");
            m_knife.gameObject.layer             = m_col.gameObject.layer;
            m_knife.GetChild(0).gameObject.layer = m_col.gameObject.layer;
            m_knife.GetChild(1).gameObject.layer = m_col.gameObject.layer;
            m_knife.GetChild(2).gameObject.layer = m_col.gameObject.layer;
            m_knife.GetChild(3).gameObject.layer = m_col.gameObject.layer;
            LayerMaskTools.AddToMask(ref m_groundMask, LayerMask.NameToLayer("Default"));
        }
        else
        {
            m_col.gameObject.layer               = LayerMask.NameToLayer("PlayerSelf_" + m_switchingToDimension.ToString());
            m_knife.gameObject.layer             = m_col.gameObject.layer;
            m_knife.GetChild(0).gameObject.layer = m_col.gameObject.layer;
            m_knife.GetChild(1).gameObject.layer = m_col.gameObject.layer;
            m_knife.GetChild(2).gameObject.layer = m_col.gameObject.layer;
            m_knife.GetChild(3).gameObject.layer = m_col.gameObject.layer;
            LayerMaskTools.AddToMask(ref m_groundMask, LayerMask.NameToLayer("Default_" + m_switchingToDimension.ToString()));
        }

        m_switchingDimensions = false;
        m_currentDimension    = m_switchingToDimension;

        yield return(null);
    }
Ejemplo n.º 2
0
    //  The co-routine that switches the player to a different dimension
    private IEnumerator SwitchDimensionCoroutine(Dimension newDimension, Dimension fromDimension)
    {
        m_switchingDimensions  = true;
        m_switchingToDimension = newDimension;
        int numberOfDimensions = Dimension.GetNames(typeof(Dimension)).Length;

        bool  transitioning = true;
        float t             = 0.0f;
        float completion    = 0.0f;

        DimensionTransitionEffect effect = m_cameras[numberOfDimensions].GetComponent <DimensionTransitionEffect>();

        effect.intensity = 1.0f;

        bool  halfWay = false;
        float prevE   = 0.0f;

        while (transitioning)
        {
            t         += Time.deltaTime;
            completion = Mathf.Clamp01(t / m_transitionTime);
            float e = m_curve.Evaluate(completion);

            effect.intensity = e;
            float newFov = Mathf.Lerp(m_startFov, m_endFov, e);

            for (int i = 0; i < numberOfDimensions; i++)
            {
                m_cameras[i].fieldOfView = newFov;

                if (i == (int)m_switchingToDimension)
                {
                    m_audioSources[i].volume = e;
                }
                else if (i == (int)fromDimension)
                {
                    m_audioSources[i].volume = 1 - e;
                }
                else
                {
                    m_audioSources[i].volume = 0;
                }
            }

            if (((completion >= m_transitionSwitchPoint && !m_autoSwitchPoint) || (prevE > e && m_autoSwitchPoint)) && !halfWay)
            {
                halfWay = true;

                //  Switch render textures
                for (int i = 0; i < numberOfDimensions; i++)
                {
                    Camera cam = m_cameras[i];

                    if (i == (int)m_switchingToDimension)
                    {
                        cam.targetTexture = null;
                        cam.depth         = 0;
                    }
                    else
                    {
                        m_cameras[i].targetTexture = m_renderTextures[i];
                        cam.depth = -1;
                    }
                }

                //  Set the new render texture
                Shader.SetGlobalTexture("_DimensionPrevewTex", m_renderTextures[(int)GetNextDimension(m_switchingToDimension)]);

                //  Switch the collider's layers
                m_groundMask = 0;
                if (newDimension == Dimension.Default)
                {
                    m_col.gameObject.layer               = LayerMask.NameToLayer("PlayerSelf");
                    m_knife.gameObject.layer             = m_col.gameObject.layer;
                    m_knife.GetChild(0).gameObject.layer = m_col.gameObject.layer;
                    m_knife.GetChild(1).gameObject.layer = m_col.gameObject.layer;
                    m_knife.GetChild(2).gameObject.layer = m_col.gameObject.layer;
                    m_knife.GetChild(3).gameObject.layer = m_col.gameObject.layer;
                    LayerMaskTools.AddToMask(ref m_groundMask, LayerMask.NameToLayer("Default"));
                }
                else
                {
                    m_col.gameObject.layer               = LayerMask.NameToLayer("PlayerSelf_" + newDimension.ToString());
                    m_knife.gameObject.layer             = m_col.gameObject.layer;
                    m_knife.GetChild(0).gameObject.layer = m_col.gameObject.layer;
                    m_knife.GetChild(1).gameObject.layer = m_col.gameObject.layer;
                    m_knife.GetChild(2).gameObject.layer = m_col.gameObject.layer;
                    m_knife.GetChild(3).gameObject.layer = m_col.gameObject.layer;
                    LayerMaskTools.AddToMask(ref m_groundMask, LayerMask.NameToLayer("Default_" + newDimension.ToString()));
                }
            }

            prevE = e;

            if (completion >= 1.0f)
            {
                transitioning = false;
            }
            yield return(new WaitForEndOfFrame());
        }

        effect.intensity = 0.0f;

        m_switchingDimensions = false;
        m_currentDimension    = newDimension;

        yield return(null);
    }