Skip to content

Commit 654894c

Browse files
Merge pull request #14 from CoderGamester/develop
Release 0.7.1
2 parents 12dbb62 + 0c846f9 commit 654894c

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

CHANGELOG.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ 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.7.1] - 2021-05-03
8+
9+
- Added the possibility for *SafeAreaHelpersView* to maintain the View in the same position if not placed outside of the safe area
10+
11+
**Fixed**:
12+
- Fixed the duplicated memory issue when loading the same *UiPresenter* multiple times at the same time before when of them is finished
13+
14+
715
## [0.7.0] - 2021-03-12
816

917
- Added *NonDrawingView* to have an Image without a renderer to not add additional draw calls.

Runtime/SafeAreaHelperView.cs

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ namespace FirstLight.UiService
1212
[RequireComponent(typeof(RectTransform))]
1313
public class SafeAreaHelperView : MonoBehaviour
1414
{
15-
private const float _floatTolerance = 0.01f;
16-
15+
[Tooltip("If true then will only shift the anchor when the pivot is out of the safe area. If inside the safe area" +
16+
"will remain in the same anchor position")]
17+
[SerializeField] private bool _checkAreaBounds = false;
1718
[SerializeField] private RectTransform _rectTransform;
18-
[SerializeField] private bool _ignoreWidth = true;
19+
[SerializeField] private bool _ignoreHeight = false;
20+
[SerializeField] private bool _ignoreWidth = false;
1921
[SerializeField] private bool _onUpdate = false;
2022
[SerializeField] private Vector2 _refResolution;
2123

@@ -69,10 +71,10 @@ internal void UpdatePositions()
6971
}
7072

7173
// Check if anchored to top or bottom
72-
if (Math.Abs(anchorMax.y - anchorMin.y) < _floatTolerance)
74+
if (!_ignoreHeight && Mathf.Approximately(anchorMax.y,anchorMin.y) && !CheckHeightAreaBounds(anchoredPosition))
7375
{
7476
// bottom
75-
if (anchorMax.y < _floatTolerance)
77+
if (anchorMax.y < Mathf.Epsilon)
7678
{
7779
anchoredPosition.y += (_safeArea.yMin - _resolution.yMin) * _refResolution.y / _resolution.height;
7880
}
@@ -83,10 +85,10 @@ internal void UpdatePositions()
8385
}
8486

8587
// Check if anchored to left or right
86-
if (!_ignoreWidth && Math.Abs(anchorMax.x - anchorMin.x) < _floatTolerance)
88+
if (!_ignoreWidth && Mathf.Approximately(anchorMax.x,anchorMin.x) && !CheckWidthAreaBounds(anchoredPosition))
8789
{
8890
// left
89-
if (anchorMax.x < _floatTolerance)
91+
if (anchorMax.x < Mathf.Epsilon)
9092
{
9193
anchoredPosition.x += (_safeArea.xMin - _resolution.xMin) * _refResolution.x / _resolution.width;
9294
}
@@ -98,6 +100,16 @@ internal void UpdatePositions()
98100

99101
_rectTransform.anchoredPosition = anchoredPosition;
100102
}
103+
104+
private bool CheckWidthAreaBounds(Vector2 anchoredPosition)
105+
{
106+
return _checkAreaBounds && anchoredPosition.x > _safeArea.xMin && anchoredPosition.x < _safeArea.xMax;
107+
}
108+
109+
private bool CheckHeightAreaBounds(Vector2 anchoredPosition)
110+
{
111+
return _checkAreaBounds && anchoredPosition.y > _safeArea.yMin && anchoredPosition.y < _safeArea.yMax;
112+
}
101113
}
102114

103115
#if UNITY_EDITOR

Runtime/UiService.cs

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,7 @@ public void Init(UiConfigs configs)
4141
}
4242
}
4343

44-
/// <summary>
45-
/// Adds the given <paramref name="layer"/> to be controlled by the <see cref="UiService"/>.
46-
/// Layers allow to group <see cref="UiPresenter"/> into the same canvas rendering order.
47-
/// </summary>
44+
/// <inheritdoc />
4845
public GameObject AddLayer(int layer)
4946
{
5047
for(int i = _layers.Count; i <= layer; i++)
@@ -145,8 +142,28 @@ public async Task<UiPresenter> LoadUiAsync(Type type, bool openAfter = false)
145142
throw new KeyNotFoundException($"The UiConfig of type {type} was not added to the service. Call {nameof(AddUiConfig)} first");
146143
}
147144

145+
if (HasUiPresenter(type))
146+
{
147+
var ui = GetUi(type);
148+
149+
ui.gameObject.SetActive(openAfter);
150+
151+
return ui;
152+
}
153+
148154
var layer = AddLayer(config.Layer);
149155
var gameObject = await _assetLoader.InstantiatePrefabAsync(config.AddressableAddress, layer.transform, false);
156+
157+
if (HasUiPresenter(type))
158+
{
159+
var ui = GetUi(type);
160+
161+
_assetLoader.UnloadAsset(gameObject);
162+
ui.gameObject.SetActive(openAfter);
163+
164+
return ui;
165+
}
166+
150167
var uiPresenter = gameObject.GetComponent<UiPresenter>();
151168

152169
gameObject.SetActive(false);

package.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{
22
"name": "com.gamelovers.uiservice",
33
"displayName": "UiService",
4-
"version": "0.7.0",
5-
"unity": "2020.1",
4+
"version": "0.7.1",
5+
"unity": "2020.3",
66
"description": "This package provides a service to help manage an Unity's, game UI.\nIt allows to open, close, load, unload and request any Ui Configured in the game.\nThe package provides a Ui Set that allows to group a set of Ui Presenters to help load, open and close multiple Uis at the same time.\n\nTo help configure the game's UI you need to create a UiConfigs Scriptable object by:\n- Right Click on the Project View > Create > ScriptableObjects > Configs > UiConfigs",
77
"dependencies": {
8-
"com.unity.addressables": "1.16.16"
8+
"com.unity.addressables": "1.17.17"
99
},
1010
"type": "library",
1111
"hideInEditor": false

0 commit comments

Comments
 (0)