com.taptap.sdk.core 4.3.0-aplha.12
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/Editor/BuildTargetUtils.cs +14 -0
- package/Editor/BuildTargetUtils.cs.meta +11 -0
- package/Editor/LinkXMLGenerator.cs +70 -0
- package/Editor/LinkXMLGenerator.cs.meta +11 -0
- package/Editor/Plist.cs +954 -0
- package/Editor/Plist.cs.meta +3 -0
- package/Editor/SDKLinkProcessBuild.cs +119 -0
- package/Editor/SDKLinkProcessBuild.cs.meta +11 -0
- package/Editor/TapFileHelper.cs +168 -0
- package/Editor/TapFileHelper.cs.meta +3 -0
- package/Editor/TapSDK.Core.Editor.asmdef +15 -0
- package/Editor/TapSDK.Core.Editor.asmdef.meta +7 -0
- package/Editor/TapSDKCoreCompile.cs +284 -0
- package/Editor/TapSDKCoreCompile.cs.meta +3 -0
- package/Editor/TapSDKCoreIOSProcessor.cs +74 -0
- package/Editor/TapSDKCoreIOSProcessor.cs.meta +3 -0
- package/Editor/UI/ScrollViewEditor.cs +267 -0
- package/Editor/UI/ScrollViewEditor.cs.meta +12 -0
- package/Editor/UI/ScrollViewExEditor.cs +34 -0
- package/Editor/UI/ScrollViewExEditor.cs.meta +12 -0
- package/Editor/UI/TapSDK.UI.Editor.asmdef +17 -0
- package/Editor/UI/TapSDK.UI.Editor.asmdef.meta +7 -0
- package/Editor/UI.meta +9 -0
- package/Editor.meta +8 -0
- package/Mobile/Editor/NativeDependencies.xml +22 -0
- package/Mobile/Editor/NativeDependencies.xml.meta +7 -0
- package/Mobile/Editor/TapCommonMobileProcessBuild.cs +20 -0
- package/Mobile/Editor/TapCommonMobileProcessBuild.cs.meta +11 -0
- package/Mobile/Editor/TapSDK.Core.Mobile.Editor.asmdef +17 -0
- package/Mobile/Editor/TapSDK.Core.Mobile.Editor.asmdef.meta +7 -0
- package/Mobile/Editor.meta +8 -0
- package/Mobile/Runtime/AndroidNativeWrapper.cs +50 -0
- package/Mobile/Runtime/AndroidNativeWrapper.cs.meta +11 -0
- package/Mobile/Runtime/Bridge.cs +84 -0
- package/Mobile/Runtime/Bridge.cs.meta +11 -0
- package/Mobile/Runtime/BridgeAndroid.cs +73 -0
- package/Mobile/Runtime/BridgeAndroid.cs.meta +11 -0
- package/Mobile/Runtime/BridgeCallback.cs +35 -0
- package/Mobile/Runtime/BridgeCallback.cs.meta +11 -0
- package/Mobile/Runtime/BridgeIOS.cs +113 -0
- package/Mobile/Runtime/BridgeIOS.cs.meta +11 -0
- package/Mobile/Runtime/Command.cs +119 -0
- package/Mobile/Runtime/Command.cs.meta +11 -0
- package/Mobile/Runtime/Constants.cs +9 -0
- package/Mobile/Runtime/Constants.cs.meta +11 -0
- package/Mobile/Runtime/EngineBridgeInitializer.cs +33 -0
- package/Mobile/Runtime/EngineBridgeInitializer.cs.meta +11 -0
- package/Mobile/Runtime/IBridge.cs +15 -0
- package/Mobile/Runtime/IBridge.cs.meta +11 -0
- package/Mobile/Runtime/IOSNativeWrapper.cs +273 -0
- package/Mobile/Runtime/IOSNativeWrapper.cs.meta +11 -0
- package/Mobile/Runtime/Result.cs +37 -0
- package/Mobile/Runtime/Result.cs.meta +11 -0
- package/Mobile/Runtime/TapCoreMobile.cs +71 -0
- package/Mobile/Runtime/TapCoreMobile.cs.meta +11 -0
- package/Mobile/Runtime/TapEventMobile.cs +265 -0
- package/Mobile/Runtime/TapEventMobile.cs.meta +11 -0
- package/Mobile/Runtime/TapSDK.Core.Mobile.Runtime.asmdef +18 -0
- package/Mobile/Runtime/TapSDK.Core.Mobile.Runtime.asmdef.meta +7 -0
- package/Mobile/Runtime/TapUUID.cs +9 -0
- package/Mobile/Runtime/TapUUID.cs.meta +11 -0
- package/Mobile/Runtime.meta +8 -0
- package/Mobile.meta +8 -0
- package/Plugins/iOS.meta +8 -0
- package/Plugins.meta +8 -0
- package/Resources/Fonts/taptap-sdk-bold.ttf +0 -0
- package/Resources/Fonts/taptap-sdk-bold.ttf.meta +22 -0
- package/Resources/Fonts/taptap-sdk.ttf +0 -0
- package/Resources/Fonts/taptap-sdk.ttf.meta +21 -0
- package/Resources/Fonts.meta +8 -0
- package/Resources/Loading.prefab +260 -0
- package/Resources/Loading.prefab.meta +7 -0
- package/Resources/TapCommonTip.prefab +194 -0
- package/Resources/TapCommonTip.prefab.meta +7 -0
- package/Resources/TapCommonToastBlack.prefab +528 -0
- package/Resources/TapCommonToastBlack.prefab.meta +7 -0
- package/Resources/TapCommonToastWhite.prefab +411 -0
- package/Resources/TapCommonToastWhite.prefab.meta +7 -0
- package/Resources/TapSDKCommonTapIcon-v2.png +0 -0
- package/Resources/TapSDKCommonTapIcon-v2.png.meta +128 -0
- package/Resources/TapSDKCommonTapIcon.png +0 -0
- package/Resources/TapSDKCommonTapIcon.png.meta +128 -0
- package/Resources/TapSDKCommonToastBg.png +0 -0
- package/Resources/TapSDKCommonToastBg.png.meta +128 -0
- package/Resources/TapSDKConstantUIRoot.prefab +100 -0
- package/Resources/TapSDKConstantUIRoot.prefab.meta +7 -0
- package/Resources/TapSDKUIRoot.prefab +100 -0
- package/Resources/TapSDKUIRoot.prefab.meta +7 -0
- package/Resources/TapTapBtn_White.png +0 -0
- package/Resources/TapTapBtn_White.png.meta +128 -0
- package/Resources/TapTapBtn_White_2.png +0 -0
- package/Resources/TapTapBtn_White_2.png.meta +128 -0
- package/Resources/ToastBackground.png +0 -0
- package/Resources/ToastBackground.png.meta +128 -0
- package/Resources/detail_bg.png +0 -0
- package/Resources/detail_bg.png.meta +92 -0
- package/Resources/success.png +0 -0
- package/Resources/success.png.meta +128 -0
- package/Resources/taptap-bg.png +0 -0
- package/Resources/taptap-bg.png.meta +140 -0
- package/Resources/taptap-close.png +0 -0
- package/Resources/taptap-close.png.meta +146 -0
- package/Resources/taptap-router-v2.png +0 -0
- package/Resources/taptap-router-v2.png.meta +128 -0
- package/Resources/taptap-router.png +0 -0
- package/Resources/taptap-router.png.meta +146 -0
- package/Resources/taptap-sdk-refresh 1.png +0 -0
- package/Resources/taptap-sdk-refresh 1.png.meta +128 -0
- package/Resources/taptap-toast-error.png +0 -0
- package/Resources/taptap-toast-error.png.meta +128 -0
- package/Resources/taptap-toast-info.png +0 -0
- package/Resources/taptap-toast-info.png.meta +128 -0
- package/Resources/taptap-toast-success.png +0 -0
- package/Resources/taptap-toast-success.png.meta +128 -0
- package/Resources/taptap-toast-warning.png +0 -0
- package/Resources/taptap-toast-warning.png.meta +128 -0
- package/Resources.meta +8 -0
- package/Runtime/Internal/Http/TapHttpClient.cs +176 -0
- package/Runtime/Internal/Http/TapHttpClient.cs.meta +11 -0
- package/Runtime/Internal/Http/TapHttpUtils.cs +83 -0
- package/Runtime/Internal/Http/TapHttpUtils.cs.meta +11 -0
- package/Runtime/Internal/Http.meta +8 -0
- package/Runtime/Internal/Init/IInitTask.cs +18 -0
- package/Runtime/Internal/Init/IInitTask.cs.meta +11 -0
- package/Runtime/Internal/Init.meta +8 -0
- package/Runtime/Internal/Json/TapJsonConverter.cs +40 -0
- package/Runtime/Internal/Json/TapJsonConverter.cs.meta +11 -0
- package/Runtime/Internal/Json.meta +8 -0
- package/Runtime/Internal/Platform/ITapCorePlatform.cs +12 -0
- package/Runtime/Internal/Platform/ITapCorePlatform.cs.meta +11 -0
- package/Runtime/Internal/Platform/ITapEventPlatform.cs +37 -0
- package/Runtime/Internal/Platform/ITapEventPlatform.cs.meta +11 -0
- package/Runtime/Internal/Platform/PlatformTypeUtils.cs +46 -0
- package/Runtime/Internal/Platform/PlatformTypeUtils.cs.meta +11 -0
- package/Runtime/Internal/Platform.meta +8 -0
- package/Runtime/Internal/UI/Base/Const.cs +27 -0
- package/Runtime/Internal/UI/Base/Const.cs.meta +11 -0
- package/Runtime/Internal/UI/Base/GraphicRaycasterBugFixed.cs +240 -0
- package/Runtime/Internal/UI/Base/GraphicRaycasterBugFixed.cs.meta +3 -0
- package/Runtime/Internal/UI/Base/LoadingPanelController.cs +29 -0
- package/Runtime/Internal/UI/Base/LoadingPanelController.cs.meta +11 -0
- package/Runtime/Internal/UI/Base/MonoSingleton.cs +102 -0
- package/Runtime/Internal/UI/Base/MonoSingleton.cs.meta +11 -0
- package/Runtime/Internal/UI/Base/Singleton.cs +29 -0
- package/Runtime/Internal/UI/Base/Singleton.cs.meta +11 -0
- package/Runtime/Internal/UI/Base/TipPanelController.cs +45 -0
- package/Runtime/Internal/UI/Base/TipPanelController.cs.meta +3 -0
- package/Runtime/Internal/UI/Base/ToastBlackPanelController.cs +95 -0
- package/Runtime/Internal/UI/Base/ToastBlackPanelController.cs.meta +11 -0
- package/Runtime/Internal/UI/Base/ToastWhitePanelController.cs +79 -0
- package/Runtime/Internal/UI/Base/ToastWhitePanelController.cs.meta +3 -0
- package/Runtime/Internal/UI/Base/UIManager.cs +724 -0
- package/Runtime/Internal/UI/Base/UIManager.cs.meta +11 -0
- package/Runtime/Internal/UI/Base.meta +8 -0
- package/Runtime/Internal/UI/BasePanel/BasePanelController.cs +385 -0
- package/Runtime/Internal/UI/BasePanel/BasePanelController.cs.meta +11 -0
- package/Runtime/Internal/UI/BasePanel.meta +8 -0
- package/Runtime/Internal/UI/Params/BasePanelConfig.cs +18 -0
- package/Runtime/Internal/UI/Params/BasePanelConfig.cs.meta +11 -0
- package/Runtime/Internal/UI/Params/IOpenPanelParameter.cs +7 -0
- package/Runtime/Internal/UI/Params/IOpenPanelParameter.cs.meta +11 -0
- package/Runtime/Internal/UI/Params.meta +8 -0
- package/Runtime/Internal/UI/ScrollViewEx/ObjPool/SimpleObjPool.cs +76 -0
- package/Runtime/Internal/UI/ScrollViewEx/ObjPool/SimpleObjPool.cs.meta +12 -0
- package/Runtime/Internal/UI/ScrollViewEx/ObjPool.meta +9 -0
- package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollView.cs +828 -0
- package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollView.cs.meta +12 -0
- package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollViewEx.cs +245 -0
- package/Runtime/Internal/UI/ScrollViewEx/ScrollView/ScrollViewEx.cs.meta +12 -0
- package/Runtime/Internal/UI/ScrollViewEx/ScrollView.meta +9 -0
- package/Runtime/Internal/UI/ScrollViewEx.meta +8 -0
- package/Runtime/Internal/UI.meta +8 -0
- package/Runtime/Internal/Utils/BridgeUtils.cs +29 -0
- package/Runtime/Internal/Utils/BridgeUtils.cs.meta +11 -0
- package/Runtime/Internal/Utils/ImageUtils.cs +147 -0
- package/Runtime/Internal/Utils/ImageUtils.cs.meta +11 -0
- package/Runtime/Internal/Utils/TapLoom.cs +155 -0
- package/Runtime/Internal/Utils/TapLoom.cs.meta +11 -0
- package/Runtime/Internal/Utils/UrlUtils.cs +34 -0
- package/Runtime/Internal/Utils/UrlUtils.cs.meta +11 -0
- package/Runtime/Internal/Utils.meta +8 -0
- package/Runtime/Internal.meta +8 -0
- package/Runtime/Public/DataStorage.cs +141 -0
- package/Runtime/Public/DataStorage.cs.meta +11 -0
- package/Runtime/Public/ITapPropertiesProxy.cs +6 -0
- package/Runtime/Public/ITapPropertiesProxy.cs.meta +11 -0
- package/Runtime/Public/Json.cs +636 -0
- package/Runtime/Public/Json.cs.meta +11 -0
- package/Runtime/Public/Log/TapLogLevel.cs +7 -0
- package/Runtime/Public/Log/TapLogLevel.cs.meta +11 -0
- package/Runtime/Public/Log/TapLogger.cs +48 -0
- package/Runtime/Public/Log/TapLogger.cs.meta +11 -0
- package/Runtime/Public/Log.meta +8 -0
- package/Runtime/Public/Platform.cs +27 -0
- package/Runtime/Public/Platform.cs.meta +11 -0
- package/Runtime/Public/RegionType.cs +8 -0
- package/Runtime/Public/RegionType.cs.meta +11 -0
- package/Runtime/Public/SafeDictionary.cs +27 -0
- package/Runtime/Public/SafeDictionary.cs.meta +11 -0
- package/Runtime/Public/TapError.cs +62 -0
- package/Runtime/Public/TapError.cs.meta +11 -0
- package/Runtime/Public/TapErrorCode.cs +44 -0
- package/Runtime/Public/TapErrorCode.cs.meta +11 -0
- package/Runtime/Public/TapException.cs +24 -0
- package/Runtime/Public/TapException.cs.meta +11 -0
- package/Runtime/Public/TapLanguage.cs +21 -0
- package/Runtime/Public/TapLanguage.cs.meta +11 -0
- package/Runtime/Public/TapLocalizeManager.cs +128 -0
- package/Runtime/Public/TapLocalizeManager.cs.meta +11 -0
- package/Runtime/Public/TapTapEvent.cs +93 -0
- package/Runtime/Public/TapTapEvent.cs.meta +11 -0
- package/Runtime/Public/TapTapSDK.cs +96 -0
- package/Runtime/Public/TapTapSDK.cs.meta +11 -0
- package/Runtime/Public/TapTapSDKCoreOptions.cs +104 -0
- package/Runtime/Public/TapTapSDKCoreOptions.cs.meta +11 -0
- package/Runtime/Public.meta +8 -0
- package/Runtime/TapSDK.Core.Runtime.asmdef +3 -0
- package/Runtime/TapSDK.Core.Runtime.asmdef.meta +7 -0
- package/Runtime.meta +8 -0
- package/Standalone/Editor/TapCoreStandaloneProcessBuild.cs +20 -0
- package/Standalone/Editor/TapCoreStandaloneProcessBuild.cs.meta +11 -0
- package/Standalone/Editor/TapSDK.Core.Standalone.Editor.asmdef +17 -0
- package/Standalone/Editor/TapSDK.Core.Standalone.Editor.asmdef.meta +7 -0
- package/Standalone/Editor.meta +8 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/Info.plist +46 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/Info.plist.meta +7 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/MacOS/TapDBDeviceInfo +0 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/MacOS/TapDBDeviceInfo.meta +7 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/MacOS.meta +8 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/_CodeSignature/CodeResources +115 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/_CodeSignature/CodeResources.meta +7 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents/_CodeSignature.meta +8 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle/Contents.meta +8 -0
- package/Standalone/Plugins/macOS/TapDBDeviceInfo.bundle.meta +33 -0
- package/Standalone/Plugins/macOS.meta +8 -0
- package/Standalone/Plugins.meta +8 -0
- package/Standalone/Runtime/Internal/Constants.cs +37 -0
- package/Standalone/Runtime/Internal/Constants.cs.meta +11 -0
- package/Standalone/Runtime/Internal/DeviceInfo.cs +152 -0
- package/Standalone/Runtime/Internal/DeviceInfo.cs.meta +11 -0
- package/Standalone/Runtime/Internal/EventSender.cs +239 -0
- package/Standalone/Runtime/Internal/EventSender.cs.meta +11 -0
- package/Standalone/Runtime/Internal/Http/HttpClient.cs +211 -0
- package/Standalone/Runtime/Internal/Http/HttpClient.cs.meta +11 -0
- package/Standalone/Runtime/Internal/Http/NetUtils.cs +48 -0
- package/Standalone/Runtime/Internal/Http/NetUtils.cs.meta +11 -0
- package/Standalone/Runtime/Internal/Http/TimeUtil.cs +30 -0
- package/Standalone/Runtime/Internal/Http/TimeUtil.cs.meta +11 -0
- package/Standalone/Runtime/Internal/Http.meta +8 -0
- package/Standalone/Runtime/Internal/Identity.cs +43 -0
- package/Standalone/Runtime/Internal/Identity.cs.meta +11 -0
- package/Standalone/Runtime/Internal/PlayRecorder.cs +53 -0
- package/Standalone/Runtime/Internal/PlayRecorder.cs.meta +11 -0
- package/Standalone/Runtime/Internal/Prefs.cs +85 -0
- package/Standalone/Runtime/Internal/Prefs.cs.meta +11 -0
- package/Standalone/Runtime/Internal/Tracker.cs +318 -0
- package/Standalone/Runtime/Internal/Tracker.cs.meta +11 -0
- package/Standalone/Runtime/Internal/User.cs +51 -0
- package/Standalone/Runtime/Internal/User.cs.meta +11 -0
- package/Standalone/Runtime/Internal.meta +8 -0
- package/Standalone/Runtime/Public/EventManager.cs +41 -0
- package/Standalone/Runtime/Public/EventManager.cs.meta +11 -0
- package/Standalone/Runtime/Public/TapCoreStandalone.cs +197 -0
- package/Standalone/Runtime/Public/TapCoreStandalone.cs.meta +11 -0
- package/Standalone/Runtime/Public/TapEventStandalone.cs +281 -0
- package/Standalone/Runtime/Public/TapEventStandalone.cs.meta +11 -0
- package/Standalone/Runtime/Public.meta +8 -0
- package/Standalone/Runtime/TapSDK.Core.Standalone.Runtime.asmdef +21 -0
- package/Standalone/Runtime/TapSDK.Core.Standalone.Runtime.asmdef.meta +7 -0
- package/Standalone/Runtime.meta +8 -0
- package/Standalone.meta +8 -0
- package/package.json +8 -0
- package/package.json.meta +7 -0
|
@@ -0,0 +1,828 @@
|
|
|
1
|
+
// -----------------------------------------------------------------------
|
|
2
|
+
// <copyright file="ScrollView.cs" company="AillieoTech">
|
|
3
|
+
// Copyright (c) AillieoTech. All rights reserved.
|
|
4
|
+
// </copyright>
|
|
5
|
+
// -----------------------------------------------------------------------
|
|
6
|
+
|
|
7
|
+
namespace TapSDK.UI.AillieoTech
|
|
8
|
+
{
|
|
9
|
+
using System;
|
|
10
|
+
using System.Collections;
|
|
11
|
+
using System.Collections.Generic;
|
|
12
|
+
using UnityEngine;
|
|
13
|
+
using UnityEngine.Serialization;
|
|
14
|
+
using UnityEngine.UI;
|
|
15
|
+
|
|
16
|
+
[RequireComponent(typeof(RectTransform))]
|
|
17
|
+
[DisallowMultipleComponent]
|
|
18
|
+
public class ScrollView : ScrollRect
|
|
19
|
+
{
|
|
20
|
+
[Tooltip("默认item尺寸")]
|
|
21
|
+
public Vector2 defaultItemSize;
|
|
22
|
+
|
|
23
|
+
[Tooltip("item的模板")]
|
|
24
|
+
public RectTransform itemTemplate;
|
|
25
|
+
|
|
26
|
+
// 0001
|
|
27
|
+
protected const int flagScrollDirection = 1;
|
|
28
|
+
|
|
29
|
+
[SerializeField]
|
|
30
|
+
[FormerlySerializedAs("m_layoutType")]
|
|
31
|
+
protected ItemLayoutType layoutType = ItemLayoutType.Vertical;
|
|
32
|
+
|
|
33
|
+
// 只保存4个临界index
|
|
34
|
+
protected int[] criticalItemIndex = new int[4];
|
|
35
|
+
|
|
36
|
+
// callbacks for items
|
|
37
|
+
protected Action<int, RectTransform> updateFunc;
|
|
38
|
+
protected Func<int, Vector2> itemSizeFunc;
|
|
39
|
+
protected Func<int> itemCountFunc;
|
|
40
|
+
protected Func<int, RectTransform> itemGetFunc;
|
|
41
|
+
protected Action<RectTransform> itemRecycleFunc;
|
|
42
|
+
|
|
43
|
+
private readonly List<ScrollItemWithRect> managedItems = new List<ScrollItemWithRect>();
|
|
44
|
+
|
|
45
|
+
private Rect refRect;
|
|
46
|
+
|
|
47
|
+
// resource management
|
|
48
|
+
private SimpleObjPool<RectTransform> itemPool = null;
|
|
49
|
+
|
|
50
|
+
private int dataCount = 0;
|
|
51
|
+
|
|
52
|
+
[Tooltip("初始化时池内item数量")]
|
|
53
|
+
[SerializeField]
|
|
54
|
+
private int poolSize;
|
|
55
|
+
|
|
56
|
+
// status
|
|
57
|
+
private bool initialized = false;
|
|
58
|
+
private int willUpdateData = 0;
|
|
59
|
+
|
|
60
|
+
private Vector3[] viewWorldConers = new Vector3[4];
|
|
61
|
+
private Vector3[] rectCorners = new Vector3[2];
|
|
62
|
+
|
|
63
|
+
// for hide and show
|
|
64
|
+
public enum ItemLayoutType
|
|
65
|
+
{
|
|
66
|
+
// 最后一位表示滚动方向
|
|
67
|
+
Vertical = 0b0001, // 0001
|
|
68
|
+
Horizontal = 0b0010, // 0010
|
|
69
|
+
VerticalThenHorizontal = 0b0100, // 0100
|
|
70
|
+
HorizontalThenVertical = 0b0101, // 0101
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
public virtual void SetUpdateFunc(Action<int, RectTransform> func)
|
|
74
|
+
{
|
|
75
|
+
this.updateFunc = func;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
public virtual void SetItemSizeFunc(Func<int, Vector2> func)
|
|
79
|
+
{
|
|
80
|
+
this.itemSizeFunc = func;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
public virtual void SetItemCountFunc(Func<int> func)
|
|
84
|
+
{
|
|
85
|
+
this.itemCountFunc = func;
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public void SetItemGetAndRecycleFunc(Func<int, RectTransform> getFunc, Action<RectTransform> recycleFunc)
|
|
89
|
+
{
|
|
90
|
+
if (getFunc != null && recycleFunc != null)
|
|
91
|
+
{
|
|
92
|
+
this.itemGetFunc = getFunc;
|
|
93
|
+
this.itemRecycleFunc = recycleFunc;
|
|
94
|
+
}
|
|
95
|
+
else
|
|
96
|
+
{
|
|
97
|
+
this.itemGetFunc = null;
|
|
98
|
+
this.itemRecycleFunc = null;
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
public void ResetAllDelegates()
|
|
103
|
+
{
|
|
104
|
+
this.SetUpdateFunc(null);
|
|
105
|
+
this.SetItemSizeFunc(null);
|
|
106
|
+
this.SetItemCountFunc(null);
|
|
107
|
+
this.SetItemGetAndRecycleFunc(null, null);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
public void UpdateData(bool immediately = true)
|
|
111
|
+
{
|
|
112
|
+
if (immediately)
|
|
113
|
+
{
|
|
114
|
+
this.willUpdateData |= 3; // 0011
|
|
115
|
+
this.InternalUpdateData();
|
|
116
|
+
}
|
|
117
|
+
else
|
|
118
|
+
{
|
|
119
|
+
if (this.willUpdateData == 0 && this.IsActive())
|
|
120
|
+
{
|
|
121
|
+
this.StartCoroutine(this.DelayUpdateData());
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
this.willUpdateData |= 3;
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
public void UpdateDataIncrementally(bool immediately = true)
|
|
129
|
+
{
|
|
130
|
+
if (immediately)
|
|
131
|
+
{
|
|
132
|
+
this.willUpdateData |= 1; // 0001
|
|
133
|
+
this.InternalUpdateData();
|
|
134
|
+
}
|
|
135
|
+
else
|
|
136
|
+
{
|
|
137
|
+
if (this.willUpdateData == 0)
|
|
138
|
+
{
|
|
139
|
+
this.StartCoroutine(this.DelayUpdateData());
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
this.willUpdateData |= 1;
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
public void ScrollTo(int index)
|
|
147
|
+
{
|
|
148
|
+
this.InternalScrollTo(index);
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
protected override void OnEnable()
|
|
152
|
+
{
|
|
153
|
+
base.OnEnable();
|
|
154
|
+
if (this.willUpdateData != 0)
|
|
155
|
+
{
|
|
156
|
+
this.StartCoroutine(this.DelayUpdateData());
|
|
157
|
+
}
|
|
158
|
+
}
|
|
159
|
+
|
|
160
|
+
protected override void OnDisable()
|
|
161
|
+
{
|
|
162
|
+
this.initialized = false;
|
|
163
|
+
base.OnDisable();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
protected virtual void InternalScrollTo(int index)
|
|
167
|
+
{
|
|
168
|
+
index = Mathf.Clamp(index, 0, this.dataCount - 1);
|
|
169
|
+
this.EnsureItemRect(index);
|
|
170
|
+
Rect r = this.managedItems[index].rect;
|
|
171
|
+
|
|
172
|
+
var dir = (int)this.layoutType & flagScrollDirection;
|
|
173
|
+
if (dir == 1)
|
|
174
|
+
{
|
|
175
|
+
// vertical
|
|
176
|
+
var value = 1 - (-r.yMax / (this.content.sizeDelta.y - this.refRect.height));
|
|
177
|
+
this.SetNormalizedPosition(value, 1);
|
|
178
|
+
}
|
|
179
|
+
else
|
|
180
|
+
{
|
|
181
|
+
// horizontal
|
|
182
|
+
var value = r.xMin / (this.content.sizeDelta.x - this.refRect.width);
|
|
183
|
+
this.SetNormalizedPosition(value, 0);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
protected override void SetContentAnchoredPosition(Vector2 position)
|
|
188
|
+
{
|
|
189
|
+
base.SetContentAnchoredPosition(position);
|
|
190
|
+
this.UpdateCriticalItems();
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
protected override void SetNormalizedPosition(float value, int axis)
|
|
194
|
+
{
|
|
195
|
+
base.SetNormalizedPosition(value, axis);
|
|
196
|
+
this.ResetCriticalItems();
|
|
197
|
+
}
|
|
198
|
+
|
|
199
|
+
protected void EnsureItemRect(int index)
|
|
200
|
+
{
|
|
201
|
+
if (!this.managedItems[index].rectDirty)
|
|
202
|
+
{
|
|
203
|
+
// 已经是干净的了
|
|
204
|
+
return;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
ScrollItemWithRect firstItem = this.managedItems[0];
|
|
208
|
+
if (firstItem.rectDirty)
|
|
209
|
+
{
|
|
210
|
+
Vector2 firstSize = this.GetItemSize(0);
|
|
211
|
+
firstItem.rect = CreateWithLeftTopAndSize(Vector2.zero, firstSize);
|
|
212
|
+
firstItem.rectDirty = false;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
// 当前item之前的最近的已更新的rect
|
|
216
|
+
var nearestClean = 0;
|
|
217
|
+
for (var i = index; i >= 0; --i)
|
|
218
|
+
{
|
|
219
|
+
if (!this.managedItems[i].rectDirty)
|
|
220
|
+
{
|
|
221
|
+
nearestClean = i;
|
|
222
|
+
break;
|
|
223
|
+
}
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
// 需要更新 从 nearestClean 到 index 的尺寸
|
|
227
|
+
Rect nearestCleanRect = this.managedItems[nearestClean].rect;
|
|
228
|
+
Vector2 curPos = GetLeftTop(nearestCleanRect);
|
|
229
|
+
Vector2 size = nearestCleanRect.size;
|
|
230
|
+
this.MovePos(ref curPos, size);
|
|
231
|
+
|
|
232
|
+
for (var i = nearestClean + 1; i <= index; i++)
|
|
233
|
+
{
|
|
234
|
+
size = this.GetItemSize(i);
|
|
235
|
+
this.managedItems[i].rect = CreateWithLeftTopAndSize(curPos, size);
|
|
236
|
+
this.managedItems[i].rectDirty = false;
|
|
237
|
+
this.MovePos(ref curPos, size);
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
var range = new Vector2(Mathf.Abs(curPos.x), Mathf.Abs(curPos.y));
|
|
241
|
+
switch (this.layoutType)
|
|
242
|
+
{
|
|
243
|
+
case ItemLayoutType.VerticalThenHorizontal:
|
|
244
|
+
range.x += size.x;
|
|
245
|
+
range.y = this.refRect.height;
|
|
246
|
+
break;
|
|
247
|
+
case ItemLayoutType.HorizontalThenVertical:
|
|
248
|
+
range.x = this.refRect.width;
|
|
249
|
+
if (curPos.x != 0)
|
|
250
|
+
{
|
|
251
|
+
range.y += size.y;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
break;
|
|
255
|
+
default:
|
|
256
|
+
break;
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
this.content.sizeDelta = range;
|
|
260
|
+
}
|
|
261
|
+
|
|
262
|
+
protected override void OnDestroy()
|
|
263
|
+
{
|
|
264
|
+
if (this.itemPool != null)
|
|
265
|
+
{
|
|
266
|
+
this.itemPool.Purge();
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
|
|
270
|
+
protected Rect GetItemLocalRect(int index)
|
|
271
|
+
{
|
|
272
|
+
if (index >= 0 && index < this.dataCount)
|
|
273
|
+
{
|
|
274
|
+
this.EnsureItemRect(index);
|
|
275
|
+
return this.managedItems[index].rect;
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
return (Rect)default;
|
|
279
|
+
}
|
|
280
|
+
|
|
281
|
+
#if UNITY_EDITOR
|
|
282
|
+
protected override void OnValidate()
|
|
283
|
+
{
|
|
284
|
+
var dir = (int)this.layoutType & flagScrollDirection;
|
|
285
|
+
if (dir == 1)
|
|
286
|
+
{
|
|
287
|
+
// vertical
|
|
288
|
+
if (this.horizontalScrollbar != null)
|
|
289
|
+
{
|
|
290
|
+
this.horizontalScrollbar.gameObject.SetActive(false);
|
|
291
|
+
this.horizontalScrollbar = null;
|
|
292
|
+
}
|
|
293
|
+
}
|
|
294
|
+
else
|
|
295
|
+
{
|
|
296
|
+
// horizontal
|
|
297
|
+
if (this.verticalScrollbar != null)
|
|
298
|
+
{
|
|
299
|
+
this.verticalScrollbar.gameObject.SetActive(false);
|
|
300
|
+
this.verticalScrollbar = null;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
base.OnValidate();
|
|
305
|
+
}
|
|
306
|
+
#endif
|
|
307
|
+
|
|
308
|
+
private static Vector2 GetLeftTop(Rect rect)
|
|
309
|
+
{
|
|
310
|
+
Vector2 ret = rect.position;
|
|
311
|
+
ret.y += rect.size.y;
|
|
312
|
+
return ret;
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
private static Rect CreateWithLeftTopAndSize(Vector2 leftTop, Vector2 size)
|
|
316
|
+
{
|
|
317
|
+
Vector2 leftBottom = leftTop - new Vector2(0, size.y);
|
|
318
|
+
return new Rect(leftBottom, size);
|
|
319
|
+
}
|
|
320
|
+
|
|
321
|
+
private IEnumerator DelayUpdateData()
|
|
322
|
+
{
|
|
323
|
+
yield return new WaitForEndOfFrame();
|
|
324
|
+
this.InternalUpdateData();
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
private void InternalUpdateData()
|
|
328
|
+
{
|
|
329
|
+
if (!this.IsActive())
|
|
330
|
+
{
|
|
331
|
+
this.willUpdateData |= 3;
|
|
332
|
+
return;
|
|
333
|
+
}
|
|
334
|
+
|
|
335
|
+
if (!this.initialized)
|
|
336
|
+
{
|
|
337
|
+
this.InitScrollView();
|
|
338
|
+
}
|
|
339
|
+
|
|
340
|
+
var newDataCount = 0;
|
|
341
|
+
var keepOldItems = (this.willUpdateData & 2) == 0;
|
|
342
|
+
|
|
343
|
+
if (this.itemCountFunc != null)
|
|
344
|
+
{
|
|
345
|
+
newDataCount = this.itemCountFunc();
|
|
346
|
+
}
|
|
347
|
+
|
|
348
|
+
if (newDataCount != this.managedItems.Count)
|
|
349
|
+
{
|
|
350
|
+
if (this.managedItems.Count < newDataCount)
|
|
351
|
+
{
|
|
352
|
+
// 增加
|
|
353
|
+
if (!keepOldItems)
|
|
354
|
+
{
|
|
355
|
+
foreach (var itemWithRect in this.managedItems)
|
|
356
|
+
{
|
|
357
|
+
// 重置所有rect
|
|
358
|
+
itemWithRect.rectDirty = true;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
while (this.managedItems.Count < newDataCount)
|
|
363
|
+
{
|
|
364
|
+
this.managedItems.Add(new ScrollItemWithRect());
|
|
365
|
+
}
|
|
366
|
+
}
|
|
367
|
+
else
|
|
368
|
+
{
|
|
369
|
+
// 减少 保留空位 避免GC
|
|
370
|
+
for (int i = 0, count = this.managedItems.Count; i < count; ++i)
|
|
371
|
+
{
|
|
372
|
+
if (i < newDataCount)
|
|
373
|
+
{
|
|
374
|
+
// 重置所有rect
|
|
375
|
+
if (!keepOldItems)
|
|
376
|
+
{
|
|
377
|
+
this.managedItems[i].rectDirty = true;
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
if (i == newDataCount - 1)
|
|
381
|
+
{
|
|
382
|
+
this.managedItems[i].rectDirty = true;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
|
|
386
|
+
// 超出部分 清理回收item
|
|
387
|
+
if (i >= newDataCount)
|
|
388
|
+
{
|
|
389
|
+
this.managedItems[i].rectDirty = true;
|
|
390
|
+
if (this.managedItems[i].item != null)
|
|
391
|
+
{
|
|
392
|
+
this.RecycleOldItem(this.managedItems[i].item);
|
|
393
|
+
this.managedItems[i].item = null;
|
|
394
|
+
}
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
else
|
|
400
|
+
{
|
|
401
|
+
if (!keepOldItems)
|
|
402
|
+
{
|
|
403
|
+
for (int i = 0, count = this.managedItems.Count; i < count; ++i)
|
|
404
|
+
{
|
|
405
|
+
// 重置所有rect
|
|
406
|
+
this.managedItems[i].rectDirty = true;
|
|
407
|
+
}
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
this.dataCount = newDataCount;
|
|
412
|
+
|
|
413
|
+
this.ResetCriticalItems();
|
|
414
|
+
|
|
415
|
+
this.willUpdateData = 0;
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
private void ResetCriticalItems()
|
|
419
|
+
{
|
|
420
|
+
bool hasItem, shouldShow;
|
|
421
|
+
int firstIndex = -1, lastIndex = -1;
|
|
422
|
+
|
|
423
|
+
for (var i = 0; i < this.dataCount; i++)
|
|
424
|
+
{
|
|
425
|
+
hasItem = this.managedItems[i].item != null;
|
|
426
|
+
shouldShow = this.ShouldItemSeenAtIndex(i);
|
|
427
|
+
|
|
428
|
+
if (shouldShow)
|
|
429
|
+
{
|
|
430
|
+
if (firstIndex == -1)
|
|
431
|
+
{
|
|
432
|
+
firstIndex = i;
|
|
433
|
+
}
|
|
434
|
+
|
|
435
|
+
lastIndex = i;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
if (hasItem && shouldShow)
|
|
439
|
+
{
|
|
440
|
+
// 应显示且已显示
|
|
441
|
+
this.SetDataForItemAtIndex(this.managedItems[i].item, i);
|
|
442
|
+
continue;
|
|
443
|
+
}
|
|
444
|
+
|
|
445
|
+
if (hasItem == shouldShow)
|
|
446
|
+
{
|
|
447
|
+
// 不应显示且未显示
|
|
448
|
+
// if (firstIndex != -1)
|
|
449
|
+
// {
|
|
450
|
+
// // 已经遍历完所有要显示的了 后边的先跳过
|
|
451
|
+
// break;
|
|
452
|
+
// }
|
|
453
|
+
continue;
|
|
454
|
+
}
|
|
455
|
+
|
|
456
|
+
if (hasItem && !shouldShow)
|
|
457
|
+
{
|
|
458
|
+
// 不该显示 但是有
|
|
459
|
+
this.RecycleOldItem(this.managedItems[i].item);
|
|
460
|
+
this.managedItems[i].item = null;
|
|
461
|
+
continue;
|
|
462
|
+
}
|
|
463
|
+
|
|
464
|
+
if (shouldShow && !hasItem)
|
|
465
|
+
{
|
|
466
|
+
// 需要显示 但是没有
|
|
467
|
+
RectTransform item = this.GetNewItem(i);
|
|
468
|
+
this.OnGetItemForDataIndex(item, i);
|
|
469
|
+
this.managedItems[i].item = item;
|
|
470
|
+
continue;
|
|
471
|
+
}
|
|
472
|
+
}
|
|
473
|
+
|
|
474
|
+
// content.localPosition = Vector2.zero;
|
|
475
|
+
this.criticalItemIndex[CriticalItemType.UpToHide] = firstIndex;
|
|
476
|
+
this.criticalItemIndex[CriticalItemType.DownToHide] = lastIndex;
|
|
477
|
+
this.criticalItemIndex[CriticalItemType.UpToShow] = Mathf.Max(firstIndex - 1, 0);
|
|
478
|
+
this.criticalItemIndex[CriticalItemType.DownToShow] = Mathf.Min(lastIndex + 1, this.dataCount - 1);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
private RectTransform GetCriticalItem(int type)
|
|
482
|
+
{
|
|
483
|
+
var index = this.criticalItemIndex[type];
|
|
484
|
+
if (index >= 0 && index < this.dataCount)
|
|
485
|
+
{
|
|
486
|
+
return this.managedItems[index].item;
|
|
487
|
+
}
|
|
488
|
+
|
|
489
|
+
return null;
|
|
490
|
+
}
|
|
491
|
+
|
|
492
|
+
private void UpdateCriticalItems()
|
|
493
|
+
{
|
|
494
|
+
var dirty = true;
|
|
495
|
+
|
|
496
|
+
while (dirty)
|
|
497
|
+
{
|
|
498
|
+
dirty = false;
|
|
499
|
+
|
|
500
|
+
for (int i = CriticalItemType.UpToHide; i <= CriticalItemType.DownToShow; i++)
|
|
501
|
+
{
|
|
502
|
+
if (i <= CriticalItemType.DownToHide)
|
|
503
|
+
{
|
|
504
|
+
// 隐藏离开可见区域的item
|
|
505
|
+
dirty = dirty || this.CheckAndHideItem(i);
|
|
506
|
+
}
|
|
507
|
+
else
|
|
508
|
+
{
|
|
509
|
+
// 显示进入可见区域的item
|
|
510
|
+
dirty = dirty || this.CheckAndShowItem(i);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
}
|
|
515
|
+
|
|
516
|
+
private bool CheckAndHideItem(int criticalItemType)
|
|
517
|
+
{
|
|
518
|
+
RectTransform item = this.GetCriticalItem(criticalItemType);
|
|
519
|
+
var criticalIndex = this.criticalItemIndex[criticalItemType];
|
|
520
|
+
if (item != null && !this.ShouldItemSeenAtIndex(criticalIndex))
|
|
521
|
+
{
|
|
522
|
+
this.RecycleOldItem(item);
|
|
523
|
+
this.managedItems[criticalIndex].item = null;
|
|
524
|
+
|
|
525
|
+
if (criticalItemType == CriticalItemType.UpToHide)
|
|
526
|
+
{
|
|
527
|
+
// 最上隐藏了一个
|
|
528
|
+
this.criticalItemIndex[criticalItemType + 2] = Mathf.Max(criticalIndex, this.criticalItemIndex[criticalItemType + 2]);
|
|
529
|
+
this.criticalItemIndex[criticalItemType]++;
|
|
530
|
+
}
|
|
531
|
+
else
|
|
532
|
+
{
|
|
533
|
+
// 最下隐藏了一个
|
|
534
|
+
this.criticalItemIndex[criticalItemType + 2] = Mathf.Min(criticalIndex, this.criticalItemIndex[criticalItemType + 2]);
|
|
535
|
+
this.criticalItemIndex[criticalItemType]--;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
this.criticalItemIndex[criticalItemType] = Mathf.Clamp(this.criticalItemIndex[criticalItemType], 0, this.dataCount - 1);
|
|
539
|
+
|
|
540
|
+
if (this.criticalItemIndex[CriticalItemType.UpToHide] > this.criticalItemIndex[CriticalItemType.DownToHide])
|
|
541
|
+
{
|
|
542
|
+
// 偶然的情况 拖拽超出一屏
|
|
543
|
+
this.ResetCriticalItems();
|
|
544
|
+
return false;
|
|
545
|
+
}
|
|
546
|
+
|
|
547
|
+
return true;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return false;
|
|
551
|
+
}
|
|
552
|
+
|
|
553
|
+
private bool CheckAndShowItem(int criticalItemType)
|
|
554
|
+
{
|
|
555
|
+
RectTransform item = this.GetCriticalItem(criticalItemType);
|
|
556
|
+
var criticalIndex = this.criticalItemIndex[criticalItemType];
|
|
557
|
+
|
|
558
|
+
if (item == null && this.ShouldItemSeenAtIndex(criticalIndex))
|
|
559
|
+
{
|
|
560
|
+
RectTransform newItem = this.GetNewItem(criticalIndex);
|
|
561
|
+
this.OnGetItemForDataIndex(newItem, criticalIndex);
|
|
562
|
+
this.managedItems[criticalIndex].item = newItem;
|
|
563
|
+
|
|
564
|
+
if (criticalItemType == CriticalItemType.UpToShow)
|
|
565
|
+
{
|
|
566
|
+
// 最上显示了一个
|
|
567
|
+
this.criticalItemIndex[criticalItemType - 2] = Mathf.Min(criticalIndex, this.criticalItemIndex[criticalItemType - 2]);
|
|
568
|
+
this.criticalItemIndex[criticalItemType]--;
|
|
569
|
+
}
|
|
570
|
+
else
|
|
571
|
+
{
|
|
572
|
+
// 最下显示了一个
|
|
573
|
+
this.criticalItemIndex[criticalItemType - 2] = Mathf.Max(criticalIndex, this.criticalItemIndex[criticalItemType - 2]);
|
|
574
|
+
this.criticalItemIndex[criticalItemType]++;
|
|
575
|
+
}
|
|
576
|
+
|
|
577
|
+
this.criticalItemIndex[criticalItemType] = Mathf.Clamp(this.criticalItemIndex[criticalItemType], 0, this.dataCount - 1);
|
|
578
|
+
|
|
579
|
+
if (this.criticalItemIndex[CriticalItemType.UpToShow] >= this.criticalItemIndex[CriticalItemType.DownToShow])
|
|
580
|
+
{
|
|
581
|
+
// 偶然的情况 拖拽超出一屏
|
|
582
|
+
this.ResetCriticalItems();
|
|
583
|
+
return false;
|
|
584
|
+
}
|
|
585
|
+
|
|
586
|
+
return true;
|
|
587
|
+
}
|
|
588
|
+
|
|
589
|
+
return false;
|
|
590
|
+
}
|
|
591
|
+
|
|
592
|
+
private bool ShouldItemSeenAtIndex(int index)
|
|
593
|
+
{
|
|
594
|
+
if (index < 0 || index >= this.dataCount)
|
|
595
|
+
{
|
|
596
|
+
return false;
|
|
597
|
+
}
|
|
598
|
+
|
|
599
|
+
this.EnsureItemRect(index);
|
|
600
|
+
return new Rect(this.refRect.position - this.content.anchoredPosition, this.refRect.size).Overlaps(this.managedItems[index].rect);
|
|
601
|
+
}
|
|
602
|
+
|
|
603
|
+
private bool ShouldItemFullySeenAtIndex(int index)
|
|
604
|
+
{
|
|
605
|
+
if (index < 0 || index >= this.dataCount)
|
|
606
|
+
{
|
|
607
|
+
return false;
|
|
608
|
+
}
|
|
609
|
+
|
|
610
|
+
this.EnsureItemRect(index);
|
|
611
|
+
return this.IsRectContains(new Rect(this.refRect.position - this.content.anchoredPosition, this.refRect.size), this.managedItems[index].rect);
|
|
612
|
+
}
|
|
613
|
+
|
|
614
|
+
private bool IsRectContains(Rect outRect, Rect inRect, bool bothDimensions = false)
|
|
615
|
+
{
|
|
616
|
+
if (bothDimensions)
|
|
617
|
+
{
|
|
618
|
+
var xContains = (outRect.xMax >= inRect.xMax) && (outRect.xMin <= inRect.xMin);
|
|
619
|
+
var yContains = (outRect.yMax >= inRect.yMax) && (outRect.yMin <= inRect.yMin);
|
|
620
|
+
return xContains && yContains;
|
|
621
|
+
}
|
|
622
|
+
else
|
|
623
|
+
{
|
|
624
|
+
var dir = (int)this.layoutType & flagScrollDirection;
|
|
625
|
+
if (dir == 1)
|
|
626
|
+
{
|
|
627
|
+
// 垂直滚动 只计算y向
|
|
628
|
+
return (outRect.yMax >= inRect.yMax) && (outRect.yMin <= inRect.yMin);
|
|
629
|
+
}
|
|
630
|
+
else
|
|
631
|
+
{
|
|
632
|
+
// = 0
|
|
633
|
+
// 水平滚动 只计算x向
|
|
634
|
+
return (outRect.xMax >= inRect.xMax) && (outRect.xMin <= inRect.xMin);
|
|
635
|
+
}
|
|
636
|
+
}
|
|
637
|
+
}
|
|
638
|
+
|
|
639
|
+
private void InitPool()
|
|
640
|
+
{
|
|
641
|
+
var poolNode = new GameObject("POOL");
|
|
642
|
+
poolNode.SetActive(false);
|
|
643
|
+
poolNode.transform.SetParent(this.transform, false);
|
|
644
|
+
this.itemPool = new SimpleObjPool<RectTransform>(
|
|
645
|
+
this.poolSize,
|
|
646
|
+
(RectTransform item) =>
|
|
647
|
+
{
|
|
648
|
+
item.transform.SetParent(poolNode.transform, false);
|
|
649
|
+
},
|
|
650
|
+
() =>
|
|
651
|
+
{
|
|
652
|
+
GameObject itemObj = Instantiate(this.itemTemplate.gameObject);
|
|
653
|
+
RectTransform item = itemObj.GetComponent<RectTransform>();
|
|
654
|
+
itemObj.transform.SetParent(poolNode.transform, false);
|
|
655
|
+
|
|
656
|
+
item.anchorMin = Vector2.up;
|
|
657
|
+
item.anchorMax = Vector2.up;
|
|
658
|
+
item.pivot = Vector2.zero;
|
|
659
|
+
|
|
660
|
+
itemObj.SetActive(true);
|
|
661
|
+
return item;
|
|
662
|
+
});
|
|
663
|
+
}
|
|
664
|
+
|
|
665
|
+
private void OnGetItemForDataIndex(RectTransform item, int index)
|
|
666
|
+
{
|
|
667
|
+
this.SetDataForItemAtIndex(item, index);
|
|
668
|
+
item.transform.SetParent(this.content, false);
|
|
669
|
+
}
|
|
670
|
+
|
|
671
|
+
private void SetDataForItemAtIndex(RectTransform item, int index)
|
|
672
|
+
{
|
|
673
|
+
if (this.updateFunc != null)
|
|
674
|
+
{
|
|
675
|
+
this.updateFunc(index, item);
|
|
676
|
+
}
|
|
677
|
+
|
|
678
|
+
this.SetPosForItemAtIndex(item, index);
|
|
679
|
+
}
|
|
680
|
+
|
|
681
|
+
private void SetPosForItemAtIndex(RectTransform item, int index)
|
|
682
|
+
{
|
|
683
|
+
this.EnsureItemRect(index);
|
|
684
|
+
Rect r = this.managedItems[index].rect;
|
|
685
|
+
item.localPosition = r.position;
|
|
686
|
+
item.sizeDelta = r.size;
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
private Vector2 GetItemSize(int index)
|
|
690
|
+
{
|
|
691
|
+
if (index >= 0 && index <= this.dataCount)
|
|
692
|
+
{
|
|
693
|
+
if (this.itemSizeFunc != null)
|
|
694
|
+
{
|
|
695
|
+
return this.itemSizeFunc(index);
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
return this.defaultItemSize;
|
|
700
|
+
}
|
|
701
|
+
|
|
702
|
+
private RectTransform GetNewItem(int index)
|
|
703
|
+
{
|
|
704
|
+
RectTransform item;
|
|
705
|
+
if (this.itemGetFunc != null)
|
|
706
|
+
{
|
|
707
|
+
item = this.itemGetFunc(index);
|
|
708
|
+
}
|
|
709
|
+
else
|
|
710
|
+
{
|
|
711
|
+
item = this.itemPool.Get();
|
|
712
|
+
}
|
|
713
|
+
|
|
714
|
+
return item;
|
|
715
|
+
}
|
|
716
|
+
|
|
717
|
+
private void RecycleOldItem(RectTransform item)
|
|
718
|
+
{
|
|
719
|
+
if (this.itemRecycleFunc != null)
|
|
720
|
+
{
|
|
721
|
+
this.itemRecycleFunc(item);
|
|
722
|
+
}
|
|
723
|
+
else
|
|
724
|
+
{
|
|
725
|
+
this.itemPool.Recycle(item);
|
|
726
|
+
}
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
private void InitScrollView()
|
|
730
|
+
{
|
|
731
|
+
this.initialized = true;
|
|
732
|
+
|
|
733
|
+
// 根据设置来控制原ScrollRect的滚动方向
|
|
734
|
+
var dir = (int)this.layoutType & flagScrollDirection;
|
|
735
|
+
this.vertical = dir == 1;
|
|
736
|
+
this.horizontal = dir == 0;
|
|
737
|
+
|
|
738
|
+
this.content.pivot = Vector2.up;
|
|
739
|
+
this.content.anchorMin = Vector2.up;
|
|
740
|
+
this.content.anchorMax = Vector2.up;
|
|
741
|
+
this.content.anchoredPosition = Vector2.zero;
|
|
742
|
+
|
|
743
|
+
this.InitPool();
|
|
744
|
+
this.UpdateRefRect();
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
// refRect是在Content节点下的 viewport的 rect
|
|
748
|
+
private void UpdateRefRect()
|
|
749
|
+
{
|
|
750
|
+
/*
|
|
751
|
+
* WorldCorners
|
|
752
|
+
*
|
|
753
|
+
* 1 ------- 2
|
|
754
|
+
* | |
|
|
755
|
+
* | |
|
|
756
|
+
* 0 ------- 3
|
|
757
|
+
*
|
|
758
|
+
*/
|
|
759
|
+
|
|
760
|
+
if (!CanvasUpdateRegistry.IsRebuildingLayout())
|
|
761
|
+
{
|
|
762
|
+
Canvas.ForceUpdateCanvases();
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
this.viewRect.GetWorldCorners(this.viewWorldConers);
|
|
766
|
+
this.rectCorners[0] = this.content.transform.InverseTransformPoint(this.viewWorldConers[0]);
|
|
767
|
+
this.rectCorners[1] = this.content.transform.InverseTransformPoint(this.viewWorldConers[2]);
|
|
768
|
+
this.refRect = new Rect((Vector2)this.rectCorners[0] - this.content.anchoredPosition, this.rectCorners[1] - this.rectCorners[0]);
|
|
769
|
+
}
|
|
770
|
+
|
|
771
|
+
private void MovePos(ref Vector2 pos, Vector2 size)
|
|
772
|
+
{
|
|
773
|
+
// 注意 所有的rect都是左下角为基准
|
|
774
|
+
switch (this.layoutType)
|
|
775
|
+
{
|
|
776
|
+
case ItemLayoutType.Vertical:
|
|
777
|
+
// 垂直方向 向下移动
|
|
778
|
+
pos.y -= size.y;
|
|
779
|
+
break;
|
|
780
|
+
case ItemLayoutType.Horizontal:
|
|
781
|
+
// 水平方向 向右移动
|
|
782
|
+
pos.x += size.x;
|
|
783
|
+
break;
|
|
784
|
+
case ItemLayoutType.VerticalThenHorizontal:
|
|
785
|
+
pos.y -= size.y;
|
|
786
|
+
if (pos.y <= -this.refRect.height)
|
|
787
|
+
{
|
|
788
|
+
pos.y = 0;
|
|
789
|
+
pos.x += size.x;
|
|
790
|
+
}
|
|
791
|
+
|
|
792
|
+
break;
|
|
793
|
+
case ItemLayoutType.HorizontalThenVertical:
|
|
794
|
+
pos.x += size.x;
|
|
795
|
+
if (pos.x >= this.refRect.width)
|
|
796
|
+
{
|
|
797
|
+
pos.x = 0;
|
|
798
|
+
pos.y -= size.y;
|
|
799
|
+
}
|
|
800
|
+
|
|
801
|
+
break;
|
|
802
|
+
default:
|
|
803
|
+
break;
|
|
804
|
+
}
|
|
805
|
+
}
|
|
806
|
+
|
|
807
|
+
// const int 代替 enum 减少 (int)和(CriticalItemType)转换
|
|
808
|
+
protected static class CriticalItemType
|
|
809
|
+
{
|
|
810
|
+
public static byte UpToHide = 0;
|
|
811
|
+
public static byte DownToHide = 1;
|
|
812
|
+
public static byte UpToShow = 2;
|
|
813
|
+
public static byte DownToShow = 3;
|
|
814
|
+
}
|
|
815
|
+
|
|
816
|
+
private class ScrollItemWithRect
|
|
817
|
+
{
|
|
818
|
+
// scroll item 身上的 RectTransform组件
|
|
819
|
+
public RectTransform item;
|
|
820
|
+
|
|
821
|
+
// scroll item 在scrollview中的位置
|
|
822
|
+
public Rect rect;
|
|
823
|
+
|
|
824
|
+
// rect 是否需要更新
|
|
825
|
+
public bool rectDirty = true;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
}
|