Skip to content

Commit 33389cb

Browse files
committed
保存ファイルに関する挙動を変更して、軽くリファクタリングした。
1 parent 2811c50 commit 33389cb

25 files changed

+337
-567
lines changed

Assets/XmlStorage/Example/ExampleController.cs

+33-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,12 @@
1-
using UnityEngine;
1+
using System;
22
using System.Collections.Generic;
3-
using System;
3+
using System.Xml.Serialization;
4+
using UnityEngine;
45

56
namespace XmlStorage.Examples
67
{
8+
using Components;
9+
710
/// <summary>
811
/// サンプル用コントローラー
912
/// </summary>
@@ -24,6 +27,17 @@ public class Test1
2427
public List<float> list1 = new List<float>() {
2528
0.1f, 1.1f, 10.1f
2629
};
30+
31+
/// <summary>XmlIgnoreのテスト</summary>
32+
[XmlIgnore]
33+
public float ff = 1f;
34+
35+
36+
public void Log()
37+
{
38+
var s = " _ ";
39+
Debug.Log(this.integer + s + this.str + s + this.list1[0] + s + this.list1[1] + s + this.list1[2] + s + this.ff);
40+
}
2741
}
2842

2943
/// <summary>
@@ -35,6 +49,18 @@ public class Test2
3549
public Vector2 vec2 = new Vector2(1f, 2f);
3650
/// <summary><see cref="Vector3"/>型の保存テスト</summary>
3751
public Vector3 vec3 = new Vector3(1f, 2f, 3f);
52+
53+
/// <summary>XmlIgnoreのテスト</summary>
54+
[XmlIgnore]
55+
public Vector4 vec4 = new Vector4(1f, 2f, 3f, 4f);
56+
57+
58+
public void Log()
59+
{
60+
Debug.Log(this.vec2);
61+
Debug.Log(this.vec3);
62+
Debug.Log(this.vec4);
63+
}
3864
}
3965

4066
/// <summary>
@@ -45,6 +71,8 @@ public enum ExampleMode
4571
Set = 1, Get
4672
};
4773

74+
public static string SecondaryFolder = "";
75+
4876
/// <summary>
4977
/// 値をセットするかゲットするかの動作を選択
5078
/// </summary>
@@ -57,6 +85,9 @@ public enum ExampleMode
5785

5886
void Awake()
5987
{
88+
SecondaryFolder =
89+
Application.dataPath + Consts.Separator + Consts.BackDirectory + Consts.Separator + "Saves2" + Consts.Separator;
90+
6091
if(this.set == null)
6192
{
6293
this.set = GetComponentInChildren<SetExample>();

Assets/XmlStorage/Example/GetExample.cs

+74-100
Original file line numberDiff line numberDiff line change
@@ -15,140 +15,117 @@ public class GetExample : MonoBehaviour
1515
/// </summary>
1616
public void Execute()
1717
{
18-
Debug.Log(Storage.HasAggregation("Default"));
18+
/*
19+
* true
20+
* true
21+
* false
22+
*/
23+
Debug.Log(Storage.HasAggregation(Storage.DefaultAggregationName));
1924
Debug.Log(Storage.HasAggregation("Test1"));
2025
Debug.Log(Storage.HasAggregation("Test2"));
2126
Debug.Log("");
2227

23-
// 10
28+
/*
29+
* 10
30+
* 10
31+
* 15
32+
* 20
33+
* 1.12345
34+
*/
2435
Debug.Log(Storage.Get(typeof(SetExample), "SetExample", 0));
36+
Debug.Log(Storage.GetInt("integer1"));
37+
Debug.Log(Storage.GetInt("integer2"));
38+
Debug.Log(Storage.GetInt("integer3"));
39+
Debug.Log(Storage.GetFloat("float"));
40+
Debug.Log("");
2541
Debug.Log("");
2642

2743
/*
28-
* 1
29-
* 1.111
30-
* XmlStorage.Examples.ExampleController+Test
31-
* "TestString"
32-
* 0.1f
33-
* 10.1f
34-
*
35-
* 0
36-
* ""
37-
*
38-
* 0
39-
* "del_tes2"
40-
*
41-
42-
*
43-
* (0.1, 0.2)
44-
* (1.0, 2.0, 3.0)
45-
* (10.0, 20.0, 30.0)
46-
*
47-
* 111
48-
* 2018
49-
* 10
50-
*
51-
* "del_test2"
52-
* "address"
44+
* c:/......
45+
* Test2.xml
5346
*/
54-
Debug.Log("Default Aggregatpion");
47+
Storage.ChangeAggregation("Test1");
5548
Debug.Log("Directory Path : " + Storage.DirectoryPath);
56-
Debug.Log("File Name : " + Storage.FileName);
57-
this.GetData();
49+
Debug.Log("File Name : " + Storage.CurrentAggregation.FileName);
5850

5951
/*
60-
* 111
61-
* 1.111
62-
* XmlStorage.Examples.ExampleController+Test
63-
* "TestString"
64-
* 0.1f
65-
* 10.1f
66-
*
67-
* 0
68-
* ""
69-
*
70-
* 0
71-
* "del_tes2"
72-
*
73-
52+
* XmlStorage.Examples.ExampleController+Test1
53+
* 1 _ TestString _ 0.1 _ 1.1 _ 10.1 _ 1.0
54+
* XmlStorage.Examples.ExampleController+Test2
55+
* (1.0, 2.0)
56+
* (1.0, 2.0, 3.0)
57+
* (1.0, 2.0, 3.0, 4.0)
7458
*
7559
* (0.1, 0.2)
7660
* (1.0, 2.0, 3.0)
7761
* (10.0, 20.0, 30.0)
78-
*
79-
* 111
80-
* 2018
81-
* 10
82-
*
83-
* "del_test2"
84-
* "address"
8562
*/
86-
Debug.Log("Test2 Aggregation");
87-
Storage.ChangeAggregation("Test2");
88-
Debug.Log("Directory Path : " + Storage.DirectoryPath);
89-
Debug.Log("File Name : " + Storage.FileName);
90-
this.GetData();
91-
}
92-
93-
/// <summary>
94-
/// <see cref="Storage"/>から値を取得してログに出力する
95-
/// </summary>
96-
private void GetData()
97-
{
98-
Debug.Log(Storage.GetInt("integer", 0));
99-
Debug.Log(Storage.GetFloat("float", 0f));
63+
var test1 = Storage.Get<ExampleController.Test1>("test1");
64+
var test2 = Storage.Get<ExampleController.Test2>("test2");
65+
Debug.Log(test1);
66+
test1?.Log();
10067

101-
Debug.Log(Storage.Get(typeof(object), "obj_int", 0));
102-
Debug.Log(Storage.Get<object>("obj_int"));
103-
Debug.Log(Storage.Get(typeof(int), "obj_int", 0));
104-
Debug.Log(Storage.Get<int>("obj_int"));
68+
Debug.Log(test2);
69+
test2?.Log();
10570

10671
Debug.Log("");
72+
Debug.Log(Storage.Get<Vector2>("vec2"));
73+
Debug.Log(Storage.Get<Vector3>("vec3"));
74+
Debug.Log(Storage.Get<Quaternion>("qua").eulerAngles);
10775

108-
Debug.Log(Storage.Get<ExampleController.Test1>("Test1Class"));
109-
Debug.Log(Storage.Get<ExampleController.Test1>("Test1Class").str);
110-
Debug.Log(Storage.Get<ExampleController.Test1>("Test1Class").list1.First());
111-
Debug.Log(Storage.Get<ExampleController.Test1>("Test1Class").list1.Last());
112-
113-
Debug.Log(Storage.Get<ExampleController.Test2>("Test2Class", null));
114-
Debug.Log(Storage.Get<ExampleController.Test2>("Test2Class", null).vec2);
115-
Debug.Log(Storage.Get<ExampleController.Test2>("Test2Class", null).vec3);
11676

11777
Debug.Log("");
118-
119-
Debug.Log(Storage.GetInt("del_tes1"));
120-
Debug.Log(Storage.GetString("del_tes1"));
121-
12278
Debug.Log("");
79+
Storage.DirectoryPath = ExampleController.SecondaryFolder;
80+
Storage.Load();
12381

124-
Debug.Log(Storage.GetInt("del_tes2"));
125-
Debug.Log(Storage.GetString("del_tes2"));
82+
/*
83+
* c:/......
84+
* XmlStorage.xml
85+
*/
86+
Debug.Log("Directory Path : " + Storage.DirectoryPath);
87+
Debug.Log("File Name : " + Storage.CurrentAggregation.FileName);
12688

89+
/*
90+
* true
91+
* false
92+
*/
93+
Debug.Log(Storage.HasAggregation(Storage.DefaultAggregationName));
94+
Debug.Log(Storage.HasAggregation("Test1"));
12795
Debug.Log("");
12896

129-
Debug.Log(Storage.Get<string>("address"));
130-
131-
Debug.Log("");
97+
/*
98+
* 100
99+
* 10.12345
100+
* 0
101+
* ""
102+
* 0
103+
* "del_test2"
104+
*/
105+
Debug.Log(Storage.GetInt("integer"));
106+
Debug.Log(Storage.GetFloat("float"));
107+
Debug.Log(Storage.GetInt("del_test1"));
108+
Debug.Log(Storage.GetString("del_test1"));
109+
Debug.Log(Storage.GetInt("del_test2"));
110+
Debug.Log(Storage.GetString("del_test2"));
132111

133-
Debug.Log(Storage.Get("vec2", Vector2.zero));
134-
Debug.Log(Storage.Get("vec3", Vector3.zero));
135-
Debug.Log(Storage.Get("qua", Quaternion.identity).eulerAngles);
136112

137113
Debug.Log("");
114+
Debug.Log("");
115+
Storage.DirectoryPath = Storage.DefaultSaveDirectory;
116+
Storage.Load();
138117

139-
// List Example
140-
var intArr = Storage.GetInts();
141-
for(var i = 0; i < intArr.Length; i++)
118+
var ints = Storage.GetInts();
119+
for(var i = 0; i < ints.Length; i++)
142120
{
143-
Debug.Log(intArr[i]);
121+
Debug.Log(ints[i]);
144122
}
145-
146123
Debug.Log("");
147124

148-
var string_keys = Storage.GetKeys(typeof(string));
149-
for(var i = 0; i < string_keys.Length; i++)
125+
var keys = Storage.GetKeys(typeof(int));
126+
for(var i = 0; i < keys.Length; i++)
150127
{
151-
Debug.Log(string_keys[i]);
128+
Debug.Log(keys[i]);
152129
}
153130

154131
Debug.Log("");
@@ -158,9 +135,6 @@ private void GetData()
158135
{
159136
Debug.Log(types[i]);
160137
}
161-
162-
Debug.Log("");
163-
Debug.Log("");
164138
}
165139
}
166140
}
+29-34
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
using System.Collections.Generic;
22
using System.IO;
33
using UnityEngine;
4-
using UnityEngine.SceneManagement;
54

65
namespace XmlStorage.Examples
76
{
@@ -14,7 +13,6 @@ public class SetExample : MonoBehaviour
1413
/// <summary>インスタンスの保存テスト</summary>
1514
[SerializeField]
1615
private ExampleController.Test1 test1 = new ExampleController.Test1();
17-
1816
/// <summary>インスタンスの保存テスト</summary>
1917
private ExampleController.Test2 test2 = new ExampleController.Test2();
2018
/// <summary><see cref="Vector2"/>の保存テスト</summary>
@@ -30,48 +28,45 @@ public class SetExample : MonoBehaviour
3028
/// </summary>
3129
public void Execute()
3230
{
31+
this.test1.ff = 10f;
32+
this.test2.vec4 *= 10f;
33+
3334
Storage.Set(typeof(SetExample), "SetExample", 10);
34-
this.SetData(1);
35+
Storage.SetInt("integer1", 10);
36+
Storage.SetInt("integer2", 15);
37+
Storage.SetInt("integer3", 20);
38+
Storage.SetFloat("float", 1.12345f);
3539

36-
Storage.ChangeAggregation("Test2");
37-
Storage.FileName = "Test2";
38-
this.SetData(111);
40+
Storage.ChangeAggregation("Test1");
41+
Storage.CurrentAggregation.FileName = "Test1";
42+
Storage.Set("test1", this.test1);
43+
Storage.Set("test2", this.test2);
44+
Storage.Set("vec2", this.vec2);
45+
Storage.Set("vec3", this.vec3);
46+
Storage.Set("qua", this.quaternion);
3947

4048
Storage.Save();
41-
Debug.Log("Finish");
42-
}
4349

44-
/// <summary>
45-
/// <see cref="Storage"/>に値をセットする
46-
/// </summary>
47-
/// <param name="value"><see cref="int"/>型の保存テスト</param>
48-
private void SetData(int value)
49-
{
50-
Storage.SetInt("integer", value);
51-
Storage.SetFloat("float", 1.111f);
52-
53-
Storage.Set(typeof(object), "obj_int", 10);
50+
// Save to oher folder.
51+
Storage.DirectoryPath = ExampleController.SecondaryFolder;
52+
Storage.Load();
5453

55-
Storage.Set("Test1Class", this.test1);
56-
Storage.Set("Test2Class", this.test2);
54+
// meaninglessness.
55+
Storage.ChangeAggregation(Storage.DefaultAggregationName);
5756

58-
Storage.SetInt("del_tes1", 2);
59-
Storage.SetString("del_tes1", "del_tes1");
60-
Storage.DeleteKey("del_tes1");
57+
Storage.SetInt("integer", 100);
58+
Storage.SetFloat("float", 10.12345f);
6159

62-
Storage.SetInt("del_tes2", 5);
63-
Storage.SetString("del_tes2", "del_tes2");
64-
Storage.DeleteKey("del_tes2", typeof(int));
60+
Storage.SetInt("del_test1", 2);
61+
Storage.SetString("del_test1", "del_test1");
62+
Storage.DeleteKey("del_test1");
6563

66-
var address = "[email protected]";
67-
Storage.SetString("address", address);
68-
69-
Storage.Set("vec2", this.vec2);
70-
Storage.Set("vec3", this.vec3);
71-
Storage.Set("qua", this.quaternion);
64+
Storage.SetInt("del_test2", 5);
65+
Storage.SetString("del_test2", "del_test2");
66+
Storage.DeleteKey("del_test2", typeof(int));
7267

73-
Storage.SetInt("int1", 2018);
74-
Storage.SetInt("int2", 10);
68+
Storage.Save();
69+
Debug.Log("Finish");
7570
}
7671
}
7772
}
24 Bytes
Binary file not shown.

0 commit comments

Comments
 (0)