Skip to content

Commit b1056dd

Browse files
committedDec 31, 2019
AggregationNameとFileNameを編集可能とした
1 parent e19dc5b commit b1056dd

File tree

7 files changed

+70
-7
lines changed

7 files changed

+70
-7
lines changed
 

‎Assets/PrefsUGUI/Examples/PrefsUGUI.unity

+14
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ GameObject:
190190
- component: {fileID: 282840813}
191191
- component: {fileID: 282840811}
192192
- component: {fileID: 282840812}
193+
- component: {fileID: 282840815}
193194
m_Layer: 0
194195
m_Name: Main Camera
195196
m_TagString: MainCamera
@@ -401,3 +402,16 @@ Transform:
401402
m_Father: {fileID: 0}
402403
m_RootOrder: 0
403404
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
405+
--- !u!114 &282840815
406+
MonoBehaviour:
407+
m_ObjectHideFlags: 0
408+
m_CorrespondingSourceObject: {fileID: 0}
409+
m_PrefabInternal: {fileID: 0}
410+
m_GameObject: {fileID: 282840810}
411+
m_Enabled: 1
412+
m_EditorHideFlags: 0
413+
m_Script: {fileID: 11500000, guid: c3e47bcddd5f4864a83049bf8345ac55, type: 3}
414+
m_Name:
415+
m_EditorClassIdentifier:
416+
aggregationName: PrefsUGUI
417+
fileName: PrefsUGUI

‎Assets/PrefsUGUI/Examples/Scripts/Example.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,8 @@ public partial class Example : MonoBehaviour
3535

3636
private void Awake()
3737
{
38-
Debug.Log(Structs.HierarchyTest1.FullHierarchy);
39-
Debug.Log(Structs.HierarchyTest2Ex2.FullHierarchy);
38+
Debug.Log(HierarchyTest1.FullHierarchy);
39+
Debug.Log(HierarchyTest2Ex2.FullHierarchy);
4040

4141
this.test2.PrefsString.TopMargin = 50f;
4242
this.test2.PrefsString.BottomMargin = 50f;

‎Assets/PrefsUGUI/Scripts/Prefs.cs

+8-2
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,11 @@ public static partial class Prefs
2121

2222
/// <summary>Aggregation name for saving.</summary>
2323
/// <remarks>For defailts, refer to XmlStorage</remarks>
24-
public static string AggregationName => Application.productName;
24+
public static string AggregationName { get; private set; } = "";
2525
/// <summary>File name for saving.</summary>
26-
public static string FileName => Application.productName;
26+
public static string FileName { get; private set; } = "";
27+
//public static string AggregationName => Application.productName;
28+
//public static string FileName => Application.productName;
2729

2830
/// <summary>Reference to <see cref="PrefsGuis"/> component.</summary>
2931
private static PrefsGuis PrefsGuis = null;
@@ -62,6 +64,10 @@ private static void Initialize()
6264
PrefsGuis = UnityEngine.Object.Instantiate(prefab).GetComponent<PrefsGuis>();
6365
}
6466

67+
var parameters = UnityEngine.Object.FindObjectOfType<PrefsParameters>();
68+
AggregationName = parameters?.AggregationName ?? PrefsParameters.DefaultNameGetter();
69+
FileName = parameters?.FileName ?? PrefsParameters.DefaultNameGetter();
70+
6571
PrefsGuis.Initialize(() => Creators);
6672
}
6773

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

+3-3
Original file line numberDiff line numberDiff line change
@@ -54,9 +54,9 @@ public override void ResetDefaultValue()
5454
public override void Reload(bool withEvent = true)
5555
// 互換性のために古いセーブキーでもLOADだけはする.
5656
=> this.SetValueInternal(Storage.Get(
57-
(Storage.HasKey(this.SaveKey, typeof(ValType), AggregationName) == true ? this.SaveKey : this.OldSaveKey),
58-
this.DefaultValue, AggregationName), withEvent
59-
);
57+
(Storage.HasKey(this.SaveKey, typeof(ValType), AggregationName) == true ? this.SaveKey : this.OldSaveKey),
58+
this.DefaultValue, AggregationName), withEvent
59+
);
6060
//=> this.SetValueInternal(Storage.Get(this.SaveKey, this.defaultValue, AggregationName), withEvent);
6161

6262
protected virtual void SetValueInternal(ValType value, bool withEvent = true)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
5+
namespace PrefsUGUI
6+
{
7+
[AddComponentMenu("")]
8+
[DisallowMultipleComponent]
9+
public class PrefsParameters : MonoBehaviour
10+
{
11+
public static readonly Func<string> DefaultNameGetter = () => Application.productName;
12+
13+
public string AggregationName
14+
=> string.IsNullOrEmpty(this.aggregationName) == true ? DefaultNameGetter() : this.aggregationName;
15+
public string FileName
16+
=> string.IsNullOrEmpty(this.fileName) == true ? DefaultNameGetter() : this.fileName;
17+
18+
[SerializeField]
19+
private string aggregationName = "";
20+
[SerializeField]
21+
private string fileName = "";
22+
23+
24+
private void Reset()
25+
{
26+
this.aggregationName = DefaultNameGetter();
27+
this.fileName = DefaultNameGetter();
28+
}
29+
}
30+
}

‎Assets/PrefsUGUI/Scripts/PrefsParameters.cs.meta

+11
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎README.md

+2
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ If you want to view more details, Let's check Example codes.
3737

3838
- A save key is generate by combine with full hierarchy path and SaveKey parameter.
3939

40+
- If you attached PrefsParameters component to any GameObject, you can edit AggregationName and FileName for change XmlStorage information that used by PrefsUGUI.
41+
4042
- I generate and use a dedicated Canvas.
4143
<br />
4244

0 commit comments

Comments
 (0)
Please sign in to comment.