-
Notifications
You must be signed in to change notification settings - Fork 34
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SDK-454] feature/settings-handler-refactor (#124)
- refactored settings handler and separated classes
- Loading branch information
1 parent
eef533e
commit 25f78e0
Showing
13 changed files
with
110 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
using ReadyPlayerMe.Core.Data; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace ReadyPlayerMe.Core.Editor | ||
{ | ||
[InitializeOnLoad] | ||
public static class CoreSettingsLoader | ||
{ | ||
private const string PROJECT_RELATIVE_ASSET_PATH = "Assets/Ready Player Me/Resources/Settings/CoreSettings.asset"; | ||
private const string SETTINGS_SAVE_FOLDER = "Ready Player Me/Resources/Settings"; | ||
|
||
static CoreSettingsLoader() | ||
{ | ||
EnsureSettingsExist(); | ||
} | ||
|
||
public static void EnsureSettingsExist() | ||
{ | ||
if (CoreSettingsHandler.CoreSettings == null) | ||
{ | ||
CreateSettings(); | ||
} | ||
} | ||
|
||
private static void CreateSettings() | ||
{ | ||
DirectoryUtility.ValidateDirectory($"{Application.dataPath}/{SETTINGS_SAVE_FOLDER}"); | ||
var newSettings = ScriptableObject.CreateInstance<CoreSettings>(); | ||
AssetDatabase.CreateAsset(newSettings, PROJECT_RELATIVE_ASSET_PATH); | ||
AssetDatabase.SaveAssets(); | ||
AssetDatabase.Refresh(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
using UnityEditor; | ||
|
||
namespace ReadyPlayerMe.Core.Editor | ||
{ | ||
public static class CoreSettingsSetter | ||
{ | ||
public static void SetEnableAnalytics(bool isEnabled) | ||
{ | ||
CoreSettingsHandler.CoreSettings.EnableAnalytics = isEnabled; | ||
Save(); | ||
} | ||
|
||
public static void SetEnableLogging(bool isEnabled) | ||
{ | ||
CoreSettingsHandler.CoreSettings.EnableLogging = isEnabled; | ||
Save(); | ||
} | ||
|
||
public static void SaveSubDomain(string subDomain) | ||
{ | ||
if (string.IsNullOrEmpty(subDomain) || CoreSettingsHandler.CoreSettings.Subdomain == subDomain) return; | ||
CoreSettingsHandler.CoreSettings.Subdomain = subDomain; | ||
Save(); | ||
} | ||
|
||
public static void SaveAppId(string appId) | ||
{ | ||
CoreSettingsHandler.CoreSettings.AppId = appId; | ||
Save(); | ||
} | ||
|
||
public static void Save() | ||
{ | ||
EditorUtility.SetDirty(CoreSettingsHandler.CoreSettings); | ||
AssetDatabase.SaveAssets(); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,71 +1,30 @@ | ||
using ReadyPlayerMe.Core.Data; | ||
using UnityEditor; | ||
using UnityEngine; | ||
|
||
namespace ReadyPlayerMe.Core | ||
{ | ||
public static class CoreSettingsHandler | ||
{ | ||
private const string RESOURCE_PATH = "Settings/CoreSettings"; | ||
public const string PROJECT_RELATIVE_ASSET_PATH = "Assets/Ready Player Me/Resources/Settings/CoreSettings.asset"; | ||
private const string SETTINGS_SAVE_FOLDER = "Ready Player Me/Resources/Settings"; | ||
|
||
public static CoreSettings CoreSettings | ||
{ | ||
get | ||
{ | ||
if (coreSettings != null) return coreSettings; | ||
coreSettings = Resources.Load<CoreSettings>(RESOURCE_PATH); | ||
#if UNITY_EDITOR | ||
coreSettings = Load(); | ||
if (coreSettings == null) | ||
{ | ||
coreSettings = CreateSettings(); | ||
Debug.LogError("CoreSettings could not be loaded."); | ||
} | ||
#endif | ||
return coreSettings; | ||
} | ||
} | ||
|
||
private static CoreSettings coreSettings; | ||
|
||
#if UNITY_EDITOR | ||
public static void SaveSubDomain(string subDomain) | ||
{ | ||
if (string.IsNullOrEmpty(subDomain) || coreSettings.Subdomain == subDomain) return; | ||
coreSettings.Subdomain = subDomain; | ||
Save(); | ||
} | ||
|
||
public static void SaveAppId(string appId) | ||
{ | ||
coreSettings.AppId = appId; | ||
Save(); | ||
} | ||
|
||
public static void Save() | ||
{ | ||
EditorUtility.SetDirty(coreSettings); | ||
AssetDatabase.SaveAssets(); | ||
} | ||
|
||
public static void EnsureSettingsExist() | ||
{ | ||
coreSettings = Resources.Load<CoreSettings>(RESOURCE_PATH); | ||
if (coreSettings == null) | ||
{ | ||
coreSettings = CreateSettings(); | ||
} | ||
} | ||
|
||
private static CoreSettings CreateSettings() | ||
public static CoreSettings Load() | ||
{ | ||
DirectoryUtility.ValidateDirectory($"{Application.dataPath}/{SETTINGS_SAVE_FOLDER}"); | ||
var newSettings = ScriptableObject.CreateInstance<CoreSettings>(); | ||
AssetDatabase.CreateAsset(newSettings, PROJECT_RELATIVE_ASSET_PATH); | ||
AssetDatabase.SaveAssets(); | ||
AssetDatabase.Refresh(); | ||
return newSettings; | ||
return Resources.Load<CoreSettings>(RESOURCE_PATH); | ||
} | ||
#endif | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters