Esempio n. 1
0
    public static Color HSVToRGB(HSVColor hsbColor)
    {
        float r = hsbColor.v;
        float g = hsbColor.v;
        float b = hsbColor.v;

        if (!WadeUtils.IsZero(hsbColor.s))
        {
            float max = hsbColor.v;
            float dif = hsbColor.v * hsbColor.s;
            float min = hsbColor.v - dif;

            float h = hsbColor.h * 360f;

            if (h < 60f)
            {
                r = max;
                g = h * dif / 60f + min;
                b = min;
            }
            else if (h < 120f)
            {
                r = -(h - 120f) * dif / 60f + min;
                g = max;
                b = min;
            }
            else if (h < 180f)
            {
                r = min;
                g = max;
                b = (h - 120f) * dif / 60f + min;
            }
            else if (h < 240f)
            {
                r = min;
                g = -(h - 240f) * dif / 60f + min;
                b = max;
            }
            else if (h < 300f)
            {
                r = (h - 240f) * dif / 60f + min;
                g = min;
                b = max;
            }
            else if (h <= 360f)
            {
                r = max;
                g = min;
                b = -(h - 360f) * dif / 60f + min;
            }
            else
            {
                r = 0f;
                g = 0f;
                b = 0f;
            }
        }

        return(new Color(Mathf.Clamp01(r), Mathf.Clamp01(g), Mathf.Clamp01(b), hsbColor.a));
    }
Esempio n. 2
0
    void FixedUpdate()
    {
        float horInput = _inputDevice.LeftStick.Vector.x;

        if (_inControl && !player.ballControl.isShooting)
        {
            if (Mathf.Abs(horInput) * rigidbody2D.velocity.x < _xSpeedRange.max)
            {
                if (!WadeUtils.IsZero(horInput))
                {
                    if (Mathf.Abs(rigidbody2D.velocity.x) < _xSpeedRange.min)
                    {
                        Vector2 currentVelocity = rigidbody2D.velocity;
                        currentVelocity.x    = _xSpeedRange.min * Mathf.Sign(horInput);
                        rigidbody2D.velocity = currentVelocity;
                    }

                    Vector3 spriteScale = _spriteTransform.localScale;
                    spriteScale.x = -Mathf.Sign(horInput);
                    _spriteTransform.localScale = spriteScale;

                    rigidbody2D.AddForce(Vector2.right * horInput * _moveSpeed);
                }
                else
                {
                    ComeToStop();
                }
            }
        }

        if (WadeUtils.IsZero(horInput) || player.ballControl.isShooting)
        {
            ComeToStop();
        }

        if (Mathf.Abs(rigidbody2D.velocity.x) > _xSpeedRange.max)
        {
            rigidbody2D.velocity = new Vector2(Mathf.Sign(rigidbody2D.velocity.x) * _xSpeedRange.max, rigidbody2D.velocity.y);
        }

        animator.SetFloat("moveSpeed", Mathf.Abs(rigidbody2D.velocity.x));
    }
Esempio n. 3
0
    void CalculateBranchMesh(List <PlantJoint> plantJoints)
    {
        float uvHeight = 0f;

        // Iterate through each of the plant joints
        for (int i = 0; i < plantJoints.Count; i++)
        {
            PlantJoint pj = plantJoints[i];
            uvHeight += _jointDropDistance;

            // If main branch current plantjoint is at 0f time, we've just added a new plantjoint
            // Don't draw the last set of triangles otherwise there will be Z-fighting
            if (pj == _mainBranchCurrentJoint && WadeUtils.IsZero(pj.timeAlive))
            {
                continue;
            }

            for (int j = 0; j < _vertsPerJoint; j++)
            {
                Vector3 jointUp             = Vector3.Cross(pj.forward, pj.right);
                float   percentAroundCircle = j / (float)_vertsPerJoint;

                Vector3 vertPos     = pj.position;
                Vector3 circleUp    = Mathf.Sin(percentAroundCircle * Mathf.PI * 2f) * jointUp;
                Vector3 circleRight = Mathf.Cos(percentAroundCircle * Mathf.PI * 2f) * pj.right;

                vertPos += circleUp * pj.scale;
                vertPos += circleRight * pj.scale;
                _vertices.Add(vertPos);

                Vector3 basicOffset = vertPos + circleUp + circleRight;
                Vector3 normal      = (basicOffset - pj.position).normalized;

                if (uvHeight > 0.5f)
                {
                    uvHeight = uvHeight % 0.5f;
                }

                _normals.Add(normal);
                _uv.Add(new Vector2((j + 1) / (float)_vertsPerJoint, uvHeight) * 0.5f);

                // Calculate tangent in a dumb way
                Vector3 tanPos = pj.position;
                if (j == 0)
                {
                    circleRight = Mathf.Cos(percentAroundCircle - 0.001f * Mathf.PI * 2f) * -pj.right;
                }
                else
                {
                    circleRight = Mathf.Cos(percentAroundCircle + 0.001f * Mathf.PI * 2f) * pj.right;
                }

                tanPos += circleRight;
                tanPos += circleUp;

                _tangents.Add(((Vector4)(tanPos - vertPos).normalized).SetW(1f));

                if (i != 0 && j != 0)
                {
                    int currentTri       = _vertices.Count - 1;
                    int prevTri          = currentTri - 1;              // Previous vert on same joint
                    int prevJointTri     = currentTri - _vertsPerJoint; // Same vert previous joint
                    int prevJointPrevTri = prevTri - _vertsPerJoint;    // Previous vert on previous joint

                    _triangles.Add(prevJointPrevTri);
                    _triangles.Add(currentTri);
                    _triangles.Add(prevTri);

                    _triangles.Add(prevJointPrevTri);
                    _triangles.Add(prevJointTri);
                    _triangles.Add(currentTri);

                    if (j == _vertsPerJoint - 1)
                    {
                        // Need to complete the cylinder!
                        // Treat each joints 0 verts as another new vert around the cylinder as before

                        // Jump prevs up to the current and prevJoints
                        prevTri          = currentTri;                // Previous vert on same joint
                        prevJointPrevTri = prevJointTri;              // Previous vert on previous joint

                        currentTri   = _vertices.Count - _vertsPerJoint;
                        prevJointTri = currentTri - _vertsPerJoint;                         // Same vert previous joint

                        _triangles.Add(prevJointPrevTri);
                        _triangles.Add(currentTri);
                        _triangles.Add(prevTri);

                        _triangles.Add(prevJointPrevTri);
                        _triangles.Add(prevJointTri);
                        _triangles.Add(currentTri);
                    }
                }
            }
        }
    }