Skip to content

Commit 085e117

Browse files
Merge pull request #16 from CoderGamester/develop
Release 0.8.0
2 parents 5cdab27 + 4b5f3ad commit 085e117

23 files changed

+868
-786
lines changed

CHANGELOG.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,22 @@ All notable changes to this package will be documented in this file.
44
The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
55
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html)
66

7+
## [0.8.0] - 2024-10-29
8+
9+
- Added new *PresenterDelayerBase*, *AnimationDelayer* and *TimeDelayer* to support presenters that open/close with a delay
10+
- Added new *DelayUiPresenter* to interact with *PresenterDelayerBase* implementations and allow presenters to open/close with a delay
11+
- Improved performance of *UiService*
12+
13+
***Changed**:
14+
- Removed *AnimatedUiPresenter*. Use the new *DelayUiPresenter* with one of the *PresenterDelayerBase* implementations
15+
- Removed *UiCloseActivePresenter* and *UiCloseActivePresenterData*. Use the new *DelayUiPresenter* with one of the *PresenterDelayerBase* implementations
16+
- Removed the dependency of *UiPresenter* from Canvas. Allowing different structures of UI Unity project hierarchy to work with the *UiService*
17+
- Removed all Get and Has methods from *IUiService*. Replaced with IReadOnlyDictionaries for all the collections being requested from the service
18+
- Changed all OpenUi methods to be async. This guarantees the expected behaviour that will always load the Ui first before opening
19+
- Changed all CloseUi methods to be synchronous. Closing an Ui will now always be atomic. To get the close delay, you can request directly from the *DelayUiPresenter*
20+
- Changed *IUiAssetLoader* to unify the prefab instantiation into a single call. This simplefies the method so the caller doesn't have to worry about synchronous or async behaviour
21+
- Changed the *UiConfig* to know contain the information of the *UiPresenter* if is loaded sync or async
22+
723
## [0.7.2] - 2021-05-09
824

925
**Fixed**:

Editor/NonDrawingViewEditor.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
// ReSharper disable once CheckNamespace
77

8-
namespace FirstLightEditor.UiService
8+
namespace GameLoversEditor.UiService
99
{
1010
/// <summary>
1111
/// <see cref="NonDrawingView"/> custom inspector

Editor/UiConfigsEditor.cs

Lines changed: 63 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -55,30 +55,31 @@ public abstract class UiConfigsEditor<TSet> : Editor
5555
private readonly List<string> _assetsPath = new List<string>();
5656
private readonly List<string> _uiConfigsType = new List<string>();
5757
private readonly List<ReorderableList> _setsConfigsList = new List<ReorderableList>();
58-
private readonly GUIContent _uiConfigGuiContent = new GUIContent("Ui Config",
58+
private readonly GUIContent _uiConfigGuiContent = new GUIContent("Ui Config",
5959
"All the Addressable addresses for every UiPresenter in the game.\n" +
6060
"The second field is the layer where the UiPresenter should be shown. " +
6161
"The higher the value, the closer is the UiPresenter to the camera.\n" +
6262
"If the UiPresenter contains a Canvas in the root, the layer value is the same of the Canvas sorting order");
63-
private readonly GUIContent _uiSetConfigGuiContent = new GUIContent("Ui Set",
63+
private readonly GUIContent _uiSetConfigGuiContent = new GUIContent("Ui Set",
6464
"All the Ui Sets in the game.\n" +
6565
"A UiSet groups a list of UiConfigs and shows them all at the same time via the UiService.\n" +
6666
"The UiConfigs are all loaded in the order they are configured. Top = first; Bottom = Last");
67-
67+
6868
private string[] _uiConfigsAddress;
6969
private SerializedProperty _configsProperty;
7070
private SerializedProperty _setsProperty;
7171
private ReorderableList _configList;
7272
private ReorderableList _setList;
7373
private bool _resetValues;
74-
74+
private UiConfigs _scriptableObject;
75+
7576
private void OnEnable()
7677
{
7778
_resetValues = false;
78-
79+
7980
InitConfigValues();
8081
InitReorderableLists();
81-
82+
8283
_setList.drawHeaderCallback = rect => EditorGUI.LabelField(rect, $"Ui {nameof(UiConfigs.Sets)}");
8384
_setList.elementHeightCallback = index => _setsConfigsList[index].GetHeight();
8485
_setList.drawElementCallback = (rect, index, active, focused) => _setsConfigsList[index].DoList(rect);
@@ -90,14 +91,17 @@ private void OnEnable()
9091
public override void OnInspectorGUI()
9192
{
9293
serializedObject.Update();
93-
94+
95+
LoadingSpinnerLayout();
96+
97+
EditorGUILayout.Space();
9498
EditorGUILayout.HelpBox(_uiConfigGuiContent.tooltip, MessageType.Info);
9599
_configList.DoLayoutList();
96100
EditorGUILayout.LabelField("", GUI.skin.horizontalSlider);
97101
EditorGUILayout.Space();
98102
EditorGUILayout.HelpBox(_uiSetConfigGuiContent.tooltip, MessageType.Info);
99103
_setList.DoLayoutList();
100-
104+
101105
serializedObject.ApplyModifiedProperties();
102106

103107
if (_resetValues)
@@ -106,67 +110,94 @@ public override void OnInspectorGUI()
106110
}
107111
}
108112

113+
private void LoadingSpinnerLayout()
114+
{
115+
var uiPresentersNames = new List<string> { "<None>" };
116+
var uiPresentersAssemblyNames = new List<string> { "<None>" };
117+
118+
foreach (var uiConfig in _scriptableObject.Configs)
119+
{
120+
uiPresentersNames.Add(uiConfig.UiType.Name);
121+
uiPresentersAssemblyNames.Add(uiConfig.UiType.AssemblyQualifiedName);
122+
}
123+
124+
var selectedIndex = 0;
125+
if (_scriptableObject.LoadingSpinnerType != null)
126+
{
127+
selectedIndex = uiPresentersAssemblyNames.FindIndex(uiPresenterName =>
128+
_scriptableObject.LoadingSpinnerTypeString ==
129+
uiPresenterName);
130+
selectedIndex = Math.Max(selectedIndex, 0);
131+
}
132+
133+
selectedIndex = EditorGUILayout.Popup("Loading Spinner Presenter", selectedIndex, uiPresentersNames.ToArray());
134+
_scriptableObject.LoadingSpinnerTypeString =
135+
selectedIndex == 0 ? null : uiPresentersAssemblyNames[selectedIndex];
136+
}
137+
109138
private void InitConfigValues()
110139
{
111140
var assetList = GetAssetList();
112141
var gameObjectType = typeof(GameObject);
113142
var uiConfigsAddress = new List<string>();
114143
var configs = new List<UiConfig>();
115-
var scriptableObject = target as UiConfigs;
116-
144+
_scriptableObject = target as UiConfigs;
145+
117146
_uiConfigsType.Clear();
118147
_assetsPath.Clear();
119148

120-
if (scriptableObject == null)
149+
if (_scriptableObject == null)
121150
{
122151
throw new NullReferenceException($"The Object is not of type {nameof(UiConfigs)}");
123152
}
124153

125-
var configsCache = scriptableObject.Configs;
126-
154+
var configsCache = _scriptableObject.Configs;
155+
127156
for (int i = 0; i < assetList.Count; i++)
128157
{
129158
var assetAddress = assetList[i].address;
130-
159+
131160
if (AssetDatabase.GetMainAssetTypeAtPath(assetList[i].AssetPath) != gameObjectType)
132161
{
133162
continue;
134163
}
135-
164+
136165
var uiPresenter = AssetDatabase.LoadAssetAtPath<UiPresenter>(assetList[i].AssetPath);
137166

138167
if (uiPresenter == null)
139168
{
140169
continue;
141170
}
142-
171+
143172
_assetsPath.Add(assetList[i].AssetPath);
144173

145174
var canvas = uiPresenter.GetComponent<Canvas>();
146175
var indexMatch = configsCache.FindIndex(configCheck => configCheck.AddressableAddress == assetAddress);
176+
var type = uiPresenter.GetType();
147177
var config = new UiConfig
148178
{
149179
AddressableAddress = assetList[i].address,
150180
Layer = canvas == null ? 0 : canvas.sortingOrder,
151-
UiType = uiPresenter.GetType()
152-
181+
UiType = type,
182+
LoadSynchronously = Attribute.IsDefined(type, typeof(LoadSynchronouslyAttribute))
183+
153184
};
154-
185+
155186
if (indexMatch > -1)
156187
{
157188
uiConfigsAddress.Add(config.AddressableAddress);
158189
_uiConfigsType.Add(config.UiType.AssemblyQualifiedName);
159190

160191
config.Layer = canvas == null ? configsCache[indexMatch].Layer : config.Layer;
161192
}
162-
193+
163194
configs.Add(config);
164195
}
165196

166-
scriptableObject.Configs = configs;
197+
_scriptableObject.Configs = configs;
167198
_uiConfigsAddress = uiConfigsAddress.ToArray();
168199

169-
EditorUtility.SetDirty(scriptableObject);
200+
EditorUtility.SetDirty(_scriptableObject);
170201
AssetDatabase.SaveAssets();
171202
Resources.UnloadUnusedAssets();
172203
}
@@ -180,7 +211,7 @@ private void InitReorderableLists()
180211
{
181212
throw new NullReferenceException($"The Object is not of type {nameof(UiConfigs)}");
182213
}
183-
214+
184215
scriptableObject.SetSetsSize(Enum.GetNames(typeof(TSet)).Length);
185216

186217
_configsProperty = serializedObject.FindProperty("_configs");
@@ -191,7 +222,7 @@ private void InitReorderableLists()
191222
_setsConfigsList.Clear();
192223
_setsConfigsList.Capacity = enumNames.Length;
193224
_configList.onChangedCallback = reorderableList => _resetValues = true;
194-
225+
195226
for (int i = 0; i < enumNames.Length; i++)
196227
{
197228
var property = _setsProperty.GetArrayElementAtIndex(i).FindPropertyRelative($"{nameof(UiConfigs.UiSetConfigSerializable.UiConfigsType)}");
@@ -205,18 +236,18 @@ private void InitReorderableLists()
205236
var serializedProperty = property.GetArrayElementAtIndex(index);
206237
var typeIndex = string.IsNullOrEmpty(serializedProperty.stringValue) ?
207238
0 : _uiConfigsType.FindIndex(type => type == serializedProperty.stringValue);
208-
239+
209240
serializedProperty.stringValue = _uiConfigsType[EditorGUI.Popup(rect, typeIndex, _uiConfigsAddress)];
210241
};
211-
242+
212243
_setsConfigsList.Add(list);
213244
}
214245
}
215246

216247
private void DrawUiConfigElement(Rect rect, int index, bool isActive, bool isFocused)
217248
{
218249
const int layerRectWidth = 100;
219-
250+
220251
var addressRect = new Rect(rect.x, rect.y, rect.width - layerRectWidth - 5, rect.height);
221252
var layerRect = new Rect(addressRect.xMax + 5, rect.y, layerRectWidth, rect.height);
222253
var arrayElement = _configsProperty.GetArrayElementAtIndex(index);
@@ -233,14 +264,14 @@ private void DrawUiConfigElement(Rect rect, int index, bool isActive, bool isFoc
233264
{
234265
return;
235266
}
236-
267+
237268
layer.intValue = newLayer;
238-
269+
239270
var canvas = AssetDatabase.LoadAssetAtPath<GameObject>(_assetsPath[index]).GetComponent<Canvas>();
240271
if (canvas != null)
241272
{
242273
canvas.sortingOrder = newLayer;
243-
274+
244275
EditorUtility.SetDirty(canvas);
245276
AssetDatabase.SaveAssets();
246277
}
@@ -252,14 +283,14 @@ private static List<AddressableAssetEntry> GetAssetList()
252283
{
253284
var assetList = new List<AddressableAssetEntry>();
254285
var assetsSettings = AddressableAssetSettingsDefaultObject.Settings;
255-
286+
256287
foreach (var settingsGroup in assetsSettings.groups)
257288
{
258289
if (settingsGroup.ReadOnly)
259290
{
260291
continue;
261292
}
262-
293+
263294
settingsGroup.GatherAllAssets(assetList, true, true, true);
264295
}
265296

0 commit comments

Comments
 (0)