forked from Tunkali/com.unity.xr.management
-
Notifications
You must be signed in to change notification settings - Fork 0
/
XRPackageInitializationSettings.cs
98 lines (82 loc) · 2.85 KB
/
XRPackageInitializationSettings.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime;
using UnityEngine;
using UnityEditor;
namespace UnityEditor.XR.Management
{
internal class XRPackageInitializationSettings : ScriptableObject
{
private static XRPackageInitializationSettings s_PackageSettings = null;
private static object s_Lock = new object();
internal static string s_ProjectSettingsAssetName = "XRPackageSettings.asset";
internal static string s_ProjectSettingsFolder = "../ProjectSettings";
internal static string s_ProjectSettingsPath;
internal static string s_PackageInitPath;
[SerializeField]
private List<string> m_Settings = new List<string>();
private XRPackageInitializationSettings(){ }
internal static XRPackageInitializationSettings Instance
{
get
{
if (s_PackageSettings == null)
{
lock(s_Lock)
{
if (s_PackageSettings == null)
{
s_PackageSettings = ScriptableObject.CreateInstance<XRPackageInitializationSettings>();
s_PackageSettings.LoadSettings();
}
}
}
return s_PackageSettings;
}
}
void InitPaths()
{
if (String.IsNullOrEmpty(s_ProjectSettingsPath)) s_ProjectSettingsPath = Path.Combine(Application.dataPath, s_ProjectSettingsFolder);
if (String.IsNullOrEmpty(s_PackageInitPath)) s_PackageInitPath = Path.Combine(s_ProjectSettingsPath, s_ProjectSettingsAssetName);
}
void OnEnable()
{
InitPaths();
}
internal void LoadSettings()
{
InitPaths();
if (File.Exists(s_PackageInitPath))
{
using (StreamReader sr = new StreamReader(s_PackageInitPath))
{
string settings = sr.ReadToEnd();
JsonUtility.FromJsonOverwrite(settings, this);
}
}
}
internal void SaveSettings()
{
InitPaths();
if (!Directory.Exists(s_ProjectSettingsPath))
Directory.CreateDirectory(s_ProjectSettingsPath);
using (StreamWriter sw = new StreamWriter(s_PackageInitPath))
{
string settings = JsonUtility.ToJson(this, true);
sw.Write(settings);
}
}
internal bool HasSettings(string key)
{
return m_Settings.Contains(key);
}
internal void AddSettings(string key)
{
if (!HasSettings(key))
m_Settings.Add(key);
}
}
}