PersistentTrails.Utilities.makeUniqueTrackName C# (CSharp) Method

makeUniqueTrackName() public static method

public static makeUniqueTrackName ( string name, List &trackList, bool renaming ) : string
name string
trackList List
renaming bool
return string
        public static string makeUniqueTrackName(string name, ref List<Track> trackList, bool renaming)
        {
            int uniqueIndex = 1;
            string uniqueSuffix = "";
            //while (File.Exists(Utilities.TrackPath + name + "_" + uniqueIndex + ".trk"))
            //{
            //    ++uniqueIndex;
            //}
            while (!nameIsUnique(name + uniqueSuffix, ref trackList, renaming))
            {
                uniqueIndex++;
                uniqueSuffix = "_" + uniqueIndex;
            }
            return name + uniqueSuffix;
        }

Usage Example

        public void startNewTrack()
        {
            Debug.Log("Starting new Track");
            recording = true;


            //create new Track
            activeTrack = new Track(); //initializes with TrackName = activeVessel.Name

            CraftLoader.saveCraftToFile();

            activeTrack.TrackName = Utilities.makeUniqueTrackName(activeTrack.TrackName, ref allTracks, false);
            allTracks.Add(activeTrack);
            updateCurrentTrack();
        }
All Usage Examples Of PersistentTrails.Utilities::makeUniqueTrackName