Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 2e9d02a

Browse files
committed
add ScrollViewEx
1 parent a8db3ee commit 2e9d02a

File tree

9 files changed

+2087
-352
lines changed

9 files changed

+2087
-352
lines changed

‎Assets/ScrollView/Editor/ScrollViewEditor.cs‎

Lines changed: 36 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -25,40 +25,45 @@ protected override void OnEnable()
2525
defaultItemSize = serializedObject.FindProperty("defaultItemSize");
2626
layoutType = serializedObject.FindProperty("m_layoutType");
2727
}
28-
28+
29+
GUIStyle m_caption;
30+
GUIStyle caption
31+
{
32+
get
33+
{
34+
if(m_caption == null)
35+
{
36+
m_caption = new GUIStyle { richText = true, alignment = TextAnchor.MiddleCenter };
37+
}
38+
return m_caption;
39+
}
40+
}
2941

3042
public override void OnInspectorGUI()
3143
{
3244
serializedObject.Update();
3345

34-
EditorGUILayout.Separator();
35-
36-
EditorGUILayout.LabelField("<color=#0000FF><b>Additional configs</b></color>", new GUIStyle { richText = true });
37-
38-
EditorGUI.indentLevel++;
46+
EditorGUILayout.BeginVertical("box");
47+
EditorGUILayout.LabelField("<b>Additional configs</b>", caption);
48+
EditorGUILayout.Space(5);
49+
DrawConfigInfo();
50+
serializedObject.ApplyModifiedProperties();
51+
EditorGUILayout.EndVertical();
3952

53+
EditorGUILayout.BeginVertical("box");
54+
EditorGUILayout.LabelField("<b>For original ScrollRect</b>", caption);
55+
EditorGUILayout.Space(5);
56+
base.OnInspectorGUI();
57+
EditorGUILayout.EndVertical();
58+
}
59+
60+
protected virtual void DrawConfigInfo()
61+
{
4062
EditorGUILayout.PropertyField(itemTemplate);
4163
EditorGUILayout.PropertyField(poolSize);
4264
EditorGUILayout.PropertyField(defaultItemSize);
4365
layoutType.intValue = (int)(ScrollView.ItemLayoutType)EditorGUILayout.EnumPopup("layoutType", (ScrollView.ItemLayoutType)layoutType.intValue);
44-
45-
46-
serializedObject.ApplyModifiedProperties();
47-
48-
EditorGUILayout.Separator();
49-
50-
EditorGUI.indentLevel--;
51-
52-
EditorGUILayout.LabelField("<color=#0000FF><b>For original ScrollRect</b></color>", new GUIStyle { richText = true });
53-
54-
EditorGUI.indentLevel++;
55-
56-
base.OnInspectorGUI();
57-
58-
EditorGUI.indentLevel--;
59-
6066
}
61-
6267

6368

6469

@@ -75,10 +80,15 @@ public override void OnInspectorGUI()
7580

7681

7782

78-
[MenuItem("GameObject/UI/Dynamic Scroll View", false, 90)]
83+
[MenuItem("GameObject/UI/ScrollView", false, 90)]
7984
static public void AddScrollView(MenuCommand menuCommand)
8085
{
81-
GameObject root = CreateUIElementRoot("Dynamic Scroll View", new Vector2(200, 200));
86+
InternalAddScrollView<ScrollView>(menuCommand);
87+
}
88+
89+
protected static void InternalAddScrollView<T>(MenuCommand menuCommand) where T : ScrollView
90+
{
91+
GameObject root = CreateUIElementRoot(typeof(T).Name, new Vector2(200, 200));
8292

8393
GameObject viewport = CreateUIObject("Viewport", root);
8494
GameObject content = CreateUIObject("Content", viewport);
@@ -125,7 +135,7 @@ static public void AddScrollView(MenuCommand menuCommand)
125135
contentRect.sizeDelta = new Vector2(0, 300);
126136
contentRect.pivot = Vector2.up;
127137

128-
ScrollView scrollRect = root.AddComponent<ScrollView>();
138+
ScrollView scrollRect = root.AddComponent<T>();
129139
scrollRect.content = contentRect;
130140
scrollRect.viewport = viewportRect;
131141
scrollRect.horizontalScrollbar = hScrollbar.GetComponent<Scrollbar>();
@@ -183,7 +193,6 @@ static GameObject CreateScrollbar()
183193
return scrollbarRoot;
184194
}
185195

186-
187196
static GameObject CreateUIElementRoot(string name, Vector2 size)
188197
{
189198
GameObject child = new GameObject(name);
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
using UnityEditor;
2+
using UnityEditor.UI;
3+
using UnityEngine;
4+
using UnityEngine.UI;
5+
6+
namespace AillieoUtils
7+
{
8+
9+
[CustomEditor(typeof(ScrollViewEx))]
10+
public class ScrollViewExEditor : ScrollViewEditor
11+
{
12+
SerializedProperty pageSize;
13+
14+
15+
protected override void OnEnable()
16+
{
17+
base.OnEnable();
18+
pageSize = serializedObject.FindProperty("m_pageSize");
19+
}
20+
21+
protected override void DrawConfigInfo()
22+
{
23+
base.DrawConfigInfo();
24+
EditorGUILayout.PropertyField(pageSize);
25+
}
26+
27+
[MenuItem("GameObject/UI/ScrollViewEx", false, 90)]
28+
static public void AddScrollViewEx(MenuCommand menuCommand)
29+
{
30+
InternalAddScrollView<ScrollViewEx>(menuCommand);
31+
}
32+
}
33+
}

‎Assets/ScrollView/Editor/ScrollViewExEditor.cs.meta‎

Lines changed: 12 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Assets/ScrollView/ScrollView.cs‎

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,24 +37,24 @@ public enum ItemLayoutType
3737
VerticalThenHorizontal = 4, // 0100
3838
HorizontalThenVertical = 5, // 0101
3939
}
40-
const int flagScrollDirection = 1; // 0001
40+
publicconst int flagScrollDirection = 1; // 0001
4141

4242

4343
[SerializeField]
4444
ItemLayoutType m_layoutType = ItemLayoutType.Vertical;
45-
ItemLayoutType layoutType { get { return m_layoutType; } }
45+
protectedItemLayoutType layoutType { get { return m_layoutType; } }
4646

4747

4848
// const int 代替 enum 减少 (int)和(CriticalItemType)转换
49-
static class CriticalItemType
49+
protectedstatic class CriticalItemType
5050
{
5151
public const int UpToHide = 0;
5252
public const int DownToHide = 1;
5353
public const int UpToShow = 2;
5454
public const int DownToShow = 3;
5555
}
5656
// 只保存4个临界index
57-
int[] criticalItemIndex = new int[4];
57+
protectedint[] criticalItemIndex = new int[4];
5858
Rect refRect;
5959

6060

@@ -86,17 +86,17 @@ static class CriticalItemType
8686
private bool initialized = false;
8787
private bool willUpdateData = false;
8888

89-
public void SetUpdateFunc(Action<int,RectTransform> func)
89+
public virtualvoid SetUpdateFunc(Action<int,RectTransform> func)
9090
{
9191
updateFunc = func;
9292
}
9393

94-
public void SetItemSizeFunc(Func<int, Vector2> func)
94+
public virtualvoid SetItemSizeFunc(Func<int, Vector2> func)
9595
{
9696
itemSizeFunc = func;
9797
}
9898

99-
public void SetItemCountFunc(Func<int> func)
99+
public virtualvoid SetItemCountFunc(Func<int> func)
100100
{
101101
itemCountFunc = func;
102102
}
@@ -185,7 +185,7 @@ private void InternalUpdateData()
185185
}
186186
else //减少 保留空位 避免GC
187187
{
188-
for(int i = 0, count = managedItems.Count; i < count; ++i)
188+
for(int i = 0, count = managedItems.Count; i < count; ++i)
189189
{
190190
// 重置所有rect
191191
managedItems[i].rectDirty = true;
@@ -202,6 +202,14 @@ private void InternalUpdateData()
202202
}
203203
}
204204
}
205+
else
206+
{
207+
for (int i = 0, count = managedItems.Count; i < count; ++i)
208+
{
209+
// 重置所有rect
210+
managedItems[i].rectDirty = true;
211+
}
212+
}
205213

206214
m_dataCount = newDataCount;
207215

@@ -718,6 +726,15 @@ protected override void OnDestroy()
718726
}
719727
}
720728

729+
protected Rect GetItemLocalRect(int index)
730+
{
731+
if(index >= 0 && index < m_dataCount)
732+
{
733+
EnsureItemRect(index);
734+
return managedItems[index].rect;
735+
}
736+
return new Rect();
737+
}
721738
}
722739

723740
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /