Skip to content

Commit 5bf1f6a

Browse files
Erik Bylundkirre-bylund
authored andcommitted
Handle when LL is added as asset at unknown path
1 parent afecc2a commit 5bf1f6a

File tree

1 file changed

+30
-6
lines changed

1 file changed

+30
-6
lines changed

Runtime/Game/Resources/LootLockerConfig.cs

Lines changed: 30 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -117,33 +117,57 @@ static void CreateConfigFile()
117117
[InitializeOnLoadMethod]
118118
static void StoreSDKVersion()
119119
{
120+
if ((!string.IsNullOrEmpty(LootLockerConfig.current.sdk_version) &&
121+
!LootLockerConfig.current.sdk_version.Equals("N/A")) || ListInstalledPackagesRequest != null)
122+
{
123+
return;
124+
}
120125
ListInstalledPackagesRequest = Client.List();
121-
EditorApplication.update += ListRequestProgress;
126+
EditorApplication.update += ListInstalledPackagesRequestProgress;
122127
}
123128

129+
[Serializable]
124130
private class LLPackageDescription
125131
{
126-
public string version;
132+
public string name { get; set; }
133+
public string version { get; set; }
127134
}
128135

129-
static void ListRequestProgress()
136+
static void ListInstalledPackagesRequestProgress()
130137
{
131138
if (ListInstalledPackagesRequest.IsCompleted)
132139
{
133-
EditorApplication.update -= ListRequestProgress;
140+
EditorApplication.update -= ListInstalledPackagesRequestProgress;
134141
foreach (var package in ListInstalledPackagesRequest.Result)
135142
{
136143
if (package.name.Equals("com.lootlocker.lootlockersdk"))
137144
{
138145
LootLockerConfig.current.sdk_version = package.version;
139-
break;
146+
return;
140147
}
141148
}
142149

143-
if (string.IsNullOrEmpty(LootLockerConfig.current.sdk_version))
150+
if (File.Exists("Assets/LootLockerSDK/package.json"))
144151
{
145152
LootLockerConfig.current.sdk_version = LootLockerJson.DeserializeObject<LLPackageDescription>(File.ReadAllText("Assets/LootLockerSDK/package.json")).version;
153+
return;
154+
}
155+
156+
157+
foreach (var assetPath in AssetDatabase.GetAllAssetPaths())
158+
{
159+
if (assetPath.EndsWith("package.json"))
160+
{
161+
var packageDescription = LootLockerJson.DeserializeObject<LLPackageDescription>(File.ReadAllText(assetPath));
162+
if (!string.IsNullOrEmpty(packageDescription.name) && packageDescription.name.Equals("com.lootlocker.lootlockersdk"))
163+
{
164+
LootLockerConfig.current.sdk_version = packageDescription.version;
165+
return;
166+
}
167+
}
146168
}
169+
170+
LootLockerConfig.current.sdk_version = "N/A";
147171
}
148172
}
149173
#endif

0 commit comments

Comments
 (0)