diff options
author | chai <215380520@qq.com> | 2023-05-16 08:50:55 +0800 |
---|---|---|
committer | chai <215380520@qq.com> | 2023-05-16 08:50:55 +0800 |
commit | 27df4282109a26a21aa042793c3136fbb5b81a98 (patch) | |
tree | fb20d2b3b6270430eaa32de9a0c88aa7ea5d8258 /WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs | |
parent | 85629d871b1cbf65e57c8e25b2145c0b77f7e353 (diff) |
*misc
Diffstat (limited to 'WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs')
-rw-r--r-- | WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs | 51 |
1 files changed, 51 insertions, 0 deletions
diff --git a/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs b/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs new file mode 100644 index 0000000..7e54840 --- /dev/null +++ b/WorldlineKeepers/Assets/Scripts/Tools/UniqueStringMap.cs @@ -0,0 +1,51 @@ +using System.Collections; +using System.Collections.Generic; +using UnityEngine; + +namespace WK.Tools +{ + + public class UniqueStringMap + { + private int m_Index = 1; + + private Dictionary<string, int/*ID*/> m_StringMap = new Dictionary<string, int>(); + + public int RegisterString(string str) + { + if(m_StringMap.ContainsKey(str)) + return m_StringMap[str]; + + int index = m_Index++; + m_StringMap.Add(str, index); + + return index; + } + + public int GetStringCode(string str) + { + if (!m_StringMap.ContainsKey(str)) + return 0; + return m_StringMap[str]; + } + + //public int GetOrAddStringCode(string str) + //{ + // if (!m_StringMap.ContainsKey(str)) + // { + // RegisterString(str); + // } + // return m_StringMap[str]; + //} + + public int this[string str] + { + get + { + return GetStringCode(str); + } + } + + } + +} |