// Use this for initialization
    void Awake()
    {
        thisPillar    = GetComponent <DimensionPillar>();
        thisRenderer  = GetComponent <SuperspectiveRenderer>();
        optionalGlass = GetComponentInChildren <GlassGlow>();

        wasActive = thisPillar.enabled;
    }
Exemplo n.º 2
0
    void Awake()
    {
        pillar         = GetComponentInParent <DimensionPillar>();
        pillarRenderer = pillar.GetComponent <Renderer>();
        thisRenderer   = GetComponent <Renderer>();

        roomBoundsMask = 1 << LayerMask.NameToLayer("RoomBounds");

        InitializeWallTransform();
    }
 private void SearchForPillarsInBox(List <DimensionPillar> blacklist)
 {
     foreach (var pillarMaybe in Physics.OverlapBox(transform.position, pillarSearchBoxSize / 2f, new Quaternion()))
     {
         DimensionPillar pillar = pillarMaybe.GetComponent <DimensionPillar>();
         if (pillar != null && !blacklist.Contains(pillar))
         {
             pillarsFound.Add(pillar);
         }
     }
 }
 private void SearchForPillarsInSphere(List <DimensionPillar> blacklist)
 {
     foreach (var pillarMaybe in Physics.OverlapSphere(transform.position, pillarSearchRadius))
     {
         DimensionPillar pillar = pillarMaybe.GetComponent <DimensionPillar>();
         if (pillar != null && !blacklist.Contains(pillar))
         {
             pillarsFound.Add(pillar);
         }
     }
 }
Exemplo n.º 5
0
    private void TriggerPillarChangeBackward()
    {
        if (backwardTriggeredPillar == null && !backwardSameScenePillar)
        {
            string pillarKey = PillarKey(backwardPillarLevel, backwardPillarName);
            if (DimensionPillar.pillars.ContainsKey(pillarKey))
            {
                backwardTriggeredPillar = DimensionPillar.pillars[pillarKey];
            }
        }

        DimensionPillar.activePillar = backwardTriggeredPillar;
    }
    protected virtual void HandleActivePillarChanged(DimensionPillar prevPillar)
    {
        if (prevPillar != null && PillarIsRelevant(prevPillar))
        {
            TeardownEventListeners(prevPillar);
        }
        FindRelevantPillars();

        if (DimensionPillar.activePillar != null && PillarIsRelevant(DimensionPillar.activePillar))
        {
            RecalculateOnOffPositions();
            SetupEventListeners(DimensionPillar.activePillar);
            HandlePillarDimensionChange(-1, DimensionPillar.activePillar.curDimension);
        }
    }
Exemplo n.º 7
0
        /// <summary>
        /// Frame 1: Teleport player and disable this portal's volumetric portal while enabling the otherPortal's volumetric portal
        /// Frame 2: Do nothing (but ensure that this is not called twice)
        /// </summary>
        /// <param name="player"></param>
        /// <returns></returns>
        IEnumerator TeleportPlayer(Transform player)
        {
            teleportingPlayer = true;

            //if (DEBUG) Debug.Break();
            TriggerEventsBeforeTeleport(player.GetComponent <Collider>());

            // Position
            player.position = TransformPoint(player.position);

            // Rotation
            player.rotation = TransformRotation(player.rotation);

            // Velocity
            Rigidbody playerRigidbody = player.GetComponent <Rigidbody>();

            playerRigidbody.velocity = TransformDirection(playerRigidbody.velocity);

            Physics.gravity = Physics.gravity.magnitude * -player.up;

            if (changeCameraEdgeDetection)
            {
                SwapEdgeDetectionColors();
            }

            if (changeActiveSceneOnTeleport)
            {
                LevelManager.instance.SwitchActiveScene(otherPortal.gameObject.scene.name);
            }

            // If the out portal is also a PillarDimensionObject, update the active pillar's curDimension to match the out portal's Dimension
            if (otherPortal.dimensionObject != null && otherPortal.dimensionObject is PillarDimensionObject pillarDimensionObject)
            {
                DimensionPillar activePillar = pillarDimensionObject.activePillar;
                if (activePillar != null)
                {
                    activePillar.curDimension = pillarDimensionObject.Dimension;
                    activePillar.dimensionWall.UpdateStateForCamera(SuperspectiveScreen.instance.playerCamera);
                }
            }

            TriggerEventsAfterTeleport(player.GetComponent <Collider>());
            DisableVolumetricPortal();
            otherPortal.EnableVolumetricPortal();
            yield return(null);

            teleportingPlayer = false;
        }
Exemplo n.º 8
0
 void Start()
 {
     pillar = GetComponent <DimensionPillar>();
 }
 void TeardownEventListeners(DimensionPillar pillar)
 {
     pillar.OnDimensionChange        -= HandlePillarDimensionChange;
     pillar.OnPlayerMoveAroundPillar -= HandlePlayerMoveAroundPillar;
 }
 void SetupEventListeners(DimensionPillar pillar)
 {
     pillar.OnDimensionChange        += HandlePillarDimensionChange;
     pillar.OnPlayerMoveAroundPillar += HandlePlayerMoveAroundPillar;
 }
 private bool PillarIsRelevant(DimensionPillar pillar)
 {
     return((findPillarsTechnique == FindPillarsTechnique.anyPillar && pillar != null) || (pillarsFound.Contains(pillar)));
 }
Exemplo n.º 12
0
        RecursiveTextures RenderPortalDepth(int depth, Portal portal, Rect[] portalScreenBounds, string tree)
        {
            if (depth == MaxDepth || renderSteps >= MaxRenderSteps)
            {
                Debug.LogError($"At max depth or max render steps:\nDepth: {depth}/{MaxDepth}\nRenderSteps: {renderSteps}/{MaxRenderSteps}");
                return(null);
            }

            var index = renderSteps;

            renderSteps++;

            SetupPortalCameraForPortal(portal, portal.otherPortal, depth);

            CameraSettings modifiedCamSettings = new CameraSettings {
                camPosition         = portalCamera.transform.position,
                camRotation         = portalCamera.transform.rotation,
                camProjectionMatrix = portalCamera.projectionMatrix,
                edgeColors          = new EDColors(portalCameraEdgeDetection)
            };

            // Key == Visible Portal, Value == visible portal screen bounds
            Dictionary <Portal, Rect[]> visiblePortals = GetVisiblePortalsAndTheirScreenBounds(portal, portalScreenBounds);
            // Key == Visible Portal, Value == RecursiveTextures
            Dictionary <Portal, RecursiveTextures> visiblePortalTextures = new Dictionary <Portal, RecursiveTextures>();

            debug.Log($"Index (Depth): {index} ({depth})\nPortal:{portal.name}\nNumVisible:{visiblePortals.Count}\nPortalCamPos:{portalCamera.transform.position}\nTree:{tree}\nScreenBounds:{string.Join(", ", portalScreenBounds)}");

            foreach (var visiblePortalTuple in visiblePortals)
            {
                Portal visiblePortal = visiblePortalTuple.Key;

                if (ShouldRenderRecursively(depth, portal, visiblePortal))
                {
                    string nextTree           = tree + ", " + visiblePortal.name;
                    Rect[] visiblePortalRects = visiblePortalTuple.Value;
                    Rect[] nextPortalBounds   = IntersectionOfBounds(portalScreenBounds, visiblePortalRects);

                    // Remember state
                    visiblePortalTextures[visiblePortal] = RenderPortalDepth(depth + 1, visiblePortal, nextPortalBounds, nextTree);
                }
                else
                {
                    visiblePortal.DefaultMaterial();
                }

                // RESTORE STATE
                SetCameraSettings(portalCamera, modifiedCamSettings);
            }

            // RESTORE STATE
            foreach (var visiblePortalKeyVal in visiblePortals)
            {
                Portal visiblePortal = visiblePortalKeyVal.Key;

                if (ShouldRenderRecursively(depth, portal, visiblePortal))
                {
                    RecursiveTextures textures = visiblePortalTextures[visiblePortal];
                    // Restore the RenderTextures that were in use at this stage
                    visiblePortal.SetTexture(textures.mainTexture);
                    visiblePortal.SetDepthNormalsTexture(textures.depthNormalsTexture);
                }
                else
                {
                    visiblePortal.DefaultMaterial();
                }
            }
            SetCameraSettings(portalCamera, modifiedCamSettings);

            while (renderStepTextures.Count <= index)
            {
                renderStepTextures.Add(RecursiveTextures.CreateTextures($"VirtualPortalCamera_{index}"));
            }

            List <PillarDimensionObject> allRelevantPillarDimensionObjects = PillarDimensionObject.allPillarDimensionObjects
                                                                             .Where(dimensionObj => dimensionObj.IsVisibleFrom(portalCamera))
                                                                             .ToList();

            // Portals with PillarDimensionObjects are treated specially in that the effective pillar
            // dimension is set to the out portal's dimension before rendering
            PillarDimensionObject portalDimensionObj = (portal?.otherPortal?.dimensionObject is PillarDimensionObject pillarDimensionObject)
                                ? pillarDimensionObject
                                : null;
            DimensionPillar activePillar = portalDimensionObj?.activePillar;

            if (portalDimensionObj != null && activePillar != null)
            {
                activePillar.dimensionWall.UpdateStateForCamera(portalCamera);
                foreach (PillarDimensionObject dimensionObject in allRelevantPillarDimensionObjects)
                {
                    if (dimensionObject == portalDimensionObj)
                    {
                        continue;
                    }
                    dimensionObject.UpdateStateForCamera(portalCamera, portalDimensionObj.Dimension);
                }
            }

            // RENDER
            RenderDepthNormalsToPortal(portal, index);
            RenderVisibilityMaskTexture(portal, modifiedCamSettings);
            RenderPortalMaskTexture(modifiedCamSettings);
            if (DEBUG)
            {
                while (portalMaskTextures.Count <= index)
                {
                    portalMaskTextures.Add(new RenderTexture(SuperspectiveScreen.currentWidth, SuperspectiveScreen.currentHeight, 24, SuperspectiveScreen.instance.portalMaskCamera.targetTexture.format));
                }

                Graphics.CopyTexture(SuperspectiveScreen.instance.portalMaskCamera.targetTexture, portalMaskTextures[index]);
            }

            debug.Log($"Rendering: {index} to {portal.name}'s RenderTexture, depth: {depth}");
            portalCamera.targetTexture = renderStepTextures[index].mainTexture;

            portalCamera.Render();

            portal.SetTexture(renderStepTextures[index].mainTexture);

            // Restore previous DimensionObject state
            if (activePillar != null)
            {
                activePillar.dimensionWall.UpdateStateForCamera(mainCamera);
                foreach (PillarDimensionObject dimensionObject in allRelevantPillarDimensionObjects)
                {
                    if (dimensionObject == portalDimensionObj)
                    {
                        continue;
                    }
                    dimensionObject.UpdateStateForCamera(mainCamera, activePillar.curDimension);
                }
            }

            return(renderStepTextures[index]);
        }