Showing
9 changed files
with
29 additions
and
588 deletions
| @@ -51,17 +51,14 @@ | @@ -51,17 +51,14 @@ | ||
| 51 | <Compile Include="Assets\Scripts\UI\Test3.cs" /> | 51 | <Compile Include="Assets\Scripts\UI\Test3.cs" /> |
| 52 | <Compile Include="Assets\Scripts\Common\Singleton.cs" /> | 52 | <Compile Include="Assets\Scripts\Common\Singleton.cs" /> |
| 53 | <Compile Include="Assets\Scripts\Manager\UIManager.cs" /> | 53 | <Compile Include="Assets\Scripts\Manager\UIManager.cs" /> |
| 54 | - <Compile Include="Assets\Scripts\ScrollView\ItemUI.cs" /> | ||
| 55 | <Compile Include="Assets\Scripts\UI\Test2.cs" /> | 54 | <Compile Include="Assets\Scripts\UI\Test2.cs" /> |
| 56 | <Compile Include="Assets\Scripts\UI\ItemTest.cs" /> | 55 | <Compile Include="Assets\Scripts\UI\ItemTest.cs" /> |
| 57 | <Compile Include="Assets\Scripts\Common\UIBase.cs" /> | 56 | <Compile Include="Assets\Scripts\Common\UIBase.cs" /> |
| 58 | <Compile Include="Assets\Scripts\Main.cs" /> | 57 | <Compile Include="Assets\Scripts\Main.cs" /> |
| 59 | <Compile Include="Assets\Scripts\UI\ItemTestPanel.cs" /> | 58 | <Compile Include="Assets\Scripts\UI\ItemTestPanel.cs" /> |
| 60 | <Compile Include="Assets\Scripts\UI\Test1.cs" /> | 59 | <Compile Include="Assets\Scripts\UI\Test1.cs" /> |
| 61 | - <Compile Include="Assets\Scripts\ScrollView\CustomListComponent.cs" /> | ||
| 62 | <Compile Include="Assets\Scripts\Common\TimeControl.cs" /> | 60 | <Compile Include="Assets\Scripts\Common\TimeControl.cs" /> |
| 63 | <Compile Include="Assets\Scripts\Manager\ResourcesManager.cs" /> | 61 | <Compile Include="Assets\Scripts\Manager\ResourcesManager.cs" /> |
| 64 | - <Compile Include="Assets\Scripts\ScrollViewTest.cs" /> | ||
| 65 | <Compile Include="Assets\Scripts\Manager\AudioManager.cs" /> | 62 | <Compile Include="Assets\Scripts\Manager\AudioManager.cs" /> |
| 66 | <Compile Include="Assets\Scripts\UI\TimeTest.cs" /> | 63 | <Compile Include="Assets\Scripts\UI\TimeTest.cs" /> |
| 67 | <Compile Include="Assets\Scripts\Manager\UIAnimation.cs" /> | 64 | <Compile Include="Assets\Scripts\Manager\UIAnimation.cs" /> |
| 1 | -using UnityEngine; | ||
| 2 | -using System.Collections.Generic; | ||
| 3 | - | ||
| 4 | -public enum ScrollDirection | ||
| 5 | -{ | ||
| 6 | - Horizontal, | ||
| 7 | - Vertical | ||
| 8 | -} | ||
| 9 | - | ||
| 10 | -public enum LoopMode | ||
| 11 | -{ | ||
| 12 | - Normal, | ||
| 13 | - InfiniteLoop | ||
| 14 | -} | ||
| 15 | - | ||
| 16 | -public enum SnapMode | ||
| 17 | -{ | ||
| 18 | - Free, | ||
| 19 | - CenterAligned | ||
| 20 | -} | ||
| 21 | - | ||
| 22 | -public enum DragMode | ||
| 23 | -{ | ||
| 24 | - FixedDistance, | ||
| 25 | - MouseDistance | ||
| 26 | -} | ||
| 27 | - | ||
| 28 | -public enum EasingType | ||
| 29 | -{ | ||
| 30 | - Linear, | ||
| 31 | - EaseIn, | ||
| 32 | - EaseOut, | ||
| 33 | - EaseInOut | ||
| 34 | -} | ||
| 35 | - | ||
| 36 | -public class CustomListComponent : MonoBehaviour | ||
| 37 | -{ | ||
| 38 | - [Header("基本设置")] [SerializeField] private ScrollDirection direction = ScrollDirection.Horizontal; | ||
| 39 | - [SerializeField] private LoopMode loopMode = LoopMode.InfiniteLoop; | ||
| 40 | - [SerializeField] private SnapMode snapMode = SnapMode.CenterAligned; | ||
| 41 | - [SerializeField] private DragMode dragMode = DragMode.MouseDistance; | ||
| 42 | - [SerializeField] private EasingType easingType = EasingType.EaseOut; | ||
| 43 | - | ||
| 44 | - [Header("Item设置")] [SerializeField] private GameObject itemPrefab; | ||
| 45 | - [SerializeField] private float itemSize = 100f; | ||
| 46 | - [SerializeField] private float spacing = 20f; | ||
| 47 | - | ||
| 48 | - [Header("动画设置")] [SerializeField] private float snapSpeed = 5f; | ||
| 49 | - [SerializeField] private float dragSensitivity = 1f; | ||
| 50 | - [SerializeField] private float fixedDragDistance = 50f; | ||
| 51 | - | ||
| 52 | - [Header("数据")] [SerializeField] private List<ItemData> itemDataList = new List<ItemData>(); | ||
| 53 | - | ||
| 54 | - private RectTransform rectTransform; | ||
| 55 | - private List<ItemInstance> activeItems = new List<ItemInstance>(); | ||
| 56 | - private float viewportSize; | ||
| 57 | - private int maxVisibleItems; | ||
| 58 | - private float totalContentSize; | ||
| 59 | - private float currentPosition; | ||
| 60 | - private float targetPosition; | ||
| 61 | - private Vector2 lastMousePosition; | ||
| 62 | - private bool isDragging; | ||
| 63 | - private int centerItemIndex; | ||
| 64 | - private float dragStartTime; | ||
| 65 | - private float dragStartPosition; | ||
| 66 | - | ||
| 67 | - [System.Serializable] | ||
| 68 | - public class ItemData | ||
| 69 | - { | ||
| 70 | - public string id; | ||
| 71 | - public string name; | ||
| 72 | - public Sprite icon; | ||
| 73 | - public object data; | ||
| 74 | - } | ||
| 75 | - | ||
| 76 | - private class ItemInstance | ||
| 77 | - { | ||
| 78 | - public GameObject gameObject; | ||
| 79 | - public RectTransform rectTransform; | ||
| 80 | - public int dataIndex; | ||
| 81 | - public ItemUI itemUI; | ||
| 82 | - } | ||
| 83 | - | ||
| 84 | - public delegate void CenterItemChangedHandler(int index, ItemData data); | ||
| 85 | - | ||
| 86 | - public event CenterItemChangedHandler OnCenterItemChanged; | ||
| 87 | - | ||
| 88 | - private void Awake() | ||
| 89 | - { | ||
| 90 | - rectTransform = GetComponent<RectTransform>(); | ||
| 91 | - CalculateViewportSize(); | ||
| 92 | - CalculateMaxVisibleItems(); | ||
| 93 | - InitializeItems(); | ||
| 94 | - } | ||
| 95 | - | ||
| 96 | - private void CalculateViewportSize() | ||
| 97 | - { | ||
| 98 | - if (direction == ScrollDirection.Horizontal) | ||
| 99 | - { | ||
| 100 | - viewportSize = rectTransform.rect.width; | ||
| 101 | - } | ||
| 102 | - else | ||
| 103 | - { | ||
| 104 | - viewportSize = rectTransform.rect.height; | ||
| 105 | - } | ||
| 106 | - } | ||
| 107 | - | ||
| 108 | - private void CalculateMaxVisibleItems() | ||
| 109 | - { | ||
| 110 | - // 计算最多需要多少个Item才能铺满视口 | ||
| 111 | - maxVisibleItems = Mathf.CeilToInt((viewportSize + spacing) / (itemSize + spacing)) + 2; | ||
| 112 | - Debug.Log($"最多可见Item数量: {maxVisibleItems}"); | ||
| 113 | - } | ||
| 114 | - | ||
| 115 | - private void InitializeItems() | ||
| 116 | - { | ||
| 117 | - // 清除现有Item | ||
| 118 | - foreach (var item in activeItems) | ||
| 119 | - { | ||
| 120 | - Destroy(item.gameObject); | ||
| 121 | - } | ||
| 122 | - | ||
| 123 | - activeItems.Clear(); | ||
| 124 | - | ||
| 125 | - // 创建必要的Item实例 | ||
| 126 | - for (int i = 0; i < maxVisibleItems; i++) | ||
| 127 | - { | ||
| 128 | - GameObject itemGO = Instantiate(itemPrefab, transform); | ||
| 129 | - ItemInstance item = new ItemInstance | ||
| 130 | - { | ||
| 131 | - gameObject = itemGO, | ||
| 132 | - rectTransform = itemGO.GetComponent<RectTransform>(), | ||
| 133 | - dataIndex = i % itemDataList.Count, | ||
| 134 | - itemUI = itemGO.GetComponent<ItemUI>() | ||
| 135 | - }; | ||
| 136 | - | ||
| 137 | - UpdateItemPosition(item, i); | ||
| 138 | - UpdateItemData(item); | ||
| 139 | - | ||
| 140 | - activeItems.Add(item); | ||
| 141 | - } | ||
| 142 | - | ||
| 143 | - // 计算总内容大小 | ||
| 144 | - totalContentSize = itemDataList.Count * (itemSize + spacing) - spacing; | ||
| 145 | - | ||
| 146 | - // 初始化位置 | ||
| 147 | - currentPosition = 0; | ||
| 148 | - targetPosition = 0; | ||
| 149 | - UpdateCenterItem(); | ||
| 150 | - } | ||
| 151 | - | ||
| 152 | - private void UpdateItemPosition(ItemInstance item, int index) | ||
| 153 | - { | ||
| 154 | - float position = index * (itemSize + spacing); | ||
| 155 | - | ||
| 156 | - if (direction == ScrollDirection.Horizontal) | ||
| 157 | - { | ||
| 158 | - item.rectTransform.anchoredPosition = new Vector2(position - currentPosition, 0); | ||
| 159 | - } | ||
| 160 | - else | ||
| 161 | - { | ||
| 162 | - item.rectTransform.anchoredPosition = new Vector2(0, -(position - currentPosition)); | ||
| 163 | - } | ||
| 164 | - } | ||
| 165 | - | ||
| 166 | - private void UpdateItemData(ItemInstance item) | ||
| 167 | - { | ||
| 168 | - if (item.itemUI != null && item.dataIndex < itemDataList.Count) | ||
| 169 | - { | ||
| 170 | - item.itemUI.SetData(itemDataList[item.dataIndex]); | ||
| 171 | - } | ||
| 172 | - } | ||
| 173 | - | ||
| 174 | - private void Update() | ||
| 175 | - { | ||
| 176 | - HandleInput(); | ||
| 177 | - UpdateScrollPosition(); | ||
| 178 | - UpdateItems(); | ||
| 179 | - } | ||
| 180 | - | ||
| 181 | - private void HandleInput() | ||
| 182 | - { | ||
| 183 | - if (Input.GetMouseButtonDown(0)) | ||
| 184 | - { | ||
| 185 | - if (RectTransformUtility.RectangleContainsScreenPoint(rectTransform, Input.mousePosition)) | ||
| 186 | - { | ||
| 187 | - isDragging = true; | ||
| 188 | - lastMousePosition = Input.mousePosition; | ||
| 189 | - dragStartTime = Time.time; | ||
| 190 | - dragStartPosition = currentPosition; | ||
| 191 | - } | ||
| 192 | - } | ||
| 193 | - | ||
| 194 | - if (Input.GetMouseButtonUp(0)) | ||
| 195 | - { | ||
| 196 | - if (isDragging) | ||
| 197 | - { | ||
| 198 | - isDragging = false; | ||
| 199 | - | ||
| 200 | - if (snapMode == SnapMode.CenterAligned) | ||
| 201 | - { | ||
| 202 | - SnapToNearestItem(); | ||
| 203 | - } | ||
| 204 | - } | ||
| 205 | - } | ||
| 206 | - | ||
| 207 | - if (isDragging) | ||
| 208 | - { | ||
| 209 | - Vector2 mouseDelta = Input.mousePosition - new Vector3(lastMousePosition.x, lastMousePosition.y, 0); | ||
| 210 | - lastMousePosition = Input.mousePosition; | ||
| 211 | - | ||
| 212 | - float dragAmount = direction == ScrollDirection.Horizontal ? mouseDelta.x : -mouseDelta.y; | ||
| 213 | - | ||
| 214 | - if (dragMode == DragMode.FixedDistance) | ||
| 215 | - { | ||
| 216 | - dragAmount = Mathf.Sign(dragAmount) * fixedDragDistance; | ||
| 217 | - } | ||
| 218 | - | ||
| 219 | - currentPosition -= dragAmount * dragSensitivity; | ||
| 220 | - | ||
| 221 | - // 处理边界 | ||
| 222 | - if (loopMode == LoopMode.Normal) | ||
| 223 | - { | ||
| 224 | - currentPosition = Mathf.Clamp(currentPosition, 0, Mathf.Max(0, totalContentSize - viewportSize)); | ||
| 225 | - } | ||
| 226 | - } | ||
| 227 | - } | ||
| 228 | - | ||
| 229 | - private void UpdateScrollPosition() | ||
| 230 | - { | ||
| 231 | - if (!isDragging && currentPosition != targetPosition) | ||
| 232 | - { | ||
| 233 | - float deltaTime = Time.deltaTime * snapSpeed; | ||
| 234 | - | ||
| 235 | - // 应用缓动函数 | ||
| 236 | - switch (easingType) | ||
| 237 | - { | ||
| 238 | - case EasingType.Linear: | ||
| 239 | - currentPosition = Mathf.Lerp(currentPosition, targetPosition, deltaTime); | ||
| 240 | - break; | ||
| 241 | - case EasingType.EaseIn: | ||
| 242 | - currentPosition = EaseIn(currentPosition, targetPosition, deltaTime); | ||
| 243 | - break; | ||
| 244 | - case EasingType.EaseOut: | ||
| 245 | - currentPosition = EaseOut(currentPosition, targetPosition, deltaTime); | ||
| 246 | - break; | ||
| 247 | - case EasingType.EaseInOut: | ||
| 248 | - currentPosition = EaseInOut(currentPosition, targetPosition, deltaTime); | ||
| 249 | - break; | ||
| 250 | - } | ||
| 251 | - | ||
| 252 | - if (Mathf.Abs(currentPosition - targetPosition) < 0.1f) | ||
| 253 | - { | ||
| 254 | - currentPosition = targetPosition; | ||
| 255 | - } | ||
| 256 | - } | ||
| 257 | - } | ||
| 258 | - | ||
| 259 | - private void UpdateItems() | ||
| 260 | - { | ||
| 261 | - if (loopMode == LoopMode.InfiniteLoop) | ||
| 262 | - { | ||
| 263 | - // 处理无限循环 | ||
| 264 | - foreach (var item in activeItems) | ||
| 265 | - { | ||
| 266 | - bool needsUpdate = false; | ||
| 267 | - | ||
| 268 | - if (direction == ScrollDirection.Horizontal) | ||
| 269 | - { | ||
| 270 | - float itemPos = item.rectTransform.anchoredPosition.x + currentPosition; | ||
| 271 | - | ||
| 272 | - // 如果Item超出左边界,移动到右侧 | ||
| 273 | - if (itemPos < -itemSize) | ||
| 274 | - { | ||
| 275 | - item.dataIndex = (item.dataIndex + activeItems.Count) % itemDataList.Count; | ||
| 276 | - needsUpdate = true; | ||
| 277 | - } | ||
| 278 | - // 如果Item超出右边界,移动到左侧 | ||
| 279 | - else if (itemPos > viewportSize) | ||
| 280 | - { | ||
| 281 | - item.dataIndex = (item.dataIndex - activeItems.Count + itemDataList.Count) % itemDataList.Count; | ||
| 282 | - needsUpdate = true; | ||
| 283 | - } | ||
| 284 | - } | ||
| 285 | - else | ||
| 286 | - { | ||
| 287 | - float itemPos = -(item.rectTransform.anchoredPosition.y - currentPosition); | ||
| 288 | - | ||
| 289 | - // 如果Item超出上边界,移动到下侧 | ||
| 290 | - if (itemPos < -itemSize) | ||
| 291 | - { | ||
| 292 | - item.dataIndex = (item.dataIndex + activeItems.Count) % itemDataList.Count; | ||
| 293 | - needsUpdate = true; | ||
| 294 | - } | ||
| 295 | - // 如果Item超出下边界,移动到上侧 | ||
| 296 | - else if (itemPos > viewportSize) | ||
| 297 | - { | ||
| 298 | - item.dataIndex = (item.dataIndex - activeItems.Count + itemDataList.Count) % itemDataList.Count; | ||
| 299 | - needsUpdate = true; | ||
| 300 | - } | ||
| 301 | - } | ||
| 302 | - | ||
| 303 | - if (needsUpdate) | ||
| 304 | - { | ||
| 305 | - UpdateItemData(item); | ||
| 306 | - | ||
| 307 | - // 重新计算位置 | ||
| 308 | - int virtualIndex = Mathf.FloorToInt(currentPosition / (itemSize + spacing)); | ||
| 309 | - virtualIndex = (virtualIndex + item.dataIndex) % itemDataList.Count; | ||
| 310 | - | ||
| 311 | - UpdateItemPosition(item, virtualIndex); | ||
| 312 | - } | ||
| 313 | - else | ||
| 314 | - { | ||
| 315 | - // 仅更新位置 | ||
| 316 | - UpdateItemPosition(item, | ||
| 317 | - Mathf.FloorToInt((item.rectTransform.anchoredPosition.x + currentPosition) / | ||
| 318 | - (itemSize + spacing))); | ||
| 319 | - } | ||
| 320 | - } | ||
| 321 | - } | ||
| 322 | - | ||
| 323 | - UpdateCenterItem(); | ||
| 324 | - } | ||
| 325 | - | ||
| 326 | - private void SnapToNearestItem() | ||
| 327 | - { | ||
| 328 | - if (itemDataList.Count == 0) return; | ||
| 329 | - | ||
| 330 | - // 计算最接近中心的Item | ||
| 331 | - float centerPos = viewportSize / 2; | ||
| 332 | - float closestDistance = float.MaxValue; | ||
| 333 | - int closestIndex = 0; | ||
| 334 | - | ||
| 335 | - foreach (var item in activeItems) | ||
| 336 | - { | ||
| 337 | - float itemPos = direction == ScrollDirection.Horizontal | ||
| 338 | - ? item.rectTransform.anchoredPosition.x + itemSize / 2 | ||
| 339 | - : -(item.rectTransform.anchoredPosition.y - itemSize / 2); | ||
| 340 | - | ||
| 341 | - float distance = Mathf.Abs(itemPos - centerPos); | ||
| 342 | - | ||
| 343 | - if (distance < closestDistance) | ||
| 344 | - { | ||
| 345 | - closestDistance = distance; | ||
| 346 | - closestIndex = item.dataIndex; | ||
| 347 | - } | ||
| 348 | - } | ||
| 349 | - | ||
| 350 | - // 设置目标位置 | ||
| 351 | - float targetPos = closestIndex * (itemSize + spacing); | ||
| 352 | - | ||
| 353 | - // 调整目标位置使选中的Item居中 | ||
| 354 | - if (direction == ScrollDirection.Horizontal) | ||
| 355 | - { | ||
| 356 | - targetPos -= (viewportSize - itemSize) / 2; | ||
| 357 | - } | ||
| 358 | - else | ||
| 359 | - { | ||
| 360 | - targetPos -= (viewportSize - itemSize) / 2; | ||
| 361 | - } | ||
| 362 | - | ||
| 363 | - // 限制在边界内 | ||
| 364 | - if (loopMode == LoopMode.Normal) | ||
| 365 | - { | ||
| 366 | - targetPos = Mathf.Clamp(targetPos, 0, Mathf.Max(0, totalContentSize - viewportSize)); | ||
| 367 | - } | ||
| 368 | - | ||
| 369 | - targetPosition = targetPos; | ||
| 370 | - } | ||
| 371 | - | ||
| 372 | - private void UpdateCenterItem() | ||
| 373 | - { | ||
| 374 | - float centerPos = viewportSize / 2; | ||
| 375 | - float closestDistance = float.MaxValue; | ||
| 376 | - int newCenterIndex = -1; | ||
| 377 | - | ||
| 378 | - foreach (var item in activeItems) | ||
| 379 | - { | ||
| 380 | - float itemPos = direction == ScrollDirection.Horizontal | ||
| 381 | - ? item.rectTransform.anchoredPosition.x + itemSize / 2 | ||
| 382 | - : -(item.rectTransform.anchoredPosition.y - itemSize / 2); | ||
| 383 | - | ||
| 384 | - float distance = Mathf.Abs(itemPos - centerPos); | ||
| 385 | - | ||
| 386 | - if (distance < closestDistance) | ||
| 387 | - { | ||
| 388 | - closestDistance = distance; | ||
| 389 | - newCenterIndex = item.dataIndex; | ||
| 390 | - } | ||
| 391 | - } | ||
| 392 | - | ||
| 393 | - if (newCenterIndex != centerItemIndex && newCenterIndex >= 0 && newCenterIndex < itemDataList.Count) | ||
| 394 | - { | ||
| 395 | - centerItemIndex = newCenterIndex; | ||
| 396 | - OnCenterItemChanged?.Invoke(centerItemIndex, itemDataList[centerItemIndex]); | ||
| 397 | - } | ||
| 398 | - } | ||
| 399 | - | ||
| 400 | - // 缓动函数 | ||
| 401 | - private float EaseIn(float start, float end, float value) | ||
| 402 | - { | ||
| 403 | - end -= start; | ||
| 404 | - return end * Mathf.Pow(value, 2) + start; | ||
| 405 | - } | ||
| 406 | - | ||
| 407 | - private float EaseOut(float start, float end, float value) | ||
| 408 | - { | ||
| 409 | - end -= start; | ||
| 410 | - return -end * value * (value - 2) + start; | ||
| 411 | - } | ||
| 412 | - | ||
| 413 | - private float EaseInOut(float start, float end, float value) | ||
| 414 | - { | ||
| 415 | - value /= 0.5f; | ||
| 416 | - end -= start; | ||
| 417 | - | ||
| 418 | - if (value < 1) | ||
| 419 | - { | ||
| 420 | - return end * 0.5f * Mathf.Pow(value, 2) + start; | ||
| 421 | - } | ||
| 422 | - | ||
| 423 | - value--; | ||
| 424 | - return -end * 0.5f * (value * (value - 2) - 1) + start; | ||
| 425 | - } | ||
| 426 | - | ||
| 427 | - // 公共方法 | ||
| 428 | - public void SetDirection(ScrollDirection newDirection) | ||
| 429 | - { | ||
| 430 | - direction = newDirection; | ||
| 431 | - CalculateViewportSize(); | ||
| 432 | - InitializeItems(); | ||
| 433 | - } | ||
| 434 | - | ||
| 435 | - public void SetLoopMode(LoopMode newMode) | ||
| 436 | - { | ||
| 437 | - loopMode = newMode; | ||
| 438 | - } | ||
| 439 | - | ||
| 440 | - public void SetSnapMode(SnapMode newMode) | ||
| 441 | - { | ||
| 442 | - snapMode = newMode; | ||
| 443 | - } | ||
| 444 | - | ||
| 445 | - public void SetDragMode(DragMode newMode) | ||
| 446 | - { | ||
| 447 | - dragMode = newMode; | ||
| 448 | - } | ||
| 449 | - | ||
| 450 | - public void SetEasingType(EasingType newType) | ||
| 451 | - { | ||
| 452 | - easingType = newType; | ||
| 453 | - } | ||
| 454 | - | ||
| 455 | - public void SetItemSize(float size) | ||
| 456 | - { | ||
| 457 | - itemSize = size; | ||
| 458 | - CalculateMaxVisibleItems(); | ||
| 459 | - InitializeItems(); | ||
| 460 | - } | ||
| 461 | - | ||
| 462 | - public void SetSpacing(float newSpacing) | ||
| 463 | - { | ||
| 464 | - spacing = newSpacing; | ||
| 465 | - CalculateMaxVisibleItems(); | ||
| 466 | - InitializeItems(); | ||
| 467 | - } | ||
| 468 | - | ||
| 469 | - public void SetItemData(List<ItemData> dataList) | ||
| 470 | - { | ||
| 471 | - itemDataList = dataList; | ||
| 472 | - CalculateMaxVisibleItems(); | ||
| 473 | - InitializeItems(); | ||
| 474 | - } | ||
| 475 | - | ||
| 476 | - public ItemData GetCenterItemData() | ||
| 477 | - { | ||
| 478 | - if (centerItemIndex >= 0 && centerItemIndex < itemDataList.Count) | ||
| 479 | - { | ||
| 480 | - return itemDataList[centerItemIndex]; | ||
| 481 | - } | ||
| 482 | - | ||
| 483 | - return null; | ||
| 484 | - } | ||
| 485 | -} |
Assets/Scripts/ScrollView/ItemUI.cs
deleted
100644 → 0
| 1 | -using UnityEngine; | ||
| 2 | -using UnityEngine.UI; | ||
| 3 | - | ||
| 4 | -public class ItemUI : MonoBehaviour | ||
| 5 | -{ | ||
| 6 | - [SerializeField] private Text nameText; | ||
| 7 | - [SerializeField] private Image iconImage; | ||
| 8 | - | ||
| 9 | - public void SetData(CustomListComponent.ItemData data) | ||
| 10 | - { | ||
| 11 | - if (nameText != null) | ||
| 12 | - { | ||
| 13 | - nameText.text = data.name; | ||
| 14 | - } | ||
| 15 | - | ||
| 16 | - if (iconImage != null && data.icon != null) | ||
| 17 | - { | ||
| 18 | - iconImage.sprite = data.icon; | ||
| 19 | - } | ||
| 20 | - } | ||
| 21 | -} |
Assets/Scripts/ScrollViewTest.cs
deleted
100644 → 0
| 1 | -using System.Collections; | ||
| 2 | -using System.Collections.Generic; | ||
| 3 | -using UnityEngine; | ||
| 4 | - | ||
| 5 | -public class ScrollViewTest : MonoBehaviour | ||
| 6 | -{ | ||
| 7 | - public CustomListComponent myScrollView; | ||
| 8 | - | ||
| 9 | - | ||
| 10 | - void Start() | ||
| 11 | - { | ||
| 12 | - } | ||
| 13 | - | ||
| 14 | - // Update is called once per frame | ||
| 15 | - void Update() | ||
| 16 | - { | ||
| 17 | - } | ||
| 18 | -} |
| @@ -8,7 +8,7 @@ MonoBehaviour: | @@ -8,7 +8,7 @@ MonoBehaviour: | ||
| 8 | m_PrefabAsset: {fileID: 0} | 8 | m_PrefabAsset: {fileID: 0} |
| 9 | m_GameObject: {fileID: 0} | 9 | m_GameObject: {fileID: 0} |
| 10 | m_Enabled: 1 | 10 | m_Enabled: 1 |
| 11 | - m_EditorHideFlags: 1 | 11 | + m_EditorHideFlags: 0 |
| 12 | m_Script: {fileID: 12004, guid: 0000000000000000e000000000000000, type: 0} | 12 | m_Script: {fileID: 12004, guid: 0000000000000000e000000000000000, type: 0} |
| 13 | m_Name: | 13 | m_Name: |
| 14 | m_EditorClassIdentifier: | 14 | m_EditorClassIdentifier: |
| @@ -19,7 +19,7 @@ MonoBehaviour: | @@ -19,7 +19,7 @@ MonoBehaviour: | ||
| 19 | width: 2560 | 19 | width: 2560 |
| 20 | height: 1357.3334 | 20 | height: 1357.3334 |
| 21 | m_ShowMode: 4 | 21 | m_ShowMode: 4 |
| 22 | - m_Title: Console | 22 | + m_Title: Hierarchy |
| 23 | m_RootView: {fileID: 2} | 23 | m_RootView: {fileID: 2} |
| 24 | m_MinSize: {x: 875, y: 300} | 24 | m_MinSize: {x: 875, y: 300} |
| 25 | m_MaxSize: {x: 10000, y: 10000} | 25 | m_MaxSize: {x: 10000, y: 10000} |
| @@ -120,7 +120,7 @@ MonoBehaviour: | @@ -120,7 +120,7 @@ MonoBehaviour: | ||
| 120 | m_MinSize: {x: 300, y: 100} | 120 | m_MinSize: {x: 300, y: 100} |
| 121 | m_MaxSize: {x: 24288, y: 16192} | 121 | m_MaxSize: {x: 24288, y: 16192} |
| 122 | vertical: 0 | 122 | vertical: 0 |
| 123 | - controlID: 81 | 123 | + controlID: 244 |
| 124 | draggingID: 0 | 124 | draggingID: 0 |
| 125 | --- !u!114 &6 | 125 | --- !u!114 &6 |
| 126 | MonoBehaviour: | 126 | MonoBehaviour: |
| @@ -146,7 +146,7 @@ MonoBehaviour: | @@ -146,7 +146,7 @@ MonoBehaviour: | ||
| 146 | m_MinSize: {x: 100, y: 100} | 146 | m_MinSize: {x: 100, y: 100} |
| 147 | m_MaxSize: {x: 8096, y: 16192} | 147 | m_MaxSize: {x: 8096, y: 16192} |
| 148 | vertical: 1 | 148 | vertical: 1 |
| 149 | - controlID: 17 | 149 | + controlID: 132 |
| 150 | draggingID: 0 | 150 | draggingID: 0 |
| 151 | --- !u!114 &7 | 151 | --- !u!114 &7 |
| 152 | MonoBehaviour: | 152 | MonoBehaviour: |
| @@ -158,7 +158,7 @@ MonoBehaviour: | @@ -158,7 +158,7 @@ MonoBehaviour: | ||
| 158 | m_Enabled: 1 | 158 | m_Enabled: 1 |
| 159 | m_EditorHideFlags: 1 | 159 | m_EditorHideFlags: 1 |
| 160 | m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0} | 160 | m_Script: {fileID: 12006, guid: 0000000000000000e000000000000000, type: 0} |
| 161 | - m_Name: GameView | 161 | + m_Name: AssetStoreWindow |
| 162 | m_EditorClassIdentifier: | 162 | m_EditorClassIdentifier: |
| 163 | m_Children: [] | 163 | m_Children: [] |
| 164 | m_Position: | 164 | m_Position: |
| @@ -167,15 +167,15 @@ MonoBehaviour: | @@ -167,15 +167,15 @@ MonoBehaviour: | ||
| 167 | y: 0 | 167 | y: 0 |
| 168 | width: 1292 | 168 | width: 1292 |
| 169 | height: 682 | 169 | height: 682 |
| 170 | - m_MinSize: {x: 100, y: 100} | ||
| 171 | - m_MaxSize: {x: 4000, y: 4000} | ||
| 172 | - m_ActualView: {fileID: 15} | 170 | + m_MinSize: {x: 456, y: 375} |
| 171 | + m_MaxSize: {x: 4001, y: 4021} | ||
| 172 | + m_ActualView: {fileID: 13} | ||
| 173 | m_Panes: | 173 | m_Panes: |
| 174 | - {fileID: 14} | 174 | - {fileID: 14} |
| 175 | - {fileID: 15} | 175 | - {fileID: 15} |
| 176 | - {fileID: 13} | 176 | - {fileID: 13} |
| 177 | - m_Selected: 1 | ||
| 178 | - m_LastSelected: 0 | 177 | + m_Selected: 2 |
| 178 | + m_LastSelected: 1 | ||
| 179 | --- !u!114 &8 | 179 | --- !u!114 &8 |
| 180 | MonoBehaviour: | 180 | MonoBehaviour: |
| 181 | m_ObjectHideFlags: 52 | 181 | m_ObjectHideFlags: 52 |
| @@ -226,7 +226,7 @@ MonoBehaviour: | @@ -226,7 +226,7 @@ MonoBehaviour: | ||
| 226 | m_MinSize: {x: 100, y: 100} | 226 | m_MinSize: {x: 100, y: 100} |
| 227 | m_MaxSize: {x: 8096, y: 16192} | 227 | m_MaxSize: {x: 8096, y: 16192} |
| 228 | vertical: 1 | 228 | vertical: 1 |
| 229 | - controlID: 82 | 229 | + controlID: 191 |
| 230 | draggingID: 0 | 230 | draggingID: 0 |
| 231 | --- !u!114 &10 | 231 | --- !u!114 &10 |
| 232 | MonoBehaviour: | 232 | MonoBehaviour: |
| @@ -247,8 +247,8 @@ MonoBehaviour: | @@ -247,8 +247,8 @@ MonoBehaviour: | ||
| 247 | y: 0 | 247 | y: 0 |
| 248 | width: 384 | 248 | width: 384 |
| 249 | height: 751.3333 | 249 | height: 751.3333 |
| 250 | - m_MinSize: {x: 200, y: 200} | ||
| 251 | - m_MaxSize: {x: 4000, y: 4000} | 250 | + m_MinSize: {x: 202, y: 221} |
| 251 | + m_MaxSize: {x: 4002, y: 4021} | ||
| 252 | m_ActualView: {fileID: 17} | 252 | m_ActualView: {fileID: 17} |
| 253 | m_Panes: | 253 | m_Panes: |
| 254 | - {fileID: 17} | 254 | - {fileID: 17} |
| @@ -299,8 +299,8 @@ MonoBehaviour: | @@ -299,8 +299,8 @@ MonoBehaviour: | ||
| 299 | y: 0 | 299 | y: 0 |
| 300 | width: 884 | 300 | width: 884 |
| 301 | height: 1307.3334 | 301 | height: 1307.3334 |
| 302 | - m_MinSize: {x: 275, y: 50} | ||
| 303 | - m_MaxSize: {x: 4000, y: 4000} | 302 | + m_MinSize: {x: 276, y: 71} |
| 303 | + m_MaxSize: {x: 4001, y: 4021} | ||
| 304 | m_ActualView: {fileID: 19} | 304 | m_ActualView: {fileID: 19} |
| 305 | m_Panes: | 305 | m_Panes: |
| 306 | - {fileID: 19} | 306 | - {fileID: 19} |
| @@ -329,7 +329,7 @@ MonoBehaviour: | @@ -329,7 +329,7 @@ MonoBehaviour: | ||
| 329 | serializedVersion: 2 | 329 | serializedVersion: 2 |
| 330 | x: 0 | 330 | x: 0 |
| 331 | y: 72.66667 | 331 | y: 72.66667 |
| 332 | - width: 1168.3334 | 332 | + width: 1291 |
| 333 | height: 661 | 333 | height: 661 |
| 334 | m_SerializedDataModeController: | 334 | m_SerializedDataModeController: |
| 335 | m_DataMode: 0 | 335 | m_DataMode: 0 |
| @@ -405,7 +405,7 @@ MonoBehaviour: | @@ -405,7 +405,7 @@ MonoBehaviour: | ||
| 405 | floating: 0 | 405 | floating: 0 |
| 406 | collapsed: 0 | 406 | collapsed: 0 |
| 407 | displayed: 1 | 407 | displayed: 1 |
| 408 | - snapOffset: {x: 0, y: 0} | 408 | + snapOffset: {x: 0, y: 24.666666} |
| 409 | snapOffsetDelta: {x: 0, y: 0} | 409 | snapOffsetDelta: {x: 0, y: 0} |
| 410 | snapCorner: 0 | 410 | snapCorner: 0 |
| 411 | id: unity-scene-view-toolbar | 411 | id: unity-scene-view-toolbar |
| @@ -749,9 +749,9 @@ MonoBehaviour: | @@ -749,9 +749,9 @@ MonoBehaviour: | ||
| 749 | m_PlayAudio: 0 | 749 | m_PlayAudio: 0 |
| 750 | m_AudioPlay: 0 | 750 | m_AudioPlay: 0 |
| 751 | m_Position: | 751 | m_Position: |
| 752 | - m_Target: {x: 1301.7489, y: 431.4366, z: 3.0009701} | 752 | + m_Target: {x: 784.90393, y: 472.3755, z: -1.2112993} |
| 753 | speed: 2 | 753 | speed: 2 |
| 754 | - m_Value: {x: 1301.7489, y: 431.4366, z: 3.0009701} | 754 | + m_Value: {x: 961.04877, y: 479.5093, z: -0.20217133} |
| 755 | m_RenderMode: 0 | 755 | m_RenderMode: 0 |
| 756 | m_CameraMode: | 756 | m_CameraMode: |
| 757 | drawMode: 0 | 757 | drawMode: 0 |
| @@ -799,11 +799,11 @@ MonoBehaviour: | @@ -799,11 +799,11 @@ MonoBehaviour: | ||
| 799 | m_Rotation: | 799 | m_Rotation: |
| 800 | m_Target: {x: -0.0071905754, y: -0.0035052756, z: -0.000025474808, w: 0.9999826} | 800 | m_Target: {x: -0.0071905754, y: -0.0035052756, z: -0.000025474808, w: 0.9999826} |
| 801 | speed: 2 | 801 | speed: 2 |
| 802 | - m_Value: {x: -0.0071904706, y: -0.0035052246, z: -0.000025474437, w: 0.99996805} | 802 | + m_Value: {x: 0.015107922, y: 0.982547, z: 0.16077192, w: -0.09233392} |
| 803 | m_Size: | 803 | m_Size: |
| 804 | - m_Target: 261.93716 | 804 | + m_Target: 201.43204 |
| 805 | speed: 2 | 805 | speed: 2 |
| 806 | - m_Value: 261.93716 | 806 | + m_Value: 35.840363 |
| 807 | m_Ortho: | 807 | m_Ortho: |
| 808 | m_Target: 0 | 808 | m_Target: 0 |
| 809 | speed: 2 | 809 | speed: 2 |
| @@ -997,9 +997,9 @@ MonoBehaviour: | @@ -997,9 +997,9 @@ MonoBehaviour: | ||
| 997 | m_SceneHierarchy: | 997 | m_SceneHierarchy: |
| 998 | m_TreeViewState: | 998 | m_TreeViewState: |
| 999 | scrollPos: {x: 0, y: 0} | 999 | scrollPos: {x: 0, y: 0} |
| 1000 | - m_SelectedIDs: b6f7ffff | ||
| 1001 | - m_LastClickedID: -2122 | ||
| 1002 | - m_ExpandedIDs: b6f7ffff64f8ffff12f9ffff2cfbffff | 1000 | + m_SelectedIDs: |
| 1001 | + m_LastClickedID: 0 | ||
| 1002 | + m_ExpandedIDs: 10e5feff8054ffff3479ffff9e6f0000 | ||
| 1003 | m_RenameOverlay: | 1003 | m_RenameOverlay: |
| 1004 | m_UserAcceptedRename: 0 | 1004 | m_UserAcceptedRename: 0 |
| 1005 | m_Name: | 1005 | m_Name: |
| @@ -1067,7 +1067,8 @@ MonoBehaviour: | @@ -1067,7 +1067,8 @@ MonoBehaviour: | ||
| 1067 | m_ShowAllHits: 0 | 1067 | m_ShowAllHits: 0 |
| 1068 | m_SkipHidden: 0 | 1068 | m_SkipHidden: 0 |
| 1069 | m_SearchArea: 1 | 1069 | m_SearchArea: 1 |
| 1070 | - m_Folders: [] | 1070 | + m_Folders: |
| 1071 | + - Assets/resources/Prefab | ||
| 1071 | m_Globs: [] | 1072 | m_Globs: [] |
| 1072 | m_OriginalText: | 1073 | m_OriginalText: |
| 1073 | m_ImportLogFlags: 0 | 1074 | m_ImportLogFlags: 0 |
| @@ -1083,7 +1084,7 @@ MonoBehaviour: | @@ -1083,7 +1084,7 @@ MonoBehaviour: | ||
| 1083 | scrollPos: {x: 0, y: 0} | 1084 | scrollPos: {x: 0, y: 0} |
| 1084 | m_SelectedIDs: fe390000 | 1085 | m_SelectedIDs: fe390000 |
| 1085 | m_LastClickedID: 14846 | 1086 | m_LastClickedID: 14846 |
| 1086 | - m_ExpandedIDs: 00000000c85a00006a5b00006c5b00006e5b0000705b0000 | 1087 | + m_ExpandedIDs: 000000005e6f000000ca9a3b |
| 1087 | m_RenameOverlay: | 1088 | m_RenameOverlay: |
| 1088 | m_UserAcceptedRename: 0 | 1089 | m_UserAcceptedRename: 0 |
| 1089 | m_Name: | 1090 | m_Name: |
| @@ -1111,7 +1112,7 @@ MonoBehaviour: | @@ -1111,7 +1112,7 @@ MonoBehaviour: | ||
| 1111 | scrollPos: {x: 0, y: 0} | 1112 | scrollPos: {x: 0, y: 0} |
| 1112 | m_SelectedIDs: | 1113 | m_SelectedIDs: |
| 1113 | m_LastClickedID: 0 | 1114 | m_LastClickedID: 0 |
| 1114 | - m_ExpandedIDs: ffffffff00000000c85a00006a5b00006c5b00006e5b0000705b0000a25b0000a45b0000a65b0000ac5b0000be5b0000 | 1115 | + m_ExpandedIDs: 9a42ffffffffffff000000005e6f000000ca9a3b |
| 1115 | m_RenameOverlay: | 1116 | m_RenameOverlay: |
| 1116 | m_UserAcceptedRename: 0 | 1117 | m_UserAcceptedRename: 0 |
| 1117 | m_Name: | 1118 | m_Name: |
-
Please register or login to post a comment