void SetupPoint(PlatformSection currentSection, PlatformPoint[] points, PlatformPoint point)
        {
            var _platformPoints = points.OrderBy(x => x.OrderId).ToArray();
            var orderId         = point.OrderId;

            if (_platformPoints[_platformPoints.Length - 1].OrderId == point.OrderId)
            {
                point.OrderId = _platformPoints[_platformPoints.Length - 1].OrderId + 1;
            }
            else
            {
                point.OrderId++;
                var pointsToUpdate = currentSection.platformPoints.Where(x => x.OrderId >= point.OrderId).OrderBy(x => x.OrderId).ToArray();
                for (var i = 0; i < pointsToUpdate.Length; i++)
                {
                    pointsToUpdate[i].OrderId++;
                    pointsToUpdate[i].name = "Point_" + pointsToUpdate[i].OrderId;
                }
            }

            point.name = "Point_" + point.OrderId;
            currentSection.platformPoints.Add(point);

            var all      = currentSection.transform.parent.GetComponentsInChildren <PlatformSection>();
            var sections = all.Where(x => x != currentSection).ToArray();

            foreach (var section in sections)
            {
                if (section.platformPoints.Count < currentSection.platformPoints.Count)
                {
                    section.AddPointAtOrderId(orderId, point.transform.localPosition);
                }
            }
        }
Beispiel #2
0
        //set up a newly added point with this section
        void SetupPoint(PlatformPoint[] points, PlatformPoint point)
        {
            var _platformPoints = points.OrderBy(x => x.OrderId).ToArray();

            //if the point was duplicated at the end of the sections point list, then just add one to its orderId
            if (_platformPoints[_platformPoints.Length - 1].OrderId == point.OrderId)
            {
                point.OrderId = _platformPoints[_platformPoints.Length - 1].OrderId + 1;
            }
            //otherwise, we need to add one to its orderId and update all points after it (note: this is when a point between two points is added)
            else
            {
                point.OrderId++;
                var pointsToUpdate = platformPoints.Where(x => x.OrderId >= point.OrderId).OrderBy(x => x.OrderId).ToArray();
                for (var i = 0; i < pointsToUpdate.Length; i++)
                {
                    pointsToUpdate[i].OrderId++;
                    pointsToUpdate[i].name = "Point_" + pointsToUpdate[i].OrderId;
                }
            }

            point.name = "Point_" + point.OrderId;
            platformPoints.Add(point);
        }