-
Notifications
You must be signed in to change notification settings - Fork 2
/
RecyclingSystem.cs
165 lines (138 loc) · 4.84 KB
/
RecyclingSystem.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
//
// Copyright (C) 2021 LimeVista
// Author: LimeVista(https://github.com/LimeVista/RecyclableScrollRectX)
//
// This library is free software; you can redistribute it and/or modify
// it under the terms of the The MIT License (MIT).
//
// This library is distributed in the hope that it will be useful, but
// WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
// See The MIT License (MIT) for more details.
//
// You should have received a copy of The MIT License (MIT)
// along with this library.
//
using System;
using System.Collections;
using UnityEngine;
namespace RecyclableScrollRectX
{
/// <summary>
/// 列表资源回收系统
/// </summary>
public abstract class RecyclingSystem
{
#region 接口
/// <summary>
/// 数据源
/// </summary>
public interface IDataSource
{
/// <summary>
/// 单元格有单原型(Zygote)模式
/// 这种情况下决定是否有且仅有一个类型 <see cref="GetCellType"/>
/// </summary>
bool SingleZygoteMode { get; }
/// <summary>
/// 单元格个数
/// </summary>
int GetCellCount();
/// <summary>
/// 获取单元格细胞原型,一般情况下为 预制体(prefab),且未执行 GameObject.Instantiate()
/// 系统会对此数据返回结果进行缓存
/// </summary>
/// <param name="type">类型</param>
/// <returns>预制体</returns>
RectTransform GetCellZygote(int type);
/// <summary>
/// 获取单元格类型
/// <see cref="SingleZygoteMode"/> 开启时,请返回固定值
/// </summary>
/// <param name="index">索引</param>
/// <returns>单元格类型</returns>
int GetCellType(int index);
/// <summary>
/// 绑定单元格
/// </summary>
/// <param name="cell">单元格</param>
/// <param name="index">索引</param>
void OnBindCell(ICell cell, int index);
}
/// <summary>
/// 单元格
/// </summary>
public interface ICell
{
// 单元格接口
}
#endregion
#region 公开成员、属性
/// <summary>
/// 数据源
/// </summary>
public IDataSource DataSource
{
get => Delegate.DataSource;
protected set => Delegate.DataSource = value;
}
/// <summary>
/// 视口
/// </summary>
public RectTransform Viewport
{
get => Delegate.Viewport;
protected set => Delegate.Viewport = value;
}
/// <summary>
/// 内容区域
/// </summary>
public RectTransform Content
{
get => Delegate.Content;
protected set => Delegate.Content = value;
}
/// <summary>
/// 布局管理器
/// </summary>
public LayoutManager LayoutManager
{
get => Delegate.LayoutManager;
protected set => Delegate.LayoutManager = value;
}
#endregion
#region 公开方法
/// <summary>
/// 使用协程初始化
/// </summary>
/// <param name="onInitialized">初始化完成回调</param>
/// <returns>协程发生器</returns>
public abstract IEnumerator InitCoroutine(Action onInitialized);
/// <summary>
/// <see cref="AbsRecyclableScrollRect.DataSetChanged()"/>
/// 如需使用,请调用 <see cref="AbsRecyclableScrollRect.DataSetChanged()"/>
/// </summary>
/// <param name="scrollRect">滑动列表</param>
public abstract void OnDataSetChanged(AbsRecyclableScrollRect scrollRect);
/// <summary>
/// <see cref="AbsRecyclableScrollRect.ScrollToNormalizedPosition(float)"/>
/// 如需使用,请调用 <see cref="AbsRecyclableScrollRect.ScrollToNormalizedPosition(float)"/>
/// </summary>
/// <param name="scrollRect">滑动列表</param>
/// <param name="normalized">基准位置</param>
public abstract void OnScrollToNormalizedPosition(AbsRecyclableScrollRect scrollRect, float normalized);
#endregion
#region 保护成员、属性
/// <summary>
/// 数据持有者
/// </summary>
protected readonly RecyclingSystemDelegate Delegate = new RecyclingSystemDelegate();
#endregion
#region 内部成员、属性
/// <summary>
/// 内部成员访问代理
/// </summary>
internal RecyclingSystemDelegate InternalDelegate => Delegate;
#endregion
}
}