/// <summary> /// bubble sort optimize algorythme /// </summary> /// <returns>haschanged</returns> protected virtual bool BubbleSort(bool changeIndexAtEnd) { float currentPath = 0; if (_waypointList.index != -1) { currentPath = _waypointList.serializedProperty.GetArrayElementAtIndex(_waypointList.index).GetPropertie(nameof(PointsOnSplineExtension.Waypoint.PathPosition)).floatValue; } else { changeIndexAtEnd = false; } bool changed = false; for (int i = _waypointList.count - 1; i >= 1; i--) { bool sorted = true; for (int j = 0; j <= i - 1; j++) { if (_waypointList.serializedProperty.GetArrayElementAtIndex(j + 1).GetPropertie(nameof(PointsOnSplineExtension.Waypoint.PathPosition)).floatValue < _waypointList.serializedProperty.GetArrayElementAtIndex(j).GetPropertie(nameof(PointsOnSplineExtension.Waypoint.PathPosition)).floatValue) { _waypointList.Move(j + 1, j); sorted = false; changed = true; } } if (sorted) { break; } } if (changed) { if (changeIndexAtEnd) { for (int i = 0; i < _target.WaypointsCount; i++) { float indexPath = _waypointList.serializedProperty.GetArrayElementAtIndex(i).GetPropertie(nameof(PointsOnSplineExtension.Waypoint.PathPosition)).floatValue; if (indexPath == currentPath) { _waypointList.index = i; break; } } } RepairIndexWaypoints(); this.ApplyModification(); } _timerBeforeSort.Reset(); return(changed); }