forked from Unity-Technologies/UnityCsReference
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSerializedStringTable.cs
More file actions
71 lines (61 loc) · 1.6 KB
/
Copy pathSerializedStringTable.cs
File metadata and controls
71 lines (61 loc) · 1.6 KB
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
// Unity C# reference source
// Copyright (c) Unity Technologies. For terms of use, see
// https://unity3d.com/legal/licenses/Unity_Reference_Only_License
using UnityEngine;
using System.Collections;
[System.Serializable]
internal class SerializedStringTable
{
[SerializeField] private string[] keys;
[SerializeField] private int[] values;
private Hashtable table;
public Hashtable hashtable { get { SanityCheck(); return table; } }
public int Length { get { SanityCheck(); return keys.Length; } }
private void SanityCheck()
{
if (keys == null)
{
keys = new string[0];
values = new int[0];
}
if (table == null)
{
table = new Hashtable();
for (int i = 0; i < keys.Length; i++) table[keys[i]] = values[i];
}
}
private void SynchArrays()
{
keys = new string[table.Count];
values = new int[table.Count];
table.Keys.CopyTo(keys, 0);
table.Values.CopyTo(values, 0);
}
public void Set(string key, int value)
{
SanityCheck();
table[key] = value;
SynchArrays();
}
public void Set(string key)
{
Set(key, 0);
}
public bool Contains(string key)
{
SanityCheck();
return table.Contains(key);
}
public int Get(string key)
{
SanityCheck();
if (!table.Contains(key)) return -1;
return (int)table[key];
}
public void Remove(string key)
{
SanityCheck();
if (table.Contains(key)) table.Remove(key);
SynchArrays();
}
}