Tanoda
GlobalTagManager.cs
Go to the documentation of this file.
1using System;
2using System.Collections;
3using System.Collections.Generic;
4using System.Text;
5using GILES;
6using UnityEngine;
7
8public class GlobalTagManager : pb_MonoBehaviourSingleton<GlobalTagManager>
9{
10 private readonly Dictionary<string, string> globalTags = new Dictionary<string, string>();
11
12 public void Save(string fileName, List<string> tags)
13 {
14 var alltag = "";
15 foreach (var tag1 in tags)
16 {
17 alltag += tag1 + "\n";
18 }
19 if (globalTags.ContainsKey(fileName))
20 {
21 globalTags[fileName] = alltag;
22 }
23 else
24 {
25 globalTags.Add(fileName, alltag);
26 }
27 }
28
29 public string[] GetTags(string fileName)
30 {
31 var retval = new string[0];
32 if (globalTags.ContainsKey(fileName))
33 {
34 retval = globalTags[fileName].Split('\n');
35 }
36 return retval;
37 }
38
39 public byte[] GetData()
40 {
41 var full = "";
42 foreach (var globalTag in globalTags)
43 {
44 full += Convert.ToBase64String(Encoding.UTF8.GetBytes(globalTag.Key)) + ";" +
45 Convert.ToBase64String(Encoding.UTF8.GetBytes(globalTag.Value)) + "\n";
46 }
47 return Encoding.UTF8.GetBytes(full);
48 }
49
50 public void LoadData(byte[] data)
51 {
52 globalTags.Clear();
53 var full = Encoding.UTF8.GetString(data);
54 var split = full.Split('\n');
55 foreach (var s in split)
56 {
57 if (string.IsNullOrEmpty(s))
58 continue;
59
60 var b64 = s.Split(';');
61 globalTags.Add(Encoding.UTF8.GetString(Convert.FromBase64String(b64[0])), Encoding.UTF8.GetString(Convert.FromBase64String(b64[1])));
62 }
63 }
64}
void Save(string fileName, List< string > tags)
void LoadData(byte[] data)
string[] GetTags(string fileName)