diff --git a/Source/Editor/GUI/Timeline/Timeline.cs b/Source/Editor/GUI/Timeline/Timeline.cs index 81fe950b9..556c4dcdb 100644 --- a/Source/Editor/GUI/Timeline/Timeline.cs +++ b/Source/Editor/GUI/Timeline/Timeline.cs @@ -1288,10 +1288,7 @@ namespace FlaxEditor.GUI.Timeline public virtual void AddTrack(Track track, bool withUndo = true) { // Ensure name is unique - int idx = 1; - var name = track.Name; - while (!IsTrackNameValid(track.Name)) - track.Name = string.Format("{0} {1}", name, idx++); + track.Name = GetValidTrackName(track.Name); // Add it to the timeline _tracks.Add(track); @@ -1843,11 +1840,7 @@ namespace FlaxEditor.GUI.Timeline /// The track name. public string GetValidTrackName(string name) { - string newName = name; - int count = 0; - while (!IsTrackNameValid(newName)) - newName = string.Format("{0} {1}", name, count++); - return newName; + return Utilities.Utils.IncrementNameNumber(name, IsTrackNameValid); } /// diff --git a/Source/Editor/GUI/Timeline/Track.cs b/Source/Editor/GUI/Timeline/Track.cs index 929b213e4..ec2dd63d8 100644 --- a/Source/Editor/GUI/Timeline/Track.cs +++ b/Source/Editor/GUI/Timeline/Track.cs @@ -854,11 +854,9 @@ namespace FlaxEditor.GUI.Timeline /// The base name. public void Rename(string name) { - string newName = name; - int count = 0; - while (_timeline != null && !_timeline.IsTrackNameValid(newName)) - newName = string.Format("{0} {1}", name, count++); - OnRename(newName); + if (_timeline != null) + name = _timeline.GetValidTrackName(name); + OnRename(name); } ///