Skip to content

Commit 744d33f

Browse files
author
Miguel Cartier
committed
perf(ui-service): optimize collection types for better performance
fix(editor): ensure serialization updates before property binding refactor(editor): rename UI set enum values for clarity
1 parent ccf925e commit 744d33f

File tree

4 files changed

+26
-21
lines changed

4 files changed

+26
-21
lines changed

Editor/DefaultUiConfigsEditor.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ namespace GameLoversEditor.UiService
99
/// </summary>
1010
public enum DefaultUiSetId
1111
{
12-
None = 0,
12+
InitialLoading = 0,
1313
MainMenu = 1,
1414
Gameplay = 2,
1515
Settings = 3,
16-
Overlay = 4,
17-
Popup = 5
16+
Overlays = 4,
17+
Popups = 5
1818
}
1919

2020
/// <summary>

Editor/UiConfigsEditor.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,14 @@ private void OnEnable()
8181

8282
SyncConfigsWithAddressables();
8383

84-
_configsProperty = serializedObject.FindProperty("_configs");
85-
_setsProperty = serializedObject.FindProperty("_sets");
86-
8784
// Ensure sets array matches enum size
8885
_scriptableObject.SetSetsSize(Enum.GetNames(typeof(TSet)).Length);
86+
87+
// Update the serializedObject to reflect the changes
88+
serializedObject.Update();
89+
90+
_configsProperty = serializedObject.FindProperty("_configs");
91+
_setsProperty = serializedObject.FindProperty("_sets");
8992
}
9093

9194
/// <inheritdoc />

Runtime/UiConfigs.cs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Collections.Generic;
3+
using System.Linq;
34
using UnityEngine;
45

56
// ReSharper disable CheckNamespace
@@ -51,6 +52,8 @@ public List<UiConfig> Configs
5152
/// <param name="size">The new size of the list</param>
5253
public void SetSetsSize(int size)
5354
{
55+
var validAddresses = new HashSet<string>(_configs.Select(c => c.AddressableAddress));
56+
5457
if (size < _sets.Count)
5558
{
5659
_sets.RemoveRange(size, _sets.Count - size);
@@ -60,18 +63,8 @@ public void SetSetsSize(int size)
6063
{
6164
if (i < _sets.Count)
6265
{
63-
var cleanedConfigList = new List<string>(_sets[i].UiConfigsAddress.Count);
64-
65-
foreach (var address in _sets[i].UiConfigsAddress)
66-
{
67-
if (_configs.FindIndex(config => config.AddressableAddress == address) > -1)
68-
{
69-
cleanedConfigList.Add(address);
70-
}
71-
}
72-
7366
var set = _sets[i];
74-
set.UiConfigsAddress = cleanedConfigList;
67+
set.UiConfigsAddress.RemoveAll(address => !validAddresses.Contains(address));
7568
_sets[i] = set;
7669
continue;
7770
}

Runtime/UiSetConfig.cs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ namespace GameLovers.UiService
1313
public struct UiSetConfig
1414
{
1515
public int SetId;
16-
public IReadOnlyList<Type> UiConfigsType;
16+
public Type[] UiConfigsType;
1717
}
1818

1919
/// <summary>
@@ -27,19 +27,28 @@ public struct UiSetConfigSerializable
2727

2828
public static UiSetConfig ToUiSetConfig(UiSetConfigSerializable serializable, List<UiConfigs.UiConfigSerializable> configs)
2929
{
30-
var types = new List<Type>();
30+
var types = new Type[serializable.UiConfigsAddress.Count];
31+
var index = 0;
32+
3133
foreach (var address in serializable.UiConfigsAddress)
3234
{
3335
var config = configs.Find(c => c.AddressableAddress == address);
3436
if (!string.IsNullOrEmpty(config.UiType))
3537
{
36-
types.Add(Type.GetType(config.UiType));
38+
types[index++] = Type.GetType(config.UiType);
3739
}
3840
}
41+
42+
// Trim array if some addresses weren't found
43+
if (index < types.Length)
44+
{
45+
Array.Resize(ref types, index);
46+
}
47+
3948
return new UiSetConfig
4049
{
4150
SetId = serializable.SetId,
42-
UiConfigsType = types.AsReadOnly()
51+
UiConfigsType = types
4352
};
4453
}
4554

0 commit comments

Comments
 (0)