Exemplo n.º 1
0
    // Update is called once per frame
    void Update()
    {
        var main = particleSystem.main;
        var db   = Mathf.InverseLerp(-64, 0, analyzer.GetDB());
        var band = analyzer.GetVisualScale(emitterYPosBand);

        main.startSpeed = db * speedFactor * band;
        float y = Mathf.Lerp(emitterYMin, emitterYMax, band);

        emitterTransform.position = new Vector3(emitterTransform.position.x, y, emitterTransform.position.z);
        particleSystem.Emit((int)(band * 500));
        var shape = particleSystem.shape;

        shape.arc = Mathf.Lerp(60, 360, db);
    }
Exemplo n.º 2
0
    void UpdateVisuals()
    {
        for (int i = 0; i < analyzer.numOfBands; i++)
        {
            float value        = analyzer.GetVisualScale(i);
            float decayedValue = analyzer.GetVisualScaleDecayed(i);
            bars[i].UpdateBar(value, decayedValue);
        }


        if (Input.GetMouseButtonDown(0))
        {
            //Vector3 mousePos = Camera.main.ScreenToWorldPoint(Input.mousePosition);
            //Vector2 mousePos2D = new Vector2(mousePos.x, mousePos.y);
            Ray        ray = Camera.main.ScreenPointToRay(Input.mousePosition);
            RaycastHit hit;
            if (Physics.Raycast(ray, out hit))
            {
                if (hit.collider != null && hit.collider.gameObject.tag == "knob")
                {
                    knobClicked          = true;
                    knobClickedTransform = hit.collider.gameObject.transform;
                    knobClickedTransform.gameObject.GetComponent <Renderer>().material.color = Color.red;
                }
            }
        }
        if (Input.GetMouseButtonUp(0))
        {
            if (knobClickedTransform != null)
            {
                knobClickedTransform.gameObject.GetComponent <Renderer>().material.color = Color.grey;
            }
            knobClicked          = false;
            knobClickedTransform = null;
        }
        if (Input.GetMouseButton(0))
        {
            if (knobClicked)
            {
                float   newYPosition = 0;
                Vector3 v3           = Input.mousePosition;
                v3.z         = (Camera.main.transform.position - knobClickedTransform.position).magnitude;
                v3           = Camera.main.ScreenToWorldPoint(v3);
                newYPosition = v3.y;
                float minYPos = barYScale / 2;
                float maxYPos = barYScale * 15 - barYScale / 2;
                newYPosition = Mathf.Clamp(newYPosition, minYPos, maxYPos);
                knobClickedTransform.position = new Vector3(knobClickedTransform.position.x, newYPosition,
                                                            knobClickedTransform.position.z);
                int          i     = knobClickedTransform.GetComponent <EqKnob>().id;
                Vector3      lrPos = new Vector3((i - analyzer.numOfBands / 2) * columnScale, newYPosition, -7f);
                LineRenderer lr    = GetComponent <LineRenderer>();
                lr.SetPosition(i, lrPos);

                if (filter)
                {
                    filter.dbGain[i] = Mathf.Lerp(-24f, 24f, (newYPosition - minYPos) / (maxYPos - minYPos));
                    filter.Reprogram();
                }
            }
        }
    }