Exemplo n.º 1
0
        public void Init(int horizontalLinesCount, int verticalLinesCount, float distanceBetweenLines,
                         float animationSpeed = 1f, float delayScale = 1f)
        {
            if (verticalLinesCount > 1)
            {
                // Horizontal lines down Y axis
                for (var i = 0; i < horizontalLinesCount; i++)
                {
                    var gridLine = _itemPool.GetGridLine();
                    _gridLinesHorizontal.Add(gridLine);

                    var material = gridLine.GetComponent <Renderer>().material;
                    material.color = Colorizer.Alpha(material.color, 0f);

                    gridLine.transform.SetParent(transform);
                    gridLine.name = "GridLineHorizontal " + i;
                    gridLine.transform.localRotation = Quaternion.identity;

                    gridLine.transform.localPosition = new Vector3(
                        distanceBetweenLines * (verticalLinesCount - 1) / 2f,
                        i * distanceBetweenLines,
                        ZOffset
                        );

                    var scale = transform.localScale;
                    scale.Scale(new Vector3(
                                    distanceBetweenLines * (verticalLinesCount - 1) * _nodeWidth - _gridPointWidth,
                                    GridLineScale,
                                    GridLineScale
                                    ));
                    gridLine.transform.localScale = scale;

                    Appear(gridLine, animationSpeed, delayScale);
                    gridLine.GetComponent <GridTransit>().WaveIn(
                        i, horizontalLinesCount, Vector3.right, LeanTweenType.easeOutSine, animationSpeed, delayScale
                        );
                }
            }

            if (horizontalLinesCount > 1)
            {
                // Vertical lines across X axis
                for (var i = 0; i < verticalLinesCount; i++)
                {
                    var gridLine = _itemPool.GetGridLine();
                    _gridLinesVertical.Add(gridLine);

                    var material = gridLine.GetComponent <Renderer>().material;
                    material.color = Colorizer.Alpha(material.color, 0f);

                    gridLine.transform.SetParent(transform);
                    gridLine.name = "GridLineVertical " + i;
                    gridLine.transform.localRotation = Quaternion.identity;

                    gridLine.transform.localPosition = new Vector3(
                        i * distanceBetweenLines,
                        distanceBetweenLines * (horizontalLinesCount - 1) / 2f,
                        ZOffset
                        );

                    var scale = transform.localScale;
                    scale.Scale(new Vector3(
                                    GridLineScale,
                                    distanceBetweenLines * (horizontalLinesCount - 1) * _nodeWidth - _gridPointWidth,
                                    GridLineScale
                                    ));
                    gridLine.transform.localScale = scale;

                    Appear(gridLine, animationSpeed, delayScale);
                    gridLine.GetComponent <GridTransit>().WaveIn(
                        i, verticalLinesCount, Vector3.up, LeanTweenType.easeOutSine, animationSpeed, delayScale
                        );
                }
            }

            // Points at each cross section
            _gridPoints = new GameObject[horizontalLinesCount, verticalLinesCount];
            for (var i = 0; i < horizontalLinesCount; i++)
            {
                for (var j = 0; j < verticalLinesCount; j++)
                {
                    var gridPoint = Instantiate(GridPointPrefab);
                    _gridPoints[i, j] = gridPoint;

                    var material = gridPoint.GetComponent <Renderer>().material;
                    material.color = Colorizer.Alpha(material.color, 0f);

                    gridPoint.transform.SetParent(transform);
                    gridPoint.name = "GridPoint (" + i + "," + j + ")";
                    gridPoint.transform.localRotation = Quaternion.identity;

                    gridPoint.transform.localPosition = new Vector3(
                        j * distanceBetweenLines,
                        i * distanceBetweenLines,
                        ZOffset
                        );

                    gridPoint.transform.localScale = Vector3.one * GridPointScale;

                    Appear(gridPoint, animationSpeed, delayScale);
                    gridPoint.GetComponent <GridTransit>().WaveIn(
                        i + j, horizontalLinesCount * verticalLinesCount, Vector3.down, LeanTweenType.easeOutBack, animationSpeed, delayScale
                        );
                }
            }
        }