Skip to content

Commit e19dc5b

Browse files
committed
Update SaveKey generator.
1 parent 59dd51a commit e19dc5b

File tree

6 files changed

+115
-83
lines changed

6 files changed

+115
-83
lines changed

Assets/PrefsUGUI/Examples/Scripts/Example.cs

+3
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,9 @@ public partial class Example : MonoBehaviour
3535

3636
private void Awake()
3737
{
38+
Debug.Log(Structs.HierarchyTest1.FullHierarchy);
39+
Debug.Log(Structs.HierarchyTest2Ex2.FullHierarchy);
40+
3841
this.test2.PrefsString.TopMargin = 50f;
3942
this.test2.PrefsString.BottomMargin = 50f;
4043

Assets/PrefsUGUI/Scripts/GuiHierarchy.cs

+31-16
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
using System;
2+
using System.Collections;
23
using System.Collections.Generic;
4+
using System.Linq;
35
using UnityEngine;
46

57
namespace PrefsUGUI
@@ -24,22 +26,8 @@ public sealed class GuiHierarchy : IDisposable
2426
/// <summary>Parent in GUI.</summary>
2527
public GuiHierarchy Parent => this.parent;
2628
/// <summary>All Parents in GUI to the root.</summary>
27-
public List<GuiHierarchy> Parents
28-
{
29-
get
30-
{
31-
var parents = new List<GuiHierarchy>();
32-
var parent = this.Parent;
33-
34-
while(parent != null)
35-
{
36-
parents.Insert(0, parent);
37-
parent = parent.Parent;
38-
}
39-
40-
return parents;
41-
}
42-
}
29+
public IReadOnlyList<GuiHierarchy> Parents { get; }
30+
public string FullHierarchy { get; }
4331

4432
/// <summary>Hierarchy of GUI.</summary>
4533
[SerializeField]
@@ -76,6 +64,8 @@ public GuiHierarchy(string hierarchy, int[] sortOrders, GuiHierarchy parent = nu
7664
this.sortOrders = (sortOrders == null || sortOrders.Length <= 0) ? new int[] { DefaultSortOrder } : sortOrders;
7765

7866
this.hierarchy = (hierarchy.TrimEnd(HierarchySeparator) + HierarchySeparator).TrimStart(HierarchySeparator);
67+
this.Parents = this.GetParents();
68+
this.FullHierarchy = this.GetFullHierarchy();
7969
}
8070

8171
/// <summary>
@@ -94,5 +84,30 @@ public void Dispose()
9484
{
9585
RemoveGuiHierarchy(this);
9686
}
87+
88+
private List<GuiHierarchy> GetParents()
89+
{
90+
var parents = new List<GuiHierarchy>();
91+
var parent = this.Parent;
92+
93+
while(parent != null)
94+
{
95+
parents.Insert(0, parent);
96+
parent = parent.Parent;
97+
}
98+
99+
return parents;
100+
}
101+
102+
private string GetFullHierarchy()
103+
{
104+
var hierarchy = "";
105+
foreach(var parent in this.Parents)
106+
{
107+
hierarchy += parent.Hierarchy;
108+
}
109+
110+
return hierarchy + this.Hierarchy;
111+
}
97112
}
98113
}

Assets/PrefsUGUI/Scripts/Prefs/Abstracts/PrefsBase.cs

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ public abstract class PrefsBase : IDisposable
1212
{
1313
public virtual event Action OnValueChanged = delegate { };
1414

15-
public virtual string SaveKey => (this.GuiHierarchy == null ? "" : this.GuiHierarchy.Hierarchy) + this.key;
15+
public virtual string SaveKey => (this.GuiHierarchy == null ? "" : this.GuiHierarchy.FullHierarchy) + this.key;
1616
public virtual string Key => this.key;
1717
public virtual GuiHierarchy GuiHierarchy => this.hierarchy;
1818
public virtual string GuiLabel => this.guiLabel;
@@ -28,6 +28,8 @@ public abstract class PrefsBase : IDisposable
2828
[SerializeField]
2929
protected string guiLabel = "";
3030

31+
public virtual string OldSaveKey => (this.GuiHierarchy == null ? "" : this.GuiHierarchy.Hierarchy) + this.key;
32+
3133
protected GuiHierarchy hierarchy = null;
3234

3335

Assets/PrefsUGUI/Scripts/Prefs/Abstracts/PrefsValueBase.cs

+6-1
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,12 @@ public override void ResetDefaultValue()
5252
=> this.Set(this.DefaultValue);
5353

5454
public override void Reload(bool withEvent = true)
55-
=> this.SetValueInternal(Storage.Get(this.SaveKey, this.defaultValue, AggregationName), withEvent);
55+
// 互換性のために古いセーブキーでもLOADだけはする.
56+
=> this.SetValueInternal(Storage.Get(
57+
(Storage.HasKey(this.SaveKey, typeof(ValType), AggregationName) == true ? this.SaveKey : this.OldSaveKey),
58+
this.DefaultValue, AggregationName), withEvent
59+
);
60+
//=> this.SetValueInternal(Storage.Get(this.SaveKey, this.defaultValue, AggregationName), withEvent);
5661

5762
protected virtual void SetValueInternal(ValType value, bool withEvent = true)
5863
{

Assets/PrefsUGUI/Version.txt

+1-1
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
1.3.1
1+
2.0.0

README.md

+71-64
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,71 @@
1-
PrefsUGUI
2-
===
3-
4-
5-
## Description
6-
The library that auto creation GUI elements by doing variable declaration.
7-
8-
*Inspired by [fuqunaga/PrefsGUI](https://github.com/fuqunaga/PrefsGUI)*
9-
PrefsGUI is a so useful library. But, PrefsGUI is using the OnGUI system, So I have some problem by itself.
10-
- In high resolution display, GUI window is showing like so small.
11-
- OnGUI system don't have kind and useful visual.
12-
- I heard that OnGUI system to make a spike sometimes.
13-
- OnGUI system can't validate about input values.
14-
15-
By uGUI system, I can solve those problems like easy.
16-
17-
![PrefsUGUI](./Documents/PrefsUGUI.gif)
18-
19-
## Usage
20-
Sample code
21-
```` csharp
22-
using PrefsUGUI;
23-
24-
public class Example : MonoBehaviour
25-
{
26-
private PrefsVector2 vec2 = new PrefsVector2("vec2");
27-
}
28-
````
29-
If you want to view more details, Let's check Example codes.
30-
[Example codes](Assets/PrefsUGUI/Examples/)
31-
32-
## Behaviour
33-
- Using the [XmlStorage](https://github.com/a3geek/XmlStorage) library for saving and loading data.
34-
<br />
35-
36-
- I generate and use a dedicated Canvas.
37-
<br />
38-
39-
- You can move uGUI window by mouse moving.
40-
<br />
41-
42-
- If you pressed discard button, back values to last saved.
43-
<br />
44-
45-
## Implemented type
46-
- PrefsBool
47-
- PrefsButton
48-
- PrefsColor
49-
- PrefsColorSlider
50-
- PrefsEnum
51-
- PrefsFloat
52-
- PrefsFloatSlider
53-
- PrefsInt
54-
- PrefsIntSlider
55-
- PrefsString
56-
- PrefsVector2
57-
- PrefsVector2Int
58-
- PrefsVector3
59-
- PrefsVector3Int
60-
- PrefsVector4
61-
62-
## References
63-
[fuqunaga/PrefsGUI](https://github.com/fuqunaga/PrefsGUI)
64-
[XmlStorage](https://github.com/a3geek/XmlStorage)
1+
PrefsUGUI
2+
===
3+
4+
5+
## Description
6+
The library that auto creation GUI elements by doing variable declaration.
7+
8+
*Inspired by [fuqunaga/PrefsGUI](https://github.com/fuqunaga/PrefsGUI)*
9+
PrefsGUI is a so useful library. But, PrefsGUI is using the OnGUI system, So I have some problem by itself.
10+
- In high resolution display, GUI window is showing like so small.
11+
- OnGUI system don't have kind and useful visual.
12+
- I heard that OnGUI system to make a spike sometimes.
13+
- OnGUI system can't validate about input values.
14+
15+
By uGUI system, I can solve those problems like easy.
16+
17+
![PrefsUGUI](./Documents/PrefsUGUI.gif)
18+
19+
## Usage
20+
Sample code
21+
```` csharp
22+
using PrefsUGUI;
23+
24+
public class Example : MonoBehaviour
25+
{
26+
public IReadOnlyPrefs<float> value = new PrefsFloat("value", 10f); // Read Only Interface.
27+
28+
private PrefsVector2 vec2 = new PrefsVector2("vec2");
29+
}
30+
````
31+
If you want to view more details, Let's check Example codes.
32+
[Example codes](Assets/PrefsUGUI/Examples/)
33+
34+
## Behaviour
35+
- Using the [XmlStorage](https://github.com/a3geek/XmlStorage) library for saving and loading data.
36+
<br />
37+
38+
- A save key is generate by combine with full hierarchy path and SaveKey parameter.
39+
40+
- I generate and use a dedicated Canvas.
41+
<br />
42+
43+
- You can move uGUI window by mouse moving.
44+
<br />
45+
46+
- If you pressed discard button, back values to last saved.
47+
<br />
48+
49+
## Implemented type
50+
- PrefsBool
51+
- PrefsButton
52+
- PrefsColor
53+
- PrefsColorSlider
54+
- PrefsEnum
55+
- PrefsFloat
56+
- PrefsFloatSlider
57+
- PrefsImageLabel
58+
- PrefsInt
59+
- PrefsIntSlider
60+
- PrefsLabel
61+
- PrefsRect
62+
- PrefsString
63+
- PrefsVector2
64+
- PrefsVector2Int
65+
- PrefsVector3
66+
- PrefsVector3Int
67+
- PrefsVector4
68+
69+
## References
70+
[fuqunaga/PrefsGUI](https://github.com/fuqunaga/PrefsGUI)
71+
[XmlStorage](https://github.com/a3geek/XmlStorage)

0 commit comments

Comments
 (0)