com.amanotes.gdk 0.2.75 → 0.2.78
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +48 -0
- package/Editor/AmaGDKEditor.cs +24 -15
- package/Editor/Extra/SDKVersionTracking.cs +29 -0
- package/Editor/Utils/GDKPackageInstaller.cs +116 -0
- package/Editor/Utils/GDKPackageInstaller.cs.meta +11 -0
- package/Extra/AmaGDKInstaller.unitypackage +0 -0
- package/Extra/AutoEventQC.unitypackage +0 -0
- package/{Runtime/GDKAudio/Plugins/iOS.meta → Extra/AutoEventQC.unitypackage.meta} +1 -2
- package/Extra/CheckDiskSpace.unitypackage +0 -0
- package/Extra/Consent.unitypackage +0 -0
- package/Extra/ForceUpdate.unitypackage +0 -0
- package/Extra/LegacyGDKUpdateHelper.unitypackage +0 -0
- package/Extra/PostProcessor.unitypackage +0 -0
- package/Packages/AmaGDKConfig.unitypackage +0 -0
- package/Packages/AmaGDKExample.unitypackage +0 -0
- package/Packages/AmaGDKTest.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.AdRevenue.AF6.14AndOlder.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.PurchaseConnector.unitypackage +0 -0
- package/Packages/AppsFlyerAdapter.unitypackage +0 -0
- package/Packages/FirebaseAnalyticsAdapter.unitypackage +0 -0
- package/Packages/FirebaseRemoteConfigAdapter.unitypackage +0 -0
- package/Packages/IronSourceAdapter.AdQuality.unitypackage +0 -0
- package/{Runtime/GDKAudio/Plugins/macOS.meta → Packages/IronSourceAdapter.AdQuality.unitypackage.meta} +1 -2
- package/Packages/IronSourceAdapter.unitypackage +0 -0
- package/Packages/MaxAdNetworkAdapter.unitypackage +0 -0
- package/Packages/RevenueCatAdapter.unitypackage +0 -0
- package/Packages/SqliteAnalyticsAdapter.unitypackage +0 -0
- package/Runtime/Ad/AdLogic.cs +52 -55
- package/Runtime/Ad/AdShowContext.cs +1 -1
- package/Runtime/AmaGDK.Adapters.cs +2 -2
- package/Runtime/AmaGDK.Analytics.cs +18 -15
- package/Runtime/AmaGDK.Consent.cs +3 -8
- package/Runtime/AmaGDK.Mono.cs +1 -1
- package/Runtime/AmaGDK.RemoteConfig.cs +12 -2
- package/Runtime/AmaGDK.UserProfile.cs +31 -23
- package/Runtime/AmaGDK.cs +140 -41
- package/Runtime/Core/GDKDebug.cs +12 -5
- package/Runtime/Core/GDKPrefabPool.cs +571 -0
- package/Runtime/Core/GDKPrefabPool.cs.meta +11 -0
- package/Runtime/Core/GDKRoutine.cs +48 -2
- package/Runtime/Internal/AmaGDK.Internal.cs +1 -1
- package/Runtime/Internal/AmaGDK.Utils.cs +38 -0
- package/Runtime/UI/ScrollView/Editor/GDKScrollViewEditor.cs +50 -0
- package/Runtime/UI/ScrollView/Editor/GDKScrollViewEditor.cs.meta +11 -0
- package/Runtime/{GDKAudio/Resources.meta → UI/ScrollView/Editor.meta} +1 -1
- package/Runtime/UI/ScrollView/GDKScrollView.cs +702 -0
- package/Runtime/UI/ScrollView/GDKScrollView.cs.meta +12 -0
- package/Runtime/UI/ScrollView.meta +9 -0
- package/Runtime/UI/ScrollableText/GDKScrollableText.cs +68 -0
- package/Runtime/UI/ScrollableText/GDKScrollableText.cs.meta +3 -0
- package/Runtime/UI/ScrollableText/GDKScrollableText.prefab +806 -0
- package/Runtime/UI/ScrollableText/GDKScrollableText.prefab.meta +7 -0
- package/Runtime/UI/ScrollableText.meta +3 -0
- package/Runtime/{GDKAudio/Plugins.meta → UI.meta} +1 -1
- package/Runtime/Utils/GDKUtils.cs +18 -0
- package/package.json +1 -1
- package/Packages/AppsFlyerAdapter.AdRevenue.unitypackage +0 -0
- package/Runtime/GDKAudio/GDKAudio.cs +0 -483
- package/Runtime/GDKAudio/GDKAudio.cs.meta +0 -3
- package/Runtime/GDKAudio/Plugins/Android/atensor-release.aar +0 -0
- package/Runtime/GDKAudio/Plugins/Android/atensor-release.aar.meta +0 -32
- package/Runtime/GDKAudio/Plugins/Android.meta +0 -3
- package/Runtime/GDKAudio/Plugins/iOS/libatensor.a +0 -0
- package/Runtime/GDKAudio/Plugins/iOS/libatensor.a.meta +0 -68
- package/Runtime/GDKAudio/Plugins/iOS/libcrypto.a +0 -0
- package/Runtime/GDKAudio/Plugins/iOS/libcrypto.a.meta +0 -68
- package/Runtime/GDKAudio/Plugins/iOS/libssl.a +0 -0
- package/Runtime/GDKAudio/Plugins/iOS/libssl.a.meta +0 -68
- package/Runtime/GDKAudio/Plugins/macOS/libatensor.dylib +0 -0
- package/Runtime/GDKAudio/Plugins/macOS/libatensor.dylib.meta +0 -81
- package/Runtime/GDKAudio/Resources/GDKAudioMixer.mixer +0 -133
- package/Runtime/GDKAudio/Resources/GDKAudioMixer.mixer.meta +0 -8
- package/Runtime/GDKAudio.meta +0 -3
- /package/Packages/{AppsFlyerAdapter.AdRevenue.unitypackage.meta → AppsFlyerAdapter.AdRevenue.AF6.14AndOlder.unitypackage.meta} +0 -0
|
@@ -0,0 +1,702 @@
|
|
|
1
|
+
using System;
|
|
2
|
+
using System.Collections;
|
|
3
|
+
using System.Collections.Generic;
|
|
4
|
+
using UnityEngine;
|
|
5
|
+
using UnityEngine.Serialization;
|
|
6
|
+
using UnityEngine.UI;
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
namespace Amanotes.Core.Internal
|
|
10
|
+
{
|
|
11
|
+
[RequireComponent(typeof(RectTransform))]
|
|
12
|
+
[DisallowMultipleComponent]
|
|
13
|
+
public class GDKScrollView : ScrollRect
|
|
14
|
+
{
|
|
15
|
+
public Vector2 defaultItemSize;
|
|
16
|
+
public RectTransform itemTemplate;
|
|
17
|
+
[SerializeField]
|
|
18
|
+
[FormerlySerializedAs("m_layoutType")]
|
|
19
|
+
protected ItemLayoutType layoutType = ItemLayoutType.Vertical;
|
|
20
|
+
|
|
21
|
+
private readonly List<ScrollItemWithRect> _managedItems = new List<ScrollItemWithRect>();
|
|
22
|
+
private readonly int[] _criticalItemIndex = new int[4];
|
|
23
|
+
|
|
24
|
+
private Action<int, RectTransform> _updateFunc;
|
|
25
|
+
private Func<int, Vector2> _itemSizeFunc;
|
|
26
|
+
private Func<int> _itemCountFunc;
|
|
27
|
+
private Func<int, RectTransform> _itemGetFunc;
|
|
28
|
+
private Action<RectTransform> _itemRecycleFunc;
|
|
29
|
+
|
|
30
|
+
private Rect _refRect;
|
|
31
|
+
private int _dataCount;
|
|
32
|
+
private bool _initialized;
|
|
33
|
+
private int _willUpdateData;
|
|
34
|
+
|
|
35
|
+
private readonly Vector3[] _viewWorldCorners = new Vector3[4];
|
|
36
|
+
private readonly Vector3[] _rectCorners = new Vector3[2];
|
|
37
|
+
private const int FLAG_SCROLL_DIRECTION = 1;
|
|
38
|
+
|
|
39
|
+
public enum ItemLayoutType
|
|
40
|
+
{
|
|
41
|
+
Vertical = 0b0001, // 0001
|
|
42
|
+
Horizontal = 0b0010, // 0010
|
|
43
|
+
VerticalThenHorizontal = 0b0100, // 0100
|
|
44
|
+
HorizontalThenVertical = 0b0101, // 0101
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
public virtual void SetUpdateFunc(Action<int, RectTransform> func)
|
|
48
|
+
{
|
|
49
|
+
_updateFunc = func;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
public virtual void SetItemSizeFunc(Func<int, Vector2> func)
|
|
53
|
+
{
|
|
54
|
+
_itemSizeFunc = func;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
public virtual void SetItemCountFunc(Func<int> func)
|
|
58
|
+
{
|
|
59
|
+
_itemCountFunc = func;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
private void SetItemGetAndRecycleFunc(Func<int, RectTransform> getFunc, Action<RectTransform> recycleFunc)
|
|
63
|
+
{
|
|
64
|
+
if (getFunc != null && recycleFunc != null)
|
|
65
|
+
{
|
|
66
|
+
_itemGetFunc = getFunc;
|
|
67
|
+
_itemRecycleFunc = recycleFunc;
|
|
68
|
+
}
|
|
69
|
+
else
|
|
70
|
+
{
|
|
71
|
+
_itemGetFunc = null;
|
|
72
|
+
_itemRecycleFunc = null;
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
public void ResetAllDelegates()
|
|
77
|
+
{
|
|
78
|
+
SetUpdateFunc(null);
|
|
79
|
+
SetItemSizeFunc(null);
|
|
80
|
+
SetItemCountFunc(null);
|
|
81
|
+
SetItemGetAndRecycleFunc(null, null);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
public void UpdateData(bool immediately = true)
|
|
85
|
+
{
|
|
86
|
+
if (immediately)
|
|
87
|
+
{
|
|
88
|
+
_willUpdateData |= 3; // 0011
|
|
89
|
+
InternalUpdateData();
|
|
90
|
+
}
|
|
91
|
+
else
|
|
92
|
+
{
|
|
93
|
+
if (_willUpdateData == 0 && IsActive())
|
|
94
|
+
{
|
|
95
|
+
StartCoroutine(DelayUpdateData());
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
_willUpdateData |= 3;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void UpdateDataIncrementally(bool immediately = true)
|
|
103
|
+
{
|
|
104
|
+
if (immediately)
|
|
105
|
+
{
|
|
106
|
+
_willUpdateData |= 1; // 0001
|
|
107
|
+
InternalUpdateData();
|
|
108
|
+
}
|
|
109
|
+
else
|
|
110
|
+
{
|
|
111
|
+
if (_willUpdateData == 0)
|
|
112
|
+
{
|
|
113
|
+
StartCoroutine(DelayUpdateData());
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
_willUpdateData |= 1;
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
public void ScrollTo(int index)
|
|
121
|
+
{
|
|
122
|
+
InternalScrollTo(index);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
protected override void OnEnable()
|
|
126
|
+
{
|
|
127
|
+
base.OnEnable();
|
|
128
|
+
if (_willUpdateData != 0)
|
|
129
|
+
{
|
|
130
|
+
StartCoroutine(DelayUpdateData());
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
protected virtual void InternalScrollTo(int index)
|
|
135
|
+
{
|
|
136
|
+
index = Mathf.Clamp(index, 0, _dataCount - 1);
|
|
137
|
+
EnsureItemRect(index);
|
|
138
|
+
Rect r = _managedItems[index].rect;
|
|
139
|
+
var dir = (int)layoutType & FLAG_SCROLL_DIRECTION;
|
|
140
|
+
if (dir == 1)
|
|
141
|
+
{
|
|
142
|
+
// vertical
|
|
143
|
+
var value = 1 - (-r.yMax / (content.sizeDelta.y - _refRect.height));
|
|
144
|
+
value = Mathf.Clamp01(value);
|
|
145
|
+
SetNormalizedPosition(value, 1);
|
|
146
|
+
}
|
|
147
|
+
else
|
|
148
|
+
{
|
|
149
|
+
// horizontal
|
|
150
|
+
var value = r.xMin / (content.sizeDelta.x - _refRect.width);
|
|
151
|
+
value = Mathf.Clamp01(value);
|
|
152
|
+
SetNormalizedPosition(value, 0);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
protected override void SetContentAnchoredPosition(Vector2 position)
|
|
157
|
+
{
|
|
158
|
+
base.SetContentAnchoredPosition(position);
|
|
159
|
+
|
|
160
|
+
if (_willUpdateData != 0)
|
|
161
|
+
{
|
|
162
|
+
return;
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
UpdateCriticalItems();
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
protected override void SetNormalizedPosition(float value, int axis)
|
|
169
|
+
{
|
|
170
|
+
base.SetNormalizedPosition(value, axis);
|
|
171
|
+
|
|
172
|
+
if (_willUpdateData != 0)
|
|
173
|
+
{
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
ResetCriticalItems();
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
private void EnsureItemRect(int index)
|
|
181
|
+
{
|
|
182
|
+
if (!_managedItems[index].rectDirty)
|
|
183
|
+
{
|
|
184
|
+
return;
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
var firstItem = _managedItems[0];
|
|
188
|
+
if (firstItem.rectDirty)
|
|
189
|
+
{
|
|
190
|
+
Vector2 firstSize = GetItemSize(0);
|
|
191
|
+
firstItem.rect = CreateWithLeftTopAndSize(Vector2.zero, firstSize);
|
|
192
|
+
firstItem.rectDirty = false;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
var nearestClean = 0;
|
|
196
|
+
for (var i = index; i >= 0; --i)
|
|
197
|
+
{
|
|
198
|
+
if (_managedItems[i].rectDirty)
|
|
199
|
+
continue;
|
|
200
|
+
nearestClean = i;
|
|
201
|
+
break;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
Rect nearestCleanRect = _managedItems[nearestClean].rect;
|
|
205
|
+
Vector2 curPos = GetLeftTop(nearestCleanRect);
|
|
206
|
+
Vector2 size = nearestCleanRect.size;
|
|
207
|
+
MovePos(ref curPos, size);
|
|
208
|
+
|
|
209
|
+
for (var i = nearestClean + 1; i <= index; i++)
|
|
210
|
+
{
|
|
211
|
+
size = GetItemSize(i);
|
|
212
|
+
_managedItems[i].rect = CreateWithLeftTopAndSize(curPos, size);
|
|
213
|
+
_managedItems[i].rectDirty = false;
|
|
214
|
+
MovePos(ref curPos, size);
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
var range = new Vector2(Mathf.Abs(curPos.x), Mathf.Abs(curPos.y));
|
|
218
|
+
switch (layoutType)
|
|
219
|
+
{
|
|
220
|
+
case ItemLayoutType.VerticalThenHorizontal:
|
|
221
|
+
range.x += size.x;
|
|
222
|
+
range.y = _refRect.height;
|
|
223
|
+
break;
|
|
224
|
+
case ItemLayoutType.HorizontalThenVertical:
|
|
225
|
+
range.x = _refRect.width;
|
|
226
|
+
if (curPos.x != 0)
|
|
227
|
+
{
|
|
228
|
+
range.y += size.y;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
break;
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
content.sizeDelta = range;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
protected override void OnDestroy()
|
|
238
|
+
{
|
|
239
|
+
GDKPrefabPool.DestroyPooled(itemTemplate);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
protected Rect GetItemLocalRect(int index)
|
|
243
|
+
{
|
|
244
|
+
if (index < 0 || index >= _dataCount)
|
|
245
|
+
return default;
|
|
246
|
+
EnsureItemRect(index);
|
|
247
|
+
return _managedItems[index].rect;
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
#if UNITY_EDITOR
|
|
252
|
+
protected override void OnValidate()
|
|
253
|
+
{
|
|
254
|
+
var dir = (int)layoutType & FLAG_SCROLL_DIRECTION;
|
|
255
|
+
if (dir == 1)
|
|
256
|
+
{
|
|
257
|
+
// vertical
|
|
258
|
+
if (horizontalScrollbar != null)
|
|
259
|
+
{
|
|
260
|
+
horizontalScrollbar.gameObject.SetActive(false);
|
|
261
|
+
horizontalScrollbar = null;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
else
|
|
265
|
+
{
|
|
266
|
+
// horizontal
|
|
267
|
+
if (verticalScrollbar != null)
|
|
268
|
+
{
|
|
269
|
+
verticalScrollbar.gameObject.SetActive(false);
|
|
270
|
+
verticalScrollbar = null;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
base.OnValidate();
|
|
275
|
+
}
|
|
276
|
+
#endif
|
|
277
|
+
|
|
278
|
+
private static Vector2 GetLeftTop(Rect rect)
|
|
279
|
+
{
|
|
280
|
+
Vector2 ret = rect.position;
|
|
281
|
+
ret.y += rect.size.y;
|
|
282
|
+
return ret;
|
|
283
|
+
}
|
|
284
|
+
|
|
285
|
+
private static Rect CreateWithLeftTopAndSize(Vector2 leftTop, Vector2 size)
|
|
286
|
+
{
|
|
287
|
+
Vector2 leftBottom = leftTop - new Vector2(0, size.y);
|
|
288
|
+
return new Rect(leftBottom, size);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
private IEnumerator DelayUpdateData()
|
|
292
|
+
{
|
|
293
|
+
yield return new WaitForEndOfFrame();
|
|
294
|
+
|
|
295
|
+
InternalUpdateData();
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
private void InternalUpdateData()
|
|
299
|
+
{
|
|
300
|
+
if (!IsActive())
|
|
301
|
+
{
|
|
302
|
+
_willUpdateData |= 3;
|
|
303
|
+
return;
|
|
304
|
+
}
|
|
305
|
+
|
|
306
|
+
if (!_initialized)
|
|
307
|
+
{
|
|
308
|
+
InitScrollView();
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
CheckDataCountChange();
|
|
312
|
+
|
|
313
|
+
ResetCriticalItems();
|
|
314
|
+
|
|
315
|
+
_willUpdateData = 0;
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
protected virtual void CheckDataCountChange()
|
|
319
|
+
{
|
|
320
|
+
var newDataCount = 0;
|
|
321
|
+
|
|
322
|
+
if (_itemCountFunc != null)
|
|
323
|
+
{
|
|
324
|
+
newDataCount = _itemCountFunc();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
var keepOldItems = (_willUpdateData & 2) == 0;
|
|
328
|
+
|
|
329
|
+
if (newDataCount != _managedItems.Count)
|
|
330
|
+
{
|
|
331
|
+
if (_managedItems.Count < newDataCount)
|
|
332
|
+
{
|
|
333
|
+
if (!keepOldItems)
|
|
334
|
+
{
|
|
335
|
+
foreach (var itemWithRect in _managedItems)
|
|
336
|
+
{
|
|
337
|
+
itemWithRect.rectDirty = true;
|
|
338
|
+
}
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
while (_managedItems.Count < newDataCount)
|
|
342
|
+
{
|
|
343
|
+
_managedItems.Add(new ScrollItemWithRect());
|
|
344
|
+
}
|
|
345
|
+
}
|
|
346
|
+
else
|
|
347
|
+
{
|
|
348
|
+
for (int i = 0, count = _managedItems.Count; i < count; ++i)
|
|
349
|
+
{
|
|
350
|
+
if (i < newDataCount)
|
|
351
|
+
{
|
|
352
|
+
if (!keepOldItems)
|
|
353
|
+
{
|
|
354
|
+
_managedItems[i].rectDirty = true;
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
if (i == newDataCount - 1)
|
|
358
|
+
{
|
|
359
|
+
_managedItems[i].rectDirty = true;
|
|
360
|
+
}
|
|
361
|
+
}
|
|
362
|
+
|
|
363
|
+
if (i < newDataCount) continue;
|
|
364
|
+
_managedItems[i].rectDirty = true;
|
|
365
|
+
if (_managedItems[i].item == null) continue;
|
|
366
|
+
RecycleOldItem(_managedItems[i].item);
|
|
367
|
+
_managedItems[i].item = null;
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
}
|
|
371
|
+
else
|
|
372
|
+
{
|
|
373
|
+
if (!keepOldItems)
|
|
374
|
+
{
|
|
375
|
+
for (int i = 0, count = _managedItems.Count; i < count; ++i)
|
|
376
|
+
{
|
|
377
|
+
_managedItems[i].rectDirty = true;
|
|
378
|
+
}
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
_dataCount = newDataCount;
|
|
383
|
+
}
|
|
384
|
+
|
|
385
|
+
private void ResetCriticalItems()
|
|
386
|
+
{
|
|
387
|
+
int firstIndex = -1, lastIndex = -1;
|
|
388
|
+
|
|
389
|
+
for (var i = 0; i < _dataCount; i++)
|
|
390
|
+
{
|
|
391
|
+
var hasItem = _managedItems[i].item != null;
|
|
392
|
+
var shouldShow = ShouldItemSeenAtIndex(i);
|
|
393
|
+
|
|
394
|
+
if (shouldShow)
|
|
395
|
+
{
|
|
396
|
+
if (firstIndex == -1)
|
|
397
|
+
{
|
|
398
|
+
firstIndex = i;
|
|
399
|
+
}
|
|
400
|
+
|
|
401
|
+
lastIndex = i;
|
|
402
|
+
}
|
|
403
|
+
|
|
404
|
+
if (hasItem && shouldShow)
|
|
405
|
+
{
|
|
406
|
+
SetDataForItemAtIndex(_managedItems[i].item, i);
|
|
407
|
+
continue;
|
|
408
|
+
}
|
|
409
|
+
|
|
410
|
+
if (hasItem == shouldShow)
|
|
411
|
+
{
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
if (hasItem)
|
|
416
|
+
{
|
|
417
|
+
RecycleOldItem(_managedItems[i].item);
|
|
418
|
+
_managedItems[i].item = null;
|
|
419
|
+
continue;
|
|
420
|
+
}
|
|
421
|
+
|
|
422
|
+
RectTransform item = GetNewItem(i);
|
|
423
|
+
OnGetItemForDataIndex(item, i);
|
|
424
|
+
_managedItems[i].item = item;
|
|
425
|
+
}
|
|
426
|
+
|
|
427
|
+
_criticalItemIndex[CriticalItemType.UpToHide] = firstIndex;
|
|
428
|
+
_criticalItemIndex[CriticalItemType.DownToHide] = lastIndex;
|
|
429
|
+
_criticalItemIndex[CriticalItemType.UpToShow] = Mathf.Max(firstIndex - 1, 0);
|
|
430
|
+
_criticalItemIndex[CriticalItemType.DownToShow] = Mathf.Min(lastIndex + 1, _dataCount - 1);
|
|
431
|
+
}
|
|
432
|
+
|
|
433
|
+
private RectTransform GetCriticalItem(int type)
|
|
434
|
+
{
|
|
435
|
+
var index = _criticalItemIndex[type];
|
|
436
|
+
if (index >= 0 && index < _dataCount)
|
|
437
|
+
{
|
|
438
|
+
return _managedItems[index].item;
|
|
439
|
+
}
|
|
440
|
+
|
|
441
|
+
return null;
|
|
442
|
+
}
|
|
443
|
+
|
|
444
|
+
private void UpdateCriticalItems()
|
|
445
|
+
{
|
|
446
|
+
var dirty = true;
|
|
447
|
+
|
|
448
|
+
while (dirty)
|
|
449
|
+
{
|
|
450
|
+
dirty = false;
|
|
451
|
+
|
|
452
|
+
for (int i = CriticalItemType.UpToHide; i <= CriticalItemType.DownToShow; i++)
|
|
453
|
+
{
|
|
454
|
+
if (i <= CriticalItemType.DownToHide)
|
|
455
|
+
{
|
|
456
|
+
dirty = dirty || CheckAndHideItem(i);
|
|
457
|
+
}
|
|
458
|
+
else
|
|
459
|
+
{
|
|
460
|
+
dirty = dirty || CheckAndShowItem(i);
|
|
461
|
+
}
|
|
462
|
+
}
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
|
|
466
|
+
private bool CheckAndHideItem(int criticalItemType)
|
|
467
|
+
{
|
|
468
|
+
RectTransform item = GetCriticalItem(criticalItemType);
|
|
469
|
+
var criticalIndex = _criticalItemIndex[criticalItemType];
|
|
470
|
+
if (item == null || ShouldItemSeenAtIndex(criticalIndex)) return false;
|
|
471
|
+
RecycleOldItem(item);
|
|
472
|
+
_managedItems[criticalIndex].item = null;
|
|
473
|
+
|
|
474
|
+
if (criticalItemType == CriticalItemType.UpToHide)
|
|
475
|
+
{
|
|
476
|
+
_criticalItemIndex[criticalItemType + 2] = Mathf.Max(criticalIndex, _criticalItemIndex[criticalItemType + 2]);
|
|
477
|
+
_criticalItemIndex[criticalItemType]++;
|
|
478
|
+
}
|
|
479
|
+
else
|
|
480
|
+
{
|
|
481
|
+
_criticalItemIndex[criticalItemType + 2] = Mathf.Min(criticalIndex, _criticalItemIndex[criticalItemType + 2]);
|
|
482
|
+
_criticalItemIndex[criticalItemType]--;
|
|
483
|
+
}
|
|
484
|
+
|
|
485
|
+
_criticalItemIndex[criticalItemType] = Mathf.Clamp(_criticalItemIndex[criticalItemType], 0, _dataCount - 1);
|
|
486
|
+
|
|
487
|
+
if (_criticalItemIndex[CriticalItemType.UpToHide] <=
|
|
488
|
+
_criticalItemIndex[CriticalItemType.DownToHide]) return true;
|
|
489
|
+
ResetCriticalItems();
|
|
490
|
+
return false;
|
|
491
|
+
|
|
492
|
+
}
|
|
493
|
+
|
|
494
|
+
private bool CheckAndShowItem(int criticalItemType)
|
|
495
|
+
{
|
|
496
|
+
RectTransform item = GetCriticalItem(criticalItemType);
|
|
497
|
+
var criticalIndex = _criticalItemIndex[criticalItemType];
|
|
498
|
+
|
|
499
|
+
if (item != null || !ShouldItemSeenAtIndex(criticalIndex)) return false;
|
|
500
|
+
RectTransform newItem = GetNewItem(criticalIndex);
|
|
501
|
+
OnGetItemForDataIndex(newItem, criticalIndex);
|
|
502
|
+
_managedItems[criticalIndex].item = newItem;
|
|
503
|
+
|
|
504
|
+
if (criticalItemType == CriticalItemType.UpToShow)
|
|
505
|
+
{
|
|
506
|
+
_criticalItemIndex[criticalItemType - 2] = Mathf.Min(criticalIndex, _criticalItemIndex[criticalItemType - 2]);
|
|
507
|
+
_criticalItemIndex[criticalItemType]--;
|
|
508
|
+
}
|
|
509
|
+
else
|
|
510
|
+
{
|
|
511
|
+
_criticalItemIndex[criticalItemType - 2] = Mathf.Max(criticalIndex, _criticalItemIndex[criticalItemType - 2]);
|
|
512
|
+
_criticalItemIndex[criticalItemType]++;
|
|
513
|
+
}
|
|
514
|
+
|
|
515
|
+
_criticalItemIndex[criticalItemType] = Mathf.Clamp(_criticalItemIndex[criticalItemType], 0, _dataCount - 1);
|
|
516
|
+
|
|
517
|
+
if (_criticalItemIndex[CriticalItemType.UpToShow] <
|
|
518
|
+
_criticalItemIndex[CriticalItemType.DownToShow]) return true;
|
|
519
|
+
ResetCriticalItems();
|
|
520
|
+
return false;
|
|
521
|
+
|
|
522
|
+
}
|
|
523
|
+
|
|
524
|
+
private bool ShouldItemSeenAtIndex(int index)
|
|
525
|
+
{
|
|
526
|
+
if (index < 0 || index >= _dataCount)
|
|
527
|
+
{
|
|
528
|
+
return false;
|
|
529
|
+
}
|
|
530
|
+
|
|
531
|
+
EnsureItemRect(index);
|
|
532
|
+
return new Rect(_refRect.position - content.anchoredPosition, _refRect.size).Overlaps(_managedItems[index].rect);
|
|
533
|
+
}
|
|
534
|
+
|
|
535
|
+
private bool ShouldItemFullySeenAtIndex(int index)
|
|
536
|
+
{
|
|
537
|
+
if (index < 0 || index >= _dataCount)
|
|
538
|
+
{
|
|
539
|
+
return false;
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
EnsureItemRect(index);
|
|
543
|
+
return IsRectContains(new Rect(_refRect.position - content.anchoredPosition, _refRect.size), _managedItems[index].rect);
|
|
544
|
+
}
|
|
545
|
+
|
|
546
|
+
private bool IsRectContains(Rect outRect, Rect inRect, bool bothDimensions = false)
|
|
547
|
+
{
|
|
548
|
+
if (bothDimensions)
|
|
549
|
+
{
|
|
550
|
+
var xContains = (outRect.xMax >= inRect.xMax) && (outRect.xMin <= inRect.xMin);
|
|
551
|
+
var yContains = (outRect.yMax >= inRect.yMax) && (outRect.yMin <= inRect.yMin);
|
|
552
|
+
return xContains && yContains;
|
|
553
|
+
}
|
|
554
|
+
else
|
|
555
|
+
{
|
|
556
|
+
var dir = (int)layoutType & FLAG_SCROLL_DIRECTION;
|
|
557
|
+
if (dir == 1)
|
|
558
|
+
{
|
|
559
|
+
return (outRect.yMax >= inRect.yMax) && (outRect.yMin <= inRect.yMin);
|
|
560
|
+
}
|
|
561
|
+
else
|
|
562
|
+
{
|
|
563
|
+
return (outRect.xMax >= inRect.xMax) && (outRect.xMin <= inRect.xMin);
|
|
564
|
+
}
|
|
565
|
+
}
|
|
566
|
+
}
|
|
567
|
+
private void OnGetItemForDataIndex(RectTransform item, int index)
|
|
568
|
+
{
|
|
569
|
+
SetDataForItemAtIndex(item, index);
|
|
570
|
+
item.transform.SetParent(content, false);
|
|
571
|
+
}
|
|
572
|
+
|
|
573
|
+
private void SetDataForItemAtIndex(RectTransform item, int index)
|
|
574
|
+
{
|
|
575
|
+
if (_updateFunc != null)
|
|
576
|
+
{
|
|
577
|
+
_updateFunc(index, item);
|
|
578
|
+
}
|
|
579
|
+
|
|
580
|
+
SetPosForItemAtIndex(item, index);
|
|
581
|
+
}
|
|
582
|
+
|
|
583
|
+
private void SetPosForItemAtIndex(RectTransform item, int index)
|
|
584
|
+
{
|
|
585
|
+
EnsureItemRect(index);
|
|
586
|
+
Rect r = _managedItems[index].rect;
|
|
587
|
+
item.localPosition = r.position;
|
|
588
|
+
item.sizeDelta = r.size;
|
|
589
|
+
}
|
|
590
|
+
|
|
591
|
+
private Vector2 GetItemSize(int index)
|
|
592
|
+
{
|
|
593
|
+
if (index < 0 || index > _dataCount) return defaultItemSize;
|
|
594
|
+
return _itemSizeFunc?.Invoke(index) ?? defaultItemSize;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
private RectTransform GetNewItem(int index)
|
|
598
|
+
{
|
|
599
|
+
var item = _itemGetFunc != null ? _itemGetFunc(index) : itemTemplate.Spawn();
|
|
600
|
+
item.anchorMin = Vector2.up;
|
|
601
|
+
item.anchorMax = Vector2.up;
|
|
602
|
+
item.pivot = Vector2.zero;
|
|
603
|
+
return item;
|
|
604
|
+
}
|
|
605
|
+
|
|
606
|
+
private void RecycleOldItem(RectTransform item)
|
|
607
|
+
{
|
|
608
|
+
if (_itemRecycleFunc != null)
|
|
609
|
+
{
|
|
610
|
+
_itemRecycleFunc(item);
|
|
611
|
+
}
|
|
612
|
+
else
|
|
613
|
+
{
|
|
614
|
+
item.Recycle();
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
|
|
618
|
+
private void InitScrollView()
|
|
619
|
+
{
|
|
620
|
+
_initialized = true;
|
|
621
|
+
var dir = (int)layoutType & FLAG_SCROLL_DIRECTION;
|
|
622
|
+
vertical = dir == 1;
|
|
623
|
+
horizontal = dir == 0;
|
|
624
|
+
|
|
625
|
+
content.pivot = Vector2.up;
|
|
626
|
+
content.anchorMin = Vector2.up;
|
|
627
|
+
content.anchorMax = Vector2.up;
|
|
628
|
+
content.anchoredPosition = Vector2.zero;
|
|
629
|
+
|
|
630
|
+
UpdateRefRect();
|
|
631
|
+
}
|
|
632
|
+
|
|
633
|
+
private void UpdateRefRect()
|
|
634
|
+
{
|
|
635
|
+
/*
|
|
636
|
+
* WorldCorners
|
|
637
|
+
*
|
|
638
|
+
* 1 ------- 2
|
|
639
|
+
* | |
|
|
640
|
+
* | |
|
|
641
|
+
* 0 ------- 3
|
|
642
|
+
*
|
|
643
|
+
*/
|
|
644
|
+
|
|
645
|
+
if (!CanvasUpdateRegistry.IsRebuildingLayout())
|
|
646
|
+
{
|
|
647
|
+
Canvas.ForceUpdateCanvases();
|
|
648
|
+
}
|
|
649
|
+
|
|
650
|
+
viewRect.GetWorldCorners(_viewWorldCorners);
|
|
651
|
+
_rectCorners[0] = content.transform.InverseTransformPoint(_viewWorldCorners[0]);
|
|
652
|
+
_rectCorners[1] = content.transform.InverseTransformPoint(_viewWorldCorners[2]);
|
|
653
|
+
_refRect = new Rect((Vector2)_rectCorners[0] - content.anchoredPosition, _rectCorners[1] - _rectCorners[0]);
|
|
654
|
+
}
|
|
655
|
+
|
|
656
|
+
private void MovePos(ref Vector2 pos, Vector2 size)
|
|
657
|
+
{
|
|
658
|
+
switch (layoutType)
|
|
659
|
+
{
|
|
660
|
+
case ItemLayoutType.Vertical:
|
|
661
|
+
pos.y -= size.y;
|
|
662
|
+
break;
|
|
663
|
+
case ItemLayoutType.Horizontal:
|
|
664
|
+
pos.x += size.x;
|
|
665
|
+
break;
|
|
666
|
+
case ItemLayoutType.VerticalThenHorizontal:
|
|
667
|
+
pos.y -= size.y;
|
|
668
|
+
if (pos.y - size.y < -_refRect.height)
|
|
669
|
+
{
|
|
670
|
+
pos.y = 0;
|
|
671
|
+
pos.x += size.x;
|
|
672
|
+
}
|
|
673
|
+
|
|
674
|
+
break;
|
|
675
|
+
case ItemLayoutType.HorizontalThenVertical:
|
|
676
|
+
|
|
677
|
+
pos.x += size.x;
|
|
678
|
+
if (pos.x + size.x > _refRect.width)
|
|
679
|
+
{
|
|
680
|
+
pos.x = 0;
|
|
681
|
+
pos.y -= size.y;
|
|
682
|
+
}
|
|
683
|
+
break;
|
|
684
|
+
}
|
|
685
|
+
}
|
|
686
|
+
|
|
687
|
+
private static class CriticalItemType
|
|
688
|
+
{
|
|
689
|
+
public const byte UpToHide = 0;
|
|
690
|
+
public const byte DownToHide = 1;
|
|
691
|
+
public const byte UpToShow = 2;
|
|
692
|
+
public const byte DownToShow = 3;
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
private class ScrollItemWithRect
|
|
696
|
+
{
|
|
697
|
+
public RectTransform item;
|
|
698
|
+
public Rect rect;
|
|
699
|
+
public bool rectDirty = true;
|
|
700
|
+
}
|
|
701
|
+
}
|
|
702
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
fileFormatVersion: 2
|
|
2
|
+
guid: 2d355eec575560046ba27246695b84ad
|
|
3
|
+
timeCreated: 1533042733
|
|
4
|
+
licenseType: Free
|
|
5
|
+
MonoImporter:
|
|
6
|
+
serializedVersion: 2
|
|
7
|
+
defaultReferences: []
|
|
8
|
+
executionOrder: 0
|
|
9
|
+
icon: {instanceID: 0}
|
|
10
|
+
userData:
|
|
11
|
+
assetBundleName:
|
|
12
|
+
assetBundleVariant:
|