Ejemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        //update position to follow camera
        if (cameraToFollow != null)
        {
            if (cameraPosOffset != null)
            {
                transform.position = cameraToFollow.transform.position + cameraPosOffset;
            }

//            if (cameraRotOffset != null)
//                transform.rotation = cameraToFollow.transform.rotation + cameraRotOffset;
        }

        if (fadingIn)
        {
            Vector2 newAlpha = interp.Update();

            rend.material.shader = Shader.Find("Standard");
            rend.material.SetColor("_Color", new Color(0, 0, 0, newAlpha.x));

            if (interp.complete)
            {
                fadingIn = false;
            }
        }
        else if (fadingOut)
        {
            Vector2 newAlpha = interp.Update();

            rend.material.shader = Shader.Find("Standard");
            rend.material.SetColor("_Color", new Color(0, 0, 0, newAlpha.x));

            if (interp.complete)
            {
                fadingOut = false;
            }
        }
        else if (triggerFadeOut)
        {
            // start fade out - TODO this is a 1d vector but i don't have Interpolar1D yet
            interp.Initialize(new Vector2(0f, 0f), new Vector2(1f, 0f), fadeOutTime);
            fadingOut = true;
        }
    }
Ejemplo n.º 2
0
    // Update is called once per frame
    void Update()
    {
        if (trigger)
        {
            trigger = false;

            if ((!onlyTrigerOnce) || (!everBeenTriggered))
            {
                active = true;

                animToStart.SetTrigger("TrigFlight");

                fadeOutInitialVolume1 = toFadeOut1.volume;
                fadeOutInitialVolume2 = toFadeOut2.volume;

                // TODO this is a 2d interp being used as two 1D interps
                interp.Initialize(new Vector2(0f, 1f), new Vector2(fadeInTargetVolume, 0f), fadeTime);
            }

            everBeenTriggered = true;
        }

        if (active)
        {
            Vector2 values = interp.Update();

            toFadeIn.volume   = values.x;
            toFadeOut1.volume = values.y * fadeOutInitialVolume1;
            toFadeOut2.volume = values.y * fadeOutInitialVolume2;

            if (interp.complete)
            {
                active = false;
            }
        }
    }
Ejemplo n.º 3
0
    // Update is called once per frame
    void Update()
    {
        if (!goingNow)
        {
            if (Time.time > nextStart)
            {
                StartFlyBy();
            }
        }
        else          // goingNow == true
        {
            if (interp.complete)
            {
                EndFlyBy();
            }
            else
            {
                Vector2 newPos   = interp.Update();
                Vector3 newPos3D = new Vector3(newPos.x, transform.position.y, newPos.y);

                transform.position = newPos3D;
            }
        }
    }
Ejemplo n.º 4
0
    void Update()
    {
        // if emerging isn't finished and you're not a manager, leave now
        if ((manager != this) && (!emergingComplete))
        {
            return;
        }

        // no glow rocks exist in the scene yet
        if ((manager == this) && (Time.time < timeBeforeEmerge))
        {
            return;
        }

        // kick off the emerge behavior
        if ((manager == this) && (Time.time >= timeBeforeEmerge) && (!emergingStarted))
        {
            emergingStarted = true;

            // TODO - this is a 2dinterpolator being used as a 1dinterpoolator
            interp_emerge.Initialize(new Vector2(0f, 0f), new Vector2(1f, 0f), emergeDuration);
            interp_emergeSfx.Initialize(new Vector2(0f, 0f), new Vector2(0.05f, 0f), emergeSfxDuration);           // hardcoded from vol 0 to vol 0.05

            // enable all glow rocks and turn on all glow rock's render and collider meshes (only)
            MeshRenderer myRend = GetComponent <MeshRenderer>();
            myRend.enabled = true;
            MeshCollider myCol = GetComponent <MeshCollider>();
            myCol.enabled = true;
            for (int i = 0; i < allRocks.Length; i++)
            {
                allRocks[i].gameObject.SetActive(true);
                MeshRenderer rend = allRocks[i].GetComponent <MeshRenderer>();
                rend.enabled = true;

                MeshCollider col = allRocks[i].GetComponent <MeshCollider>();
                col.enabled = true;
            }

            return;
        }

        // continue the emerge behavior
        if ((manager == this) && (emergingStarted) && (!emergingComplete))
        {
            // sfx first
            if (emergeSfx != null)
            {
                emergeSfx.volume = interp_emergeSfx.Update().x;
            }

            // scale all the glow rocks with the interpolator, up to their stored originalScale
            Vector2 vec         = interp_emerge.Update();
            float   newScaleMag = vec.x;

            for (int i = 0; i < allRocks.Length; i++)
            {
                Vector3 newScale = new Vector3(newScaleMag * allRocks[i].originalScale.x, newScaleMag * allRocks[i].originalScale.y, newScaleMag * allRocks[i].originalScale.z);
                allRocks[i].transform.localScale = newScale;
            }

            // manager too
            Vector3 myNewScale = new Vector3(newScaleMag * originalScale.x, newScaleMag * originalScale.y, newScaleMag * originalScale.z);
            transform.localScale = myNewScale;


            // check to see if emerging is complete yet
            if (interp_emerge.complete)
            {
                emergingComplete = true;
                TurnStuffOnOff(true);
                for (int i = 0; i < allRocks.Length; i++)
                {
                    allRocks[i].TurnStuffOnOff(true);
                }
            }

            return;
        }


        // if the code gets this far, the emerging process is complete
        if ((!emergingComplete) && ((Time.frameCount % 10) == 0))
        {
            Debug.LogError("emerging should be complete by now");
            if (manager == this)
            {
                Debug.Log("I AM the manager.");
            }
            else
            {
                Debug.Log("I am NOT the manager.");
            }
        }


        // LERP the sfx out.  this is crappy but whatever
        if ((manager == this) && (emergeSfx != null))
        {
            float percent = (Time.time - emergeDuration - timeBeforeEmerge) / (emergeSfxDuration);

            if (percent > 1f)
            {
                percent = 1f;
            }
            percent = 1 - percent;

            emergeSfx.volume = (0.05f * percent);
        }


        // put the light directly above the rock in world space, regardless of how the rock moves or rotates
        myLight.transform.position = transform.position + new Vector3(0f, myLightHeight, 0f);

        // if i'm the manager and it's time to do so, tell all the other rocks to stop auto-triggering after this next one
        if ((manager == this) && (Time.time > untriggerAllRocksTime))
        {
            allRocksTriggered = false;
            foreach (GlowRock rock in allRocks)
            {
                rock.autoTrigEnabled = false;
            }

            autoTrigEnabled = false; // manager too
        }


        // ignore new triggers if you're already in the glow behavior
        if ((triggered) && (glowStage != GlowStage.Inactive))
        {
            triggered = false;
        }


        if ((glowStage == GlowStage.Brighten) || (glowStage == GlowStage.Darken))
        {
            Vector2 newLight, newEmis;
            float   newColor;

            newLight = interp_light.Update();
            newEmis  = interp_emis.Update();
            newColor = newEmis.x;

            myRend.material.shader = Shader.Find("Standard");
            myRend.material.SetColor("_EmissionColor", new Color(newColor, newColor, newColor));
            myLight.intensity = newLight.x;

            if (interp_emis.complete && interp_light.complete)
            {
                if (glowStage == GlowStage.Brighten)
                {
                    glowStage        = GlowStage.Glowing;
                    glowingStartTime = Time.time;

                    // slam to max values
                    myRend.material.shader = Shader.Find("Standard");
                    myRend.material.SetColor("_EmissionColor", new Color(emisHigh, emisHigh, emisHigh));
                    myLight.intensity = lightIntensityHigh;
                }
                else
                {
                    glowStage = GlowStage.Inactive;

                    // slam to min values
                    myRend.material.shader = Shader.Find("Standard");
                    myRend.material.SetColor("_EmissionColor", new Color(emisLow, emisLow, emisLow));
                    myLight.intensity = lightIntensityLow;

                    if (autoTrigEnabled)
                    {
                        InitAutoTrigger();
                    }
                }
            }
        }         // end Brighten or Darken


        else if (glowStage == GlowStage.Glowing)
        {
            if ((Time.time - glowingStartTime) > glowDuration)
            {
                glowStage = GlowStage.Darken;

                interp_emis.Initialize(new Vector2(emisHigh, 0f), new Vector2(emisLow, 0f), darkenDuration);
                interp_light.Initialize(new Vector2(lightIntensityHigh, 0f), new Vector2(lightIntensityLow, 0f), darkenDuration);
            }
        }          // end Glowing


        else if (glowStage == GlowStage.Inactive)
        {
            if (triggered)
            {
                Trigger(false);
            }
            else if (autoTrigEnabled)
            {
                if (Time.time > nextAutoTrigger)
                {
                    Trigger(true);
                }
            }
        }         // end Inactive
    }