mirror of
https://github.com/Alex-Rachel/TEngine.git
synced 2025-08-14 16:51:28 +00:00
[+] UI循环列表拓展Grid 用法和List一样
[+] UI循环列表拓展Grid 用法和List一样
This commit is contained in:
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 0fcee77031f85f84dbc6735c875d64b8
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,86 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
public enum SnapStatus
|
||||
{
|
||||
NoTargetSet = 0,
|
||||
TargetHasSet = 1,
|
||||
SnapMoving = 2,
|
||||
SnapMoveFinish = 3
|
||||
}
|
||||
|
||||
|
||||
public enum ItemCornerEnum
|
||||
{
|
||||
LeftBottom = 0,
|
||||
LeftTop,
|
||||
RightTop,
|
||||
RightBottom,
|
||||
}
|
||||
|
||||
|
||||
public enum ListItemArrangeType
|
||||
{
|
||||
TopToBottom = 0,
|
||||
BottomToTop,
|
||||
LeftToRight,
|
||||
RightToLeft,
|
||||
}
|
||||
|
||||
public enum GridItemArrangeType
|
||||
{
|
||||
TopLeftToBottomRight = 0,
|
||||
BottomLeftToTopRight,
|
||||
TopRightToBottomLeft,
|
||||
BottomRightToTopLeft,
|
||||
}
|
||||
public enum GridFixedType
|
||||
{
|
||||
ColumnCountFixed = 0,
|
||||
RowCountFixed,
|
||||
}
|
||||
|
||||
public struct RowColumnPair
|
||||
{
|
||||
public RowColumnPair(int row1, int column1)
|
||||
{
|
||||
mRow = row1;
|
||||
mColumn = column1;
|
||||
}
|
||||
|
||||
public bool Equals(RowColumnPair other)
|
||||
{
|
||||
return this.mRow == other.mRow && this.mColumn == other.mColumn;
|
||||
}
|
||||
|
||||
public static bool operator ==(RowColumnPair a, RowColumnPair b)
|
||||
{
|
||||
return (a.mRow == b.mRow)&&(a.mColumn == b.mColumn);
|
||||
}
|
||||
public static bool operator !=(RowColumnPair a, RowColumnPair b)
|
||||
{
|
||||
return (a.mRow != b.mRow) || (a.mColumn != b.mColumn); ;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
public override bool Equals(object obj)
|
||||
{
|
||||
if (ReferenceEquals(null, obj))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return (obj is RowColumnPair) && Equals((RowColumnPair)obj);
|
||||
}
|
||||
|
||||
|
||||
public int mRow;
|
||||
public int mColumn;
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 19e4e487f35877f4b9bb864eb43484d6
|
||||
timeCreated: 1534508353
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: d7f738dc5a266e94d9e9870fc76009c2
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,173 @@
|
||||
namespace GameLogic
|
||||
{
|
||||
//if GridFixedType is GridFixedType.ColumnCountFixed, then the GridItemGroup is one row of the gridview
|
||||
//if GridFixedType is GridFixedType.RowCountFixed, then the GridItemGroup is one column of the gridview
|
||||
public class GridItemGroup
|
||||
{
|
||||
private int _count = 0;
|
||||
private int _groupIndex = -1;//the row index or the column index of this group
|
||||
private LoopGridViewItem _first = null;
|
||||
private LoopGridViewItem _last = null;
|
||||
public int Count => _count;
|
||||
|
||||
public LoopGridViewItem First => _first;
|
||||
|
||||
public LoopGridViewItem Last => _last;
|
||||
|
||||
public int GroupIndex
|
||||
{
|
||||
get => _groupIndex;
|
||||
set => _groupIndex = value;
|
||||
}
|
||||
|
||||
|
||||
public LoopGridViewItem GetItemByColumn(int column)
|
||||
{
|
||||
LoopGridViewItem cur = _first;
|
||||
while(cur != null)
|
||||
{
|
||||
if(cur.Column == column)
|
||||
{
|
||||
return cur;
|
||||
}
|
||||
cur = cur.NextItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public LoopGridViewItem GetItemByRow(int row)
|
||||
{
|
||||
LoopGridViewItem cur = _first;
|
||||
while (cur != null)
|
||||
{
|
||||
if (cur.Row == row)
|
||||
{
|
||||
return cur;
|
||||
}
|
||||
cur = cur.NextItem;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
public void ReplaceItem(LoopGridViewItem curItem,LoopGridViewItem newItem)
|
||||
{
|
||||
newItem.PrevItem = curItem.PrevItem;
|
||||
newItem.NextItem = curItem.NextItem;
|
||||
if(newItem.PrevItem != null)
|
||||
{
|
||||
newItem.PrevItem.NextItem = newItem;
|
||||
}
|
||||
if(newItem.NextItem != null)
|
||||
{
|
||||
newItem.NextItem.PrevItem = newItem;
|
||||
}
|
||||
if(_first == curItem)
|
||||
{
|
||||
_first = newItem;
|
||||
}
|
||||
if(_last == curItem)
|
||||
{
|
||||
_last = newItem;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddFirst(LoopGridViewItem newItem)
|
||||
{
|
||||
newItem.PrevItem = null;
|
||||
newItem.NextItem = null;
|
||||
if (_first == null)
|
||||
{
|
||||
_first = newItem;
|
||||
_last = newItem;
|
||||
_first.PrevItem = null;
|
||||
_first.NextItem = null;
|
||||
_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_first.PrevItem = newItem;
|
||||
newItem.PrevItem = null;
|
||||
newItem.NextItem = _first;
|
||||
_first = newItem;
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
|
||||
public void AddLast(LoopGridViewItem newItem)
|
||||
{
|
||||
newItem.PrevItem = null;
|
||||
newItem.NextItem = null;
|
||||
if (_first == null)
|
||||
{
|
||||
_first = newItem;
|
||||
_last = newItem;
|
||||
_first.PrevItem = null;
|
||||
_first.NextItem = null;
|
||||
_count++;
|
||||
}
|
||||
else
|
||||
{
|
||||
_last.NextItem = newItem;
|
||||
newItem.PrevItem = _last;
|
||||
newItem.NextItem = null;
|
||||
_last = newItem;
|
||||
_count++;
|
||||
}
|
||||
}
|
||||
|
||||
public LoopGridViewItem RemoveFirst()
|
||||
{
|
||||
LoopGridViewItem ret = _first;
|
||||
if (_first == null)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
if(_first == _last)
|
||||
{
|
||||
_first = null;
|
||||
_last = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
_first = _first.NextItem;
|
||||
_first.PrevItem = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
public LoopGridViewItem RemoveLast()
|
||||
{
|
||||
LoopGridViewItem ret = _last;
|
||||
if (_first == null)
|
||||
{
|
||||
return ret;
|
||||
}
|
||||
if (_first == _last)
|
||||
{
|
||||
_first = null;
|
||||
_last = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
_last = _last.PrevItem;
|
||||
_last.NextItem = null;
|
||||
--_count;
|
||||
return ret;
|
||||
}
|
||||
|
||||
|
||||
public void Clear()
|
||||
{
|
||||
LoopGridViewItem current = _first;
|
||||
while (current != null)
|
||||
{
|
||||
current.PrevItem = null;
|
||||
current.NextItem = null;
|
||||
current = current.NextItem;
|
||||
}
|
||||
_first = null;
|
||||
_last = null;
|
||||
_count = 0;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: f7e7eb25fe1319d4b8773ddfab7a240e
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,113 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public class GridItemPool
|
||||
{
|
||||
private GameObject _prefabObj;
|
||||
private string _prefabName;
|
||||
private int _initCreateCount = 1;
|
||||
private readonly List<LoopGridViewItem> _tmpPooledItemList = new List<LoopGridViewItem>();
|
||||
private readonly List<LoopGridViewItem> _pooledItemList = new List<LoopGridViewItem>();
|
||||
private static int _curItemIdCount = 0;
|
||||
private RectTransform _itemParent = null;
|
||||
public GridItemPool()
|
||||
{
|
||||
|
||||
}
|
||||
public void Init(GameObject prefabObj, int createCount, RectTransform parent)
|
||||
{
|
||||
_prefabObj = prefabObj;
|
||||
_prefabName = _prefabObj.name;
|
||||
_initCreateCount = createCount;
|
||||
_itemParent = parent;
|
||||
_prefabObj.SetActive(false);
|
||||
for (int i = 0; i < _initCreateCount; ++i)
|
||||
{
|
||||
LoopGridViewItem tViewItem = CreateItem();
|
||||
RecycleItemReal(tViewItem);
|
||||
}
|
||||
}
|
||||
public LoopGridViewItem GetItem()
|
||||
{
|
||||
_curItemIdCount++;
|
||||
LoopGridViewItem tItem = null;
|
||||
if (_tmpPooledItemList.Count > 0)
|
||||
{
|
||||
int count = _tmpPooledItemList.Count;
|
||||
tItem = _tmpPooledItemList[count - 1];
|
||||
_tmpPooledItemList.RemoveAt(count - 1);
|
||||
tItem.gameObject.SetActive(true);
|
||||
}
|
||||
else
|
||||
{
|
||||
int count = _pooledItemList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
tItem = CreateItem();
|
||||
}
|
||||
else
|
||||
{
|
||||
tItem = _pooledItemList[count - 1];
|
||||
_pooledItemList.RemoveAt(count - 1);
|
||||
tItem.gameObject.SetActive(true);
|
||||
}
|
||||
}
|
||||
tItem.ItemId = _curItemIdCount;
|
||||
return tItem;
|
||||
|
||||
}
|
||||
|
||||
public void DestroyAllItem()
|
||||
{
|
||||
ClearTmpRecycledItem();
|
||||
int count = _pooledItemList.Count;
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
GameObject.DestroyImmediate(_pooledItemList[i].gameObject);
|
||||
}
|
||||
_pooledItemList.Clear();
|
||||
}
|
||||
public LoopGridViewItem CreateItem()
|
||||
{
|
||||
|
||||
GameObject go = GameObject.Instantiate<GameObject>(_prefabObj, Vector3.zero, Quaternion.identity, _itemParent);
|
||||
go.SetActive(true);
|
||||
RectTransform rf = go.GetComponent<RectTransform>();
|
||||
rf.localScale = Vector3.one;
|
||||
rf.anchoredPosition3D = Vector3.zero;
|
||||
rf.localEulerAngles = Vector3.zero;
|
||||
LoopGridViewItem tViewItem = go.GetComponent<LoopGridViewItem>();
|
||||
tViewItem.ItemPrefabName = _prefabName;
|
||||
tViewItem.GoId = go.GetHashCode();
|
||||
return tViewItem;
|
||||
}
|
||||
void RecycleItemReal(LoopGridViewItem item)
|
||||
{
|
||||
item.gameObject.SetActive(false);
|
||||
_pooledItemList.Add(item);
|
||||
}
|
||||
public void RecycleItem(LoopGridViewItem item)
|
||||
{
|
||||
item.PrevItem = null;
|
||||
item.NextItem = null;
|
||||
_tmpPooledItemList.Add(item);
|
||||
}
|
||||
public void ClearTmpRecycledItem()
|
||||
{
|
||||
int count = _tmpPooledItemList.Count;
|
||||
if (count == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
RecycleItemReal(_tmpPooledItemList[i]);
|
||||
}
|
||||
_tmpPooledItemList.Clear();
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: c1eb92a17e8cee642a2245950dfaabea
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: 17e9881a7bce8124a8f855b96a8ca11a
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,184 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using UnityEngine;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
|
||||
public class LoopGridViewItem : MonoBehaviour
|
||||
{
|
||||
// indicates the item’s index in the list the mItemIndex can only be from 0 to itemTotalCount -1.
|
||||
int mItemIndex = -1;
|
||||
// the row index, the item is in. starting from 0.
|
||||
int mRow = -1;
|
||||
// the column index, the item is in. starting from 0.
|
||||
int mColumn = -1;
|
||||
//indicates the item’s id.
|
||||
//This property is set when the item is created or fetched from pool,
|
||||
//and will no longer change until the item is recycled back to pool.
|
||||
int mItemId = -1;
|
||||
|
||||
private int _goId = 0;
|
||||
|
||||
public int GoId
|
||||
{
|
||||
set => _goId = value;
|
||||
get => _goId;
|
||||
}
|
||||
|
||||
LoopGridView mParentGridView = null;
|
||||
bool mIsInitHandlerCalled = false;
|
||||
string mItemPrefabName;
|
||||
RectTransform mCachedRectTransform;
|
||||
int mItemCreatedCheckFrameCount = 0;
|
||||
|
||||
object mUserObjectData = null;
|
||||
int mUserIntData1 = 0;
|
||||
int mUserIntData2 = 0;
|
||||
string mUserStringData1 = null;
|
||||
string mUserStringData2 = null;
|
||||
|
||||
LoopGridViewItem mPrevItem;
|
||||
LoopGridViewItem mNextItem;
|
||||
|
||||
public object UserObjectData
|
||||
{
|
||||
get { return mUserObjectData; }
|
||||
set { mUserObjectData = value; }
|
||||
}
|
||||
public int UserIntData1
|
||||
{
|
||||
get { return mUserIntData1; }
|
||||
set { mUserIntData1 = value; }
|
||||
}
|
||||
public int UserIntData2
|
||||
{
|
||||
get { return mUserIntData2; }
|
||||
set { mUserIntData2 = value; }
|
||||
}
|
||||
public string UserStringData1
|
||||
{
|
||||
get { return mUserStringData1; }
|
||||
set { mUserStringData1 = value; }
|
||||
}
|
||||
public string UserStringData2
|
||||
{
|
||||
get { return mUserStringData2; }
|
||||
set { mUserStringData2 = value; }
|
||||
}
|
||||
|
||||
public int ItemCreatedCheckFrameCount
|
||||
{
|
||||
get { return mItemCreatedCheckFrameCount; }
|
||||
set { mItemCreatedCheckFrameCount = value; }
|
||||
}
|
||||
|
||||
|
||||
public RectTransform CachedRectTransform
|
||||
{
|
||||
get
|
||||
{
|
||||
if (mCachedRectTransform == null)
|
||||
{
|
||||
mCachedRectTransform = gameObject.GetComponent<RectTransform>();
|
||||
}
|
||||
return mCachedRectTransform;
|
||||
}
|
||||
}
|
||||
|
||||
public string ItemPrefabName
|
||||
{
|
||||
get
|
||||
{
|
||||
return mItemPrefabName;
|
||||
}
|
||||
set
|
||||
{
|
||||
mItemPrefabName = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int Row
|
||||
{
|
||||
get
|
||||
{
|
||||
return mRow;
|
||||
}
|
||||
set
|
||||
{
|
||||
mRow = value;
|
||||
}
|
||||
}
|
||||
public int Column
|
||||
{
|
||||
get
|
||||
{
|
||||
return mColumn;
|
||||
}
|
||||
set
|
||||
{
|
||||
mColumn = value;
|
||||
}
|
||||
}
|
||||
|
||||
public int ItemIndex
|
||||
{
|
||||
get
|
||||
{
|
||||
return mItemIndex;
|
||||
}
|
||||
set
|
||||
{
|
||||
mItemIndex = value;
|
||||
}
|
||||
}
|
||||
public int ItemId
|
||||
{
|
||||
get
|
||||
{
|
||||
return mItemId;
|
||||
}
|
||||
set
|
||||
{
|
||||
mItemId = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public bool IsInitHandlerCalled
|
||||
{
|
||||
get
|
||||
{
|
||||
return mIsInitHandlerCalled;
|
||||
}
|
||||
set
|
||||
{
|
||||
mIsInitHandlerCalled = value;
|
||||
}
|
||||
}
|
||||
|
||||
public LoopGridView ParentGridView
|
||||
{
|
||||
get
|
||||
{
|
||||
return mParentGridView;
|
||||
}
|
||||
set
|
||||
{
|
||||
mParentGridView = value;
|
||||
}
|
||||
}
|
||||
|
||||
public LoopGridViewItem PrevItem
|
||||
{
|
||||
get { return mPrevItem; }
|
||||
set { mPrevItem = value; }
|
||||
}
|
||||
public LoopGridViewItem NextItem
|
||||
{
|
||||
get { return mNextItem; }
|
||||
set { mNextItem = value; }
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,12 @@
|
||||
fileFormatVersion: 2
|
||||
guid: ec0432517adfcb84bb6163d7a44ab8c1
|
||||
timeCreated: 1554538573
|
||||
licenseType: Store
|
||||
MonoImporter:
|
||||
serializedVersion: 2
|
||||
defaultReferences: []
|
||||
executionOrder: 0
|
||||
icon: {instanceID: 0}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2
|
||||
guid: e9bbd48a4abc45c46a92b92d0df3ae07
|
||||
folderAsset: yes
|
||||
DefaultImporter:
|
||||
externalObjects: {}
|
||||
userData:
|
||||
assetBundleName:
|
||||
assetBundleVariant:
|
@@ -8,23 +8,6 @@ using Object = UnityEngine.Object;
|
||||
|
||||
namespace GameLogic
|
||||
{
|
||||
public enum ItemCornerEnum
|
||||
{
|
||||
LeftBottom = 0,
|
||||
LeftTop,
|
||||
RightTop,
|
||||
RightBottom,
|
||||
}
|
||||
|
||||
|
||||
public enum ListItemArrangeType
|
||||
{
|
||||
TopToBottom,
|
||||
BottomToTop,
|
||||
LeftToRight,
|
||||
RightToLeft,
|
||||
}
|
||||
|
||||
public class ItemPool
|
||||
{
|
||||
private GameObject _prefabObj;
|
||||
@@ -171,13 +154,6 @@ namespace GameLogic
|
||||
public delegate LoopListViewItem
|
||||
OnGetItemByIndex(LoopListView listView, int index); // System.Func<LoopListView, int, LoopListViewItem>
|
||||
|
||||
public enum SnapStatus
|
||||
{
|
||||
NoTargetSet = 0,
|
||||
TargetHasSet = 1,
|
||||
SnapMoving = 2,
|
||||
SnapMoveFinish = 3
|
||||
}
|
||||
|
||||
public class LoopListView : MonoBehaviour, IBeginDragHandler, IEndDragHandler, IDragHandler
|
||||
{
|
Reference in New Issue
Block a user