예제 #1
0
        IEnumerator FallDown(GameObject o, float y0, SFXPlayParams sfx)
        {
            //logoStart.GetComponent<AudioSource>().Play();
            GlobalManager.MAudio.PlaySFX(fallingSFX);
            Vector3 v = o.transform.position;

            while (v.y > y0)
            {
                yield return(new WaitForFixedUpdate());

                v.y -= deltay;
                o.transform.position = v;
            }
            v.y = y0;
            o.transform.position = v;
            yield return(new WaitForFixedUpdate());

            //o.GetComponent<AudioSource>().Play();
            GlobalManager.MAudio.PlaySFX(sfx);
        }
        IEnumerator AnimatePress(float fastFactor)
        {
            if (!animating)
            {
                animating = true;
                Vector3 position    = transform.position;
                float   currentTime = 0;
                // press the button
                float phaseTime = pressTime * fastFactor;
                while (currentTime < phaseTime)
                {
                    yield return(null);

                    currentTime       += Time.deltaTime;
                    position.z         = MoveWithin(currentTime / phaseTime, neutralZ, pressedZ);
                    transform.position = position;
                }
                position.z         = pressedZ;
                transform.position = position;
                currentTime       -= phaseTime;
                // release the button
                phaseTime = releaseTime * fastFactor;
                while (currentTime < phaseTime)
                {
                    yield return(null);

                    currentTime       += Time.deltaTime;
                    position.z         = MoveWithin(currentTime / phaseTime, pressedZ, releasedZ);
                    transform.position = position;
                }
                position.z         = releasedZ;
                transform.position = position;
                currentTime       -= phaseTime;
                // emit rotation sound
                SFXPlayParams sfxPlayParams = fastFactor > fastThreshold ? slowSFXParams : fastSFXParams;
                sfxPlayParams.pitchFactor = jinglePitchRange.Random;
                GlobalManager.MAudio.PlaySFX(sfxPlayParams);
                // rotate the button
                phaseTime = rotateTime * fastFactor;
                float rotationAngle = 0;
                while (currentTime < phaseTime)
                {
                    yield return(null);

                    currentTime += Time.deltaTime;
                    float deltaAngle = 90 * Time.deltaTime / phaseTime;
                    rotationAngle += deltaAngle;
                    transform.Rotate(Vector3.forward, deltaAngle, Space.Self);
                }
                rotationAngle -= 90;    // adjust the angle
                if (rotationAngle != 0)
                {
                    transform.Rotate(Vector3.forward, -rotationAngle, Space.Self);
                }
                currentTime -= phaseTime;
                // unpress the button
                phaseTime = backTime * fastFactor;
                while (currentTime < phaseTime)
                {
                    yield return(null);

                    currentTime       += Time.deltaTime;
                    position.z         = MoveWithin(currentTime / phaseTime, releasedZ, neutralZ);
                    transform.position = position;
                }
                position.z         = neutralZ;
                transform.position = position;
                animating          = false;
                //Debug.Log("Button " + buttonId.ToString() + " fully rotated, notifying");
                GlobalManager.MInstantMessage.DeliverMessage(InstantMessageType.PuzzleButtonRotated, this, buttonId);
            }
        }