Skip to content

Commit 3170c4c

Browse files
committed
refactor: safely convert to int; remove typo in readme
1 parent 9f7bbab commit 3170c4c

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,6 @@ Steps for trying out avatar creator sample can be found [here.](Documentation~/A
3434
A guide for customizing avatar creator can be found [here.](Documentation~/CustomizationGuide.md)
3535

3636
### Note
37-
- [*]Camera support is only provided for Windows and WebGL, using Unity’s webcam native API.
37+
- Camera support is only provided for Windows and WebGL, using Unity’s webcam native API.
3838
- Unity does not have a native file picker, so we have discontinued support for this feature.
3939
- To add support for file picker (for selfies) you have to implement it yourself

Samples~/AvatarCreatorSamples/AvatarCreatorWizard/Scripts/UI/SelectionScreens/AvatarCreatorSelection.cs

+21-4
Original file line numberDiff line numberDiff line change
@@ -201,15 +201,32 @@ private async Task LoadAvatarColors()
201201
{
202202
var startTime = Time.time;
203203
var colors = await avatarManager.LoadAvatarColors();
204-
205-
var colorAssetTypes = AssetFilterHelper.GetAssetTypesByFilter(AssetFilter.Color).ToHashSet();
206-
var equippedColors = AvatarCreatorData.AvatarProperties.Assets.Where(kvp => colorAssetTypes.Contains(kvp.Key))
207-
.ToDictionary(kvp => kvp.Key, kvp => Convert.ToInt32(kvp.Value));
204+
var equippedColors = GetEquippedColors();
208205

209206
assetButtonCreator.CreateColorUI(colors, UpdateAvatar, equippedColors);
210207
SDKLogger.Log(TAG, $"All colors loaded in {Time.time - startTime:F2}s");
211208
}
212209

210+
private Dictionary<AssetType, int> GetEquippedColors()
211+
{
212+
var colorAssetTypes = AssetFilterHelper.GetAssetTypesByFilter(AssetFilter.Color).ToHashSet();
213+
return AvatarCreatorData.AvatarProperties.Assets
214+
.Where(kvp => colorAssetTypes.Contains(kvp.Key))
215+
.ToDictionary(
216+
kvp => kvp.Key,
217+
kvp =>
218+
{
219+
try
220+
{
221+
return Convert.ToInt32(kvp.Value);
222+
}
223+
catch
224+
{
225+
return 0;
226+
}
227+
});
228+
}
229+
213230
private void CreateUI()
214231
{
215232
categoryUICreator.Setup();

0 commit comments

Comments
 (0)