Ejemplo n.º 1
0
 private void ConvertCullingMask(ref LayerMask mask)
 {
     if (newDimension != Dimension.Default)
     {
         if (LayerMaskTools.IncludesLayer(mask, "Default"))
         {
             LayerMaskTools.RemoveFromMask(ref mask, "Default");
             LayerMaskTools.AddToMask(ref mask, ("Default_" + newDimension.ToString()));
         }
         if (LayerMaskTools.IncludesLayer(mask, "PlayerSelf"))
         {
             LayerMaskTools.RemoveFromMask(ref mask, "PlayerSelf");
             LayerMaskTools.AddToMask(ref mask, ("PlayerSelf_" + newDimension.ToString()));
         }
     }
     else
     {
         if (LayerMaskTools.IncludesLayer(mask, ("Default_" + currentDimension.ToString())))
         {
             LayerMaskTools.RemoveFromMask(ref mask, ("Default_" + currentDimension.ToString()));
             LayerMaskTools.AddToMask(ref mask, "Default");
         }
         if (LayerMaskTools.IncludesLayer(mask, ("PlayerSelf_" + currentDimension.ToString())))
         {
             LayerMaskTools.RemoveFromMask(ref mask, ("PlayerSelf_" + currentDimension.ToString()));
             LayerMaskTools.AddToMask(ref mask, "PlayerSelf");
         }
     }
 }
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);
    }
Ejemplo n.º 3
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.º 4
0
    //  Generate the cameras and render textures needed for each dimension
    private void CreatePlayerCameras()
    {
        //  Create a new array the size of the number of dimenions, plus the self-camera
        m_cameras = new Camera[m_numberOfDimensions + 1];
        //  Create a new array the size of the number of dimensions
        m_renderTextures = new RenderTexture[m_numberOfDimensions];

        //  Create and set up the self-camera
        Camera selfCam = new GameObject("Camera_self").AddComponent <Camera>();

        selfCam.fieldOfView = m_startFov;
        selfCam.cullingMask = 0 << 0;
        selfCam.depth       = 1;
        selfCam.clearFlags  = CameraClearFlags.Depth;
        selfCam.transform.SetParent(cameraAnchor);
        selfCam.transform.localPosition    = Vector3.zero;
        selfCam.transform.localEulerAngles = Vector3.zero;
        selfCam.gameObject.AddComponent <DimensionTransitionEffect>();
        selfCam.gameObject.GetComponent <DimensionTransitionEffect>().material = speedEffectMaterial;
        LayerMask selfMask = selfCam.cullingMask;

        //  Loop through each dimension
        for (int i = 0; i < m_numberOfDimensions; i++)
        {
            //  Create a new camera for the dimension
            string camName = ("Camera_" + ((Dimension)i).ToString());
            Camera newCam  = new GameObject(camName).AddComponent <Camera>();
            newCam.fieldOfView = m_startFov;
            newCam.transform.SetParent(cameraAnchor);
            newCam.transform.localPosition    = Vector3.zero;
            newCam.transform.localEulerAngles = Vector3.zero;

            //  Set the new camera's skybox to match the dimension
            Skybox       sky    = newCam.gameObject.AddComponent <Skybox>();
            SkyboxHolder holder = GameObject.Find("Skybox_" + ((Dimension)i).ToString()).GetComponent <SkyboxHolder>();
            sky.material = holder.skybox;

            //  Add and remove the appropriate layers from the camera's culling mask
            LayerMask newMask = newCam.cullingMask;
            if (((Dimension)i) == Dimension.Default)
            {
                for (int j = 0; j < m_numberOfDimensions; j++)
                {
                    if (i != j)
                    {
                        LayerMaskTools.RemoveFromMask(ref newMask, ("Default_" + ((Dimension)j).ToString()));
                        LayerMaskTools.RemoveFromMask(ref newMask, ("PlayerSelf_" + ((Dimension)j).ToString()));
                    }
                }

                LayerMaskTools.AddToMask(ref selfMask, "PlayerSelf");
            }
            else
            {
                LayerMaskTools.RemoveFromMask(ref newMask, "Default");
                LayerMaskTools.RemoveFromMask(ref newMask, "PlayerSelf");
                for (int j = 0; j < m_numberOfDimensions; j++)
                {
                    if (((Dimension)j) != Dimension.Default && i != j)
                    {
                        LayerMaskTools.RemoveFromMask(ref newMask, ("Default_" + ((Dimension)j).ToString()));
                        LayerMaskTools.RemoveFromMask(ref newMask, ("PlayerSelf_" + ((Dimension)j).ToString()));
                    }
                }

                LayerMaskTools.AddToMask(ref selfMask, ("PlayerSelf_" + ((Dimension)i).ToString()));
            }
            newCam.cullingMask = newMask;

            //  Add the new camera to the array
            m_cameras[i] = newCam;
            if (Singletons.gameManager.debug)
            {
                Debug.Log("Added camera '" + camName + "'.");
            }
        }

        //  Set the self-camera's culling mask
        selfCam.cullingMask = selfMask;
        //  Add the self-camera to the array
        m_cameras[m_numberOfDimensions] = selfCam;
    }