Exemple #1
0
        private SplinePoint[] ResizeLinkArray()
        {
            maxLinkCount = Mathf.Min(maxLinkCount, MAX_JOINT_COUNT);
            SplinePoint[] initialPositions = Spline.GetSpacedPointsReversed(linkSpacing);
            activeLinkCount = Mathf.Min(maxLinkCount, initialPositions.Length) - 1;
            int spawnJointCount = (canResize) ? maxLinkCount : initialPositions.Length;

            if (spawnJointCount <= 0 && links.Length > 0)
            {
                for (int i = 0; i < links.Length; i++)
                    links[i].Destroy();

                links = new Link[0];
                initialPositions = new SplinePoint[0];
            }
            else
            {
                if (links.Length != spawnJointCount)
                {
                    if (spawnJointCount > links.Length)
                    {
                        int tSize = links.Length;
                        System.Array.Resize(ref links, spawnJointCount);
                        for (int i = tSize; i < spawnJointCount; i++)
                        {
                            links[i] = new Link(new GameObject("Link_[" + i + "]"), i);
                            links[i].Parent = transform;
                        }
                    }
                    else if (spawnJointCount > 0)
                    {
                        //targetJointCount -= 1;
                        for (int i = links.Length - 1; i >= spawnJointCount; i--)
                            links[i].Destroy();

                        System.Array.Resize(ref links, spawnJointCount);
                    }
                }
            }

            return initialPositions;
        }