Пример #1
0
    private bool BuildRing(Pool segmentPool)
    {
        if (segments <= segmentPool.CheckInventory())
        {
            segmentRadians = 2 * Mathf.PI / segments;
            bool lastSegmentSkipped = true;

            for (int i = 0; i < (segments - 1); i++)
            {
                if (Random.Range(0, 10) < 2 || i == 0)
                {
                    tempLineSegment = segmentPool.CheckOut();
                    tempLineSegment.transform.parent = transform;
                    tempLineSegment.transform.position = transform.position;
                    tempLineSegment.transform.rotation = Quaternion.identity;
                    tempLSC = tempLineSegment.GetComponent<LineSegmentController>();

                    //calculate tempPos1
                    if (lastSegmentSkipped)
                    {
                        tempPos1.x = radius * Mathf.Cos(i * segmentRadians);
                        tempPos1.y = radius * Mathf.Sin(i * segmentRadians);
                    }
                    else
                    {
                        tempPos1.x = tempPos3.x;
                        tempPos1.y = tempPos3.y;
                    }
                    //calculate tempPos3
                    tempPos3.x = radius * Mathf.Cos((i + 1) * segmentRadians);
                    tempPos3.y = radius * Mathf.Sin((i + 1) * segmentRadians);
                    //calculate tempPos2
                    tempPos2.x = (tempPos1.x + tempPos3.x) / 2;
                    tempPos2.y = (tempPos1.y + tempPos3.y) / 2;

                    tempLSC.SetPositions(tempPos1, tempPos2, tempPos3);
                    tempLSC.SetColors(segmentStartColor, segmentEndColor);
                    tempLSC.SetWidths(segmentStartWidth, segmentEndWidth);

                    lineSegments.Add(tempLineSegment);
                    lastSegmentSkipped = false;
                }
                else
                {
                    lastSegmentSkipped = true;
                }
            }
            return true;
        }
        else
        {
            return false;
        }
    }