示例#1
0
    private void Update()
    {
        // Rotate
        transform.Rotate(Vector3.up, rotateSpeed * Time.deltaTime);

        Vector3[] positionsForLineRenderer = new Vector3[m_LineRenderer.positionCount];

        // Iterate through grid points
        noiseOffset.x = 0f;
        for (int i = 0; i < gridWidth; i++)
        {
            noiseOffset.y = 0f;
            for (int j = 0; j < gridWidth; j++)
            {
                // Use perlin noise to give grid point a new target.
                Vector3 newPosition = gridPoints[i, j].position;
                newPosition.y             = currentNoiseValue;
                gridPoints[i, j].position = newPosition;

                //gridPoints[i, j].letter.transform.localPosition = gridPoints[i, j].position;

                // Move grid point towards its target
                //gridPoints[i, j].MoveTowardsTarget();

                // Update positions in line renderer.
                positionsForLineRenderer[i * gridWidth + j] = gridPoints[i, j].position;

                noiseOffset.y += noiseDetail.y;
            }

            noiseOffset.x += noiseDetail.x;
        }

        // Scramble line renderer connections.
        //System.Random random = new System.Random();
        //positionsForLineRenderer = positionsForLineRenderer.OrderBy(x => random.Next()).ToArray();
        m_LineRenderer.SetPositions(positionsForLineRenderer);

        if (Input.anyKeyDown)
        {
            ProcessWord(WordDataManager.GetDummyData());
        }

        // Iterate noise
        noiseTime += noiseSpeed * Time.deltaTime;

        // Move variables
        //rotateSpeed = rotateSpeed * 0.99f;
        if (rotateSpeed < 0)
        {
            rotateSpeed = 0;
        }
        targetScale = Mathf.Lerp(targetScale, 0f, 5f * Time.deltaTime);
        noiseScale  = Mathf.Lerp(noiseScale, targetScale, 20f * Time.deltaTime);

        /*
         * if (MicVolume.MicLoudness > maxLoudness) { maxLoudness = MicVolume.MicLoudness; }
         * Debug.Log("max vloudness: " + maxLoudness);
         */
        targetScale = MyMath.Map(MicVolume.MicLoudness, 0f, 0.055f, 1f, 400f);
    }
    private void Update()
    {
        cooldownTimer += Time.deltaTime;

        if (Input.GetKeyDown(KeyCode.Q))
        {
            ProcessWord(WordDataManager.GetDummyData());
        }

        // Rotate
        child.Rotate(Vector3.up, rotateSpeed * Time.deltaTime, Space.World);
        child.Rotate(rotationAxis, rotateSpeed * 0.2f * Time.deltaTime, Space.World);

        // Iterate through mesh vertices
        Vector3[] vertices = m_Mesh.vertices;
        noiseOffset.x = 0f;
        for (int i = 0; i < m_Mesh.vertices.Length; i++)
        {
            Vector3 newPosition = originalVertices[i];
            newPosition = child.TransformPoint(newPosition);

            noiseOffset.x = newPosition.x * noiseDetail.x;
            noiseOffset.y = newPosition.z * noiseDetail.y;

            Vector3 noiseDirection = Vector3.Normalize(transform.position - newPosition);
            newPosition += noiseDirection * currentNoiseValue;

            newPosition = child.InverseTransformPoint(newPosition);

            vertices[i] = newPosition;
        }

        m_Mesh.vertices = vertices;
        m_Mesh.RecalculateBounds();

        // Iterate noise
        noiseTime += noiseSpeed * Time.deltaTime;


        // Decrease Power
        powerDecreaseTimer += Time.deltaTime;
        if (powerDecreaseTimer >= powerDecreaseTime)
        {
            currentPower *= powerDecreaseFactor;
            bloomTimer    = 0f;
        }

        // See if we are blooming
        if (!blooming)
        {
            // Check to see if I should start to bloom
            if (!blooming && currentPower >= bloomThreshold * 0.9f)
            {
                bloomTimer += Time.deltaTime;
                if (bloomTimer >= bloomTime)
                {
                    blooming = true;
                }
            }

            else
            {
                bloomTimer = Mathf.Clamp(bloomTimer - Time.deltaTime, 0f, bloomTime);
            }

            currentPower = Mathf.Clamp(currentPower, 0f, bloomThreshold);

            rotateSpeed   = MyMath.Map(currentPower, 0, bloomThreshold, minRotateSpeed, maxRotateSpeed);
            noiseScale    = MyMath.Map(currentPower, 0, bloomThreshold, minNoiseScale, maxNoiseScale);
            materialAlpha = MyMath.Map(currentPower, 0, bloomThreshold, minAlpha, maxAlpha);
        }

        else if (blooming)
        {
            currentPower = Mathf.Clamp(currentPower, 0f, 1f);

            rotateSpeed   = MyMath.Map(currentPower, bloomThreshold, 1f, maxRotateSpeed, maxRotateSpeedBloom);
            noiseScale    = MyMath.Map(currentPower, bloomThreshold, 1f, maxNoiseScale, maxNoiseScaleBloom);
            materialAlpha = MyMath.Map(currentPower, bloomThreshold, 1f, maxAlpha, maxAlphaBloom);

            // See if we should stop blooming
            if (currentPower < bloomThreshold * 0.95f)
            {
                blooming = false;
            }
        }
    }