summaryrefslogtreecommitdiff
path: root/Library/PackageCache/com.unity.timeline@1.2.13/Editor/Utilities/SequenceSelectorNameFormater.cs
blob: 654eecbcd12ce0432064495284bd4bda600d81fd (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using System;
using System.Collections.Generic;

namespace UnityEditor.Timeline
{
    // Class used for uniquely format names used in the GenericMenu. We can't add duplicate MenuItem in GenericMenu
    // so that's why we need to keep information about the text we want to uniquely format.
    class SequenceMenuNameFormater
    {
        Dictionary<int, int> m_UniqueItem = new Dictionary<int, int>();

        public string Format(string text)
        {
            var key = text.GetHashCode();
            var index = 0;

            if (m_UniqueItem.ContainsKey(key))
            {
                index = m_UniqueItem[key];
                index++;
                m_UniqueItem[key] = index;
            }
            else
            {
                m_UniqueItem.Add(key, index);
                return text;
            }

            return $"{text}{index}";
        }
    }
}