Skip to content

Commit

Permalink
AggregationNameとFileNameを編集可能とした
Browse files Browse the repository at this point in the history
  • Loading branch information
a3geek committed Dec 31, 2019
1 parent e19dc5b commit b1056dd
Show file tree
Hide file tree
Showing 7 changed files with 70 additions and 7 deletions.
14 changes: 14 additions & 0 deletions Assets/PrefsUGUI/Examples/PrefsUGUI.unity
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,7 @@ GameObject:
- component: {fileID: 282840813}
- component: {fileID: 282840811}
- component: {fileID: 282840812}
- component: {fileID: 282840815}
m_Layer: 0
m_Name: Main Camera
m_TagString: MainCamera
Expand Down Expand Up @@ -401,3 +402,16 @@ Transform:
m_Father: {fileID: 0}
m_RootOrder: 0
m_LocalEulerAnglesHint: {x: 0, y: 0, z: 0}
--- !u!114 &282840815
MonoBehaviour:
m_ObjectHideFlags: 0
m_CorrespondingSourceObject: {fileID: 0}
m_PrefabInternal: {fileID: 0}
m_GameObject: {fileID: 282840810}
m_Enabled: 1
m_EditorHideFlags: 0
m_Script: {fileID: 11500000, guid: c3e47bcddd5f4864a83049bf8345ac55, type: 3}
m_Name:
m_EditorClassIdentifier:
aggregationName: PrefsUGUI
fileName: PrefsUGUI
4 changes: 2 additions & 2 deletions Assets/PrefsUGUI/Examples/Scripts/Example.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public partial class Example : MonoBehaviour

private void Awake()
{
Debug.Log(Structs.HierarchyTest1.FullHierarchy);
Debug.Log(Structs.HierarchyTest2Ex2.FullHierarchy);
Debug.Log(HierarchyTest1.FullHierarchy);
Debug.Log(HierarchyTest2Ex2.FullHierarchy);

this.test2.PrefsString.TopMargin = 50f;
this.test2.PrefsString.BottomMargin = 50f;
Expand Down
10 changes: 8 additions & 2 deletions Assets/PrefsUGUI/Scripts/Prefs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,11 @@ public static partial class Prefs

/// <summary>Aggregation name for saving.</summary>
/// <remarks>For defailts, refer to XmlStorage</remarks>
public static string AggregationName => Application.productName;
public static string AggregationName { get; private set; } = "";
/// <summary>File name for saving.</summary>
public static string FileName => Application.productName;
public static string FileName { get; private set; } = "";
//public static string AggregationName => Application.productName;
//public static string FileName => Application.productName;

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

var parameters = UnityEngine.Object.FindObjectOfType<PrefsParameters>();
AggregationName = parameters?.AggregationName ?? PrefsParameters.DefaultNameGetter();
FileName = parameters?.FileName ?? PrefsParameters.DefaultNameGetter();

PrefsGuis.Initialize(() => Creators);
}

Expand Down
6 changes: 3 additions & 3 deletions Assets/PrefsUGUI/Scripts/Prefs/Abstracts/PrefsValueBase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,9 @@ public override void ResetDefaultValue()
public override void Reload(bool withEvent = true)
// 互換性のために古いセーブキーでもLOADだけはする.
=> this.SetValueInternal(Storage.Get(
(Storage.HasKey(this.SaveKey, typeof(ValType), AggregationName) == true ? this.SaveKey : this.OldSaveKey),
this.DefaultValue, AggregationName), withEvent
);
(Storage.HasKey(this.SaveKey, typeof(ValType), AggregationName) == true ? this.SaveKey : this.OldSaveKey),
this.DefaultValue, AggregationName), withEvent
);
//=> this.SetValueInternal(Storage.Get(this.SaveKey, this.defaultValue, AggregationName), withEvent);

protected virtual void SetValueInternal(ValType value, bool withEvent = true)
Expand Down
30 changes: 30 additions & 0 deletions Assets/PrefsUGUI/Scripts/PrefsParameters.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
using System;
using System.Collections.Generic;
using UnityEngine;

namespace PrefsUGUI
{
[AddComponentMenu("")]
[DisallowMultipleComponent]
public class PrefsParameters : MonoBehaviour
{
public static readonly Func<string> DefaultNameGetter = () => Application.productName;

public string AggregationName
=> string.IsNullOrEmpty(this.aggregationName) == true ? DefaultNameGetter() : this.aggregationName;
public string FileName
=> string.IsNullOrEmpty(this.fileName) == true ? DefaultNameGetter() : this.fileName;

[SerializeField]
private string aggregationName = "";
[SerializeField]
private string fileName = "";


private void Reset()
{
this.aggregationName = DefaultNameGetter();
this.fileName = DefaultNameGetter();
}
}
}
11 changes: 11 additions & 0 deletions Assets/PrefsUGUI/Scripts/PrefsParameters.cs.meta

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ If you want to view more details, Let's check Example codes.

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

- If you attached PrefsParameters component to any GameObject, you can edit AggregationName and FileName for change XmlStorage information that used by PrefsUGUI.

- I generate and use a dedicated Canvas.
<br />

Expand Down

0 comments on commit b1056dd

Please sign in to comment.