Exemplo n.º 1
0
    // Late update so we know that player has already calculated their position
    void LateUpdate()
    {
        // Keep the Camera holder where the player is.
        this.transform.position = player.transform.position;

        // Check if we are allowing input
        float viewInput = Input.GetAxisRaw(StringConstants.Input.CameraView);

        if (player.IsInputEnabled() && player.IsCameraRotationEnabled() && Mathf.Abs(viewInput) > 0.15f) // A little buffer for numerical stability, otherwise camera will drift
        {
            Vector3 toCamera    = mainCamera.transform.position - player.transform.position;
            float   cameraAngle = Vector2.SignedAngle(new Vector2(toCamera.x, toCamera.z), Vector2.left);
            float   inputAngle  = rotateSpeed * -viewInput * Time.deltaTime;

            // Don't let them rotate past the max angular offset
            if (Mathf.Sign(inputAngle) != Mathf.Sign(cameraAngle) || Mathf.Abs(cameraAngle + inputAngle) <= rotationalDegrees)
            {
                this.transform.Rotate(Vector3.up, inputAngle);
            }


            /* -- Snap back to default with no input --
             * Not using this right now cuase I found it to make jumping difficult still
             * Quaternion currentRotation = this.transform.rotation;
             * this.transform.rotation = startingRotation;
             * this.transform.Rotate(Vector3.up, maxAngularOffset * -viewInput);
             * Quaternion targetRotation = this.transform.rotation;
             * this.transform.rotation = Quaternion.Lerp(currentRotation, targetRotation, rotateSpeed * Time.deltaTime);
             */
        }

        mainCamera.transform.LookAt(player.transform);
    }
Exemplo n.º 2
0
    /// <summary>
    /// Non physics based update
    /// </summary>
    private void Update()
    {
        float playerDistance = Vector3.Distance(this.transform.position, player.transform.position);

        // Check for pedestal activation
        if (Input.GetButtonDown(StringConstants.Input.ActivateButton) && playerDistance < activateDistance && player.IsInputEnabled())
        {
            // Async on this action so it happens after the flame enters the pedestal
            Action onPedestalLit = () =>
            {
                currentLevel++;
                emissionColorLerpTimes[currentLevel - 1] = emissionFadeTime;
                if (actAsCheckpoint)
                {
                    player.RecordCheckpoint(checkPoint.transform.position);
                }
                ActivatePedestal();
                audioController.GetComponent <AudioController>().PlayAudioClip(AudioController.AudioClips.fire5);
            };
            if (currentOrbitals < maxLevel && player.RequestLanternUse(orbitalTargets[currentOrbitals].position, onPedestalLit))
            {
                currentOrbitals++;
            }
        }

        // Check for pedestal deactivation
        if (Input.GetButtonDown(StringConstants.Input.DeactivateButton) && playerDistance < activateDistance && player.IsInputEnabled())
        {
            if (activated && player.RequestLanternAddition(orbitalTargets[currentLevel - 1].position))
            {
                currentLevel--;
                currentOrbitals--;
                emissionColorLerpTimes[currentLevel] = emissionFadeTime;
                if (actAsCheckpoint)
                {
                    player.RecordCheckpoint(checkPoint.transform.position);
                }
                if (currentLevel <= 0)
                {
                    DeactivatePedestal();
                    currentLevel = 0;
                    audioController.GetComponent <AudioController>().PlayAudioClip(AudioController.AudioClips.fire1);
                }
                else
                {
                    ActivatePedestal();
                }
            }
        }

        int i = 0;

        foreach (MeshRenderer emitter in emitters)
        {
            // Lerp to emissive color, if needed
            emissionColorLerpTimes[i] = Mathf.Max(emissionColorLerpTimes[i] - Time.deltaTime, 0.0f);
            Color deactiveEmissive = deactiveColor.color * deactivatedEmitterIntensity * deactivatedEmitterIntensity * Mathf.Sign(deactivatedEmitterIntensity);
            Color activeEmissive   = emissionColor * activatedEmitterIntensity * activatedEmitterIntensity * Mathf.Sign(activatedEmitterIntensity);
            if (i < currentLevel)
            {
                emitter.materials[1].SetVector("_Color", Color.Lerp(emissionColor, deactiveColor.color, emissionColorLerpTimes[i] / emissionFadeTime));
                emitter.materials[1].SetVector("_EmissionColor", Color.Lerp(activeEmissive, deactiveEmissive, emissionColorLerpTimes[i] / emissionFadeTime));
            }
            else
            {
                emitter.materials[1].SetVector("_Color", Color.Lerp(deactiveColor.color, emissionColor, emissionColorLerpTimes[i] / emissionFadeTime));
                emitter.materials[1].SetVector("_EmissionColor", Color.Lerp(deactiveEmissive, activeEmissive, emissionColorLerpTimes[i] / emissionFadeTime));
            }
            i++;
        }

        // If we are updating an emission intensity, we have to tell all materials that it touches
        // to re compute their global illumination. There is probably a better method to do this but
        // for now I think this is ok.
        foreach (MeshRenderer rend in renderersInEmission)
        {
            rend.UpdateGIMaterials();
        }

        if (currentLevel == maxLevel)
        {
            foreach (ParticleSystem particleSystem in flameParticleSystems)
            {
                if (particleSystem.isStopped)
                {
                    particleSystem.Play();
                }
            }
        }
        else
        {
            foreach (ParticleSystem particleSystem in flameParticleSystems)
            {
                if (particleSystem.isPlaying)
                {
                    particleSystem.Stop();
                }
            }
        }
    }