蟄伏--當你不夠強大時,就不要放棄努力
//NGUI............................................................
using System;
using UnityEngine;
using System.Collections;
public class ScrollViewTurnPage : MonoBehaviour
{
[Header("一頁的寬度,一般就是ScrollView的寬度")]
[SerializeField] private int m_pageWidth = 600;
[Range(5.0f, 55.0f)]
[SerializeField] private int m_springStrength = 35;
private int m_totalPages = 4; //固定的時候,寫的頁數
[Header("列數")]
[SerializeField] private int m_columns = 4;
[Header("行數")]
[SerializeField] private int m_row = 3;
#region Public Interface
public void PreviousPage()
{
if (m_bHorizontal)
{
if (m_currPage > 1) Page(m_pageWidth);
}
else
{
if (m_currPage < m_totalPages) Page(m_pageWidth);
}
}
public void NextPage()
{
if (m_bHorizontal)
{
if (m_currPage < m_totalPages) Page(-m_pageWidth);
}
else
{
if (m_currPage > 1) Page(-m_pageWidth);
}
}
public int CurrentPage
{
get { return m_currPage; }
}
public int TotalPages
{
get { return m_totalPages; }
set { m_totalPages = value; }
}
public int OnePageItemsMaxNum
{
get { return m_columns * m_row; }
}
public int ItemColumns
{
get { return m_columns; }
}
public int PageWidth
{
get { return m_pageWidth; }
}
#endregion
#region private interface
private int m_currPage = 1;
private UIScrollView m_scrollView = null;
private float m_nowLocation = 0;
private bool m_bDrag = false;
private bool m_bSpringMove = false;
private SpringPanel m_springPanel = null;
private bool m_bHorizontal = true;
void Awake()
{
m_scrollView = gameObject.GetComponent<UIScrollView>();
if (m_scrollView == null)
m_scrollView = gameObject.AddComponent<UIScrollView>();
m_springPanel = GetComponent<SpringPanel>();
if (m_springPanel == null) m_springPanel = gameObject.AddComponent<SpringPanel>();
m_springPanel.enabled = true;
m_scrollView.onDragStarted = OnDragStarted;
m_scrollView.onMomentumMove = onMomentumMove;
m_scrollView.onStoppedMoving = onStoppedMoving;
m_scrollView.onDragFinished = onDragFinished;
m_bHorizontal = m_scrollView.movement == UIScrollView.Movement.Horizontal ? true : false;
onStoppedMoving();
}
void onDragFinished()
{
onMomentumMove();
}
void OnDragStarted()
{
m_bDrag = false;
SetNowLocation();
}
void onMomentumMove()
{
if (m_bDrag) return;
Vector3 v3 = transform.localPosition;
float value = 0;
if (m_bHorizontal)
{
value = m_nowLocation - v3.x;
//if (Mathf.Abs(value) < m_springStrength) return;
if (value > 0)
{
if (m_currPage < m_totalPages) Page(-m_pageWidth);
}
else
{
if (m_currPage > 1) Page(m_pageWidth);
}
}
else
{
value = m_nowLocation - v3.y;
//if (Mathf.Abs(value) < m_springStrength) return;
if (value > 0)
{
if (m_currPage > 1) Page(-m_pageWidth);
}
else
{
if (m_currPage < m_totalPages) Page(m_pageWidth);
}
}
}
void Page(float value)
{
m_bSpringMove = true;
m_bDrag = true;
//m_springPanel = GetComponent<SpringPanel>();
//if (m_springPanel == null) m_springPanel = gameObject.AddComponent<SpringPanel>();
////m_springPanel.enabled = false;
Vector3 pos = m_springPanel.target;
pos = m_bHorizontal ? new Vector3(pos.x + value, pos.y, pos.z) : new Vector3(pos.x, pos.y + value, pos.z);
if (!SetIndexPage(pos)) return;
SpringPanel.Begin(gameObject, pos, m_springStrength).strength = 10.0f;
m_springPanel.onFinished = SpringPanleMoveEnd;
//Debug.Log("current Page ==" + m_currPage);
}
void SpringPanleMoveEnd()
{
m_bSpringMove = false;
//重新定位
}
void onStoppedMoving()
{
m_bDrag = false;
SetNowLocation();
}
void SetNowLocation()
{
if (m_bHorizontal)
{
m_nowLocation = gameObject.transform.localPosition.x;
}
else
{
m_nowLocation = gameObject.transform.localPosition.y;
}
}
bool SetIndexPage(Vector3 v3)
{
float value = m_bHorizontal ? v3.x : v3.y;
//if (m_bHorizontal)
//{
// if (value > 0 || value < (m_totalPages) * -m_pageWidth) return false;
//}
//else
//{
// if (value < 0 || value > (m_totalPages - 1) * m_pageWidth) return false;
//}
value = Mathf.Abs(value);
m_currPage = (int) (value / m_pageWidth) + 1;
return true;
}
#endregion
}
簡單的實現了下NGUI的上下翻頁。有兩個介面,分別是上一頁和下一頁。
用法如下。
如上圖,第一個引數為 Page的寬或高,具體由你的滑動元件設定的方向定。
第二個引數為滑動係數,即,滑動了多遠就翻頁
第三個引數為總頁數。
依賴元件。UIScrollView,UICenterOnChild。
指令碼和Scroll一起
分頁父物體綁上居中指令碼。為Scroll的子物體
這個基本功能沒問題。但是有一個小缺陷。就是Panel的座標必須為中心點。如果需要位移需要再加一個父物體。讓滑動元件依賴的Panel的相對座標都為0.
原因是因為我用的座標去計算的當前頁。大家如果有空。可以改為偏移量就能解決這問題。
因為我也用不上這個。這個是寫給學員參考的。所以就懶得改了。大家需要的改的話。可以自行修改。
最後。上指令碼。
- usingUnityEngine;
- usingSystem.Collections;
- publicclassYouKeTurnPage:MonoBehaviour
- {
- ///
- /// 每頁寬度(遊-客-學-院)
- ///
- publicfloat pageWidth;
- ///
- /// 翻頁力度(遊.客.學.院)
- ///
- publicintEffortsFlip=50;
- ///
- /// 總頁數
- ///
- publicint pageNums=0;
- ///
- /// 當前所在頁
- ///
- publicint pageIndex
- {
- get
- {
- return mPageIndex;
- }
- }
- ///
- /// 當前所在頁
- ///
- privateint mPageIndex=1;
- privateUIScrollView mScrollView=null;
- privatefloat nowLocation=0;
- private bool isDrag=false;
- private bool isSpringMove=false;
- privateSpringPanel mSp=null;
- private bool isHorizontal=true;
- voidAwake()
- {
- mScrollView= gameObject.GetComponent();
- if(mScrollView==null)
- {
- mScrollView= gameObject.AddComponent();
- }
- mScrollView.onDragStarted=OnDragStarted;
- mScrollView.onMomentumMove= onMomentumMove;
- mScrollView.onStoppedMoving= onStoppedMoving;
- if(mScrollView.movement==UIScrollView.Movement.Horizontal)
- {
- isHorizontal=true;
- }
- else
- {
- isHorizontal=false;
- }
- onStoppedMoving();
- }
- voidOnDragStarted()
- {
- isDrag=false;
- SetNowLocation();
- }
- void onMomentumMove()
- {
- if(isDrag)return;
- Vector3 v3= transform.localPosition;
- float value=0;
- if(isHorizontal)
- {
- value= nowLocation- v3.x;
- if(Mathf.Abs(value)<EffortsFlip)return;
- if(value>0)
- {
- if(mPageIndex< pageNums)Page(-pageWidth);
- }
- else
- {
- if(mPageIndex>1)Page(pageWidth);
- }
- }
- else
- {
- value= nowLocation- v3.y;
- if(Mathf.Abs(value)<EffortsFlip)return;
- if(value>0)
- {
- if(mPageIndex>1)Page(-pageWidth);
- }
- else
- {
- if(mPageIndex< pageNums)Page(pageWidth);
- }
- }
- }
- voidPage(float value)
- {
- isSpringMove=true;
- isDrag=true;
- mSp=GetComponent();
- if(mSp==null)mSp= gameObject.AddComponent();
- //mSp.enabled = false;
- Vector3 pos= mSp.target;
- pos= isHorizontal?newVector3(pos.x+ value, pos.y, pos.z):newVector3(pos.x, pos.y+ value, pos.z);
- if(!SetIndexPage(pos))return;
- SpringPanel.Begin(gameObject, pos,13f).strength=8f;
- mSp.onFinished=SpringPanleMoveEnd;
- Debug.Log("page index="+mPageIndex);
- }
- voidSpringPanleMoveEnd()
- {
- isSpringMove=false;
- }
- void onStoppedMoving()
- {
- isDrag=false;
- SetNowLocation();
- }
- voidSetNowLocation()
- {
- if(isHorizontal)
- {
- nowLocation= gameObject.transform.localPosition.x;
- }
- else
- {
- nowLocation= gameObject.transform.localPosition.y;
- }
- }
- boolSetIndexPage(Vector3 v3)
- {
- float value= isHorizontal? v3.x: v3.y;
- //Debug.Log((pageNums - 1) * pageWidth);
- if(isHorizontal)
- {
- if(value>0|| value<(pageNums-1)*-pageWidth)returnfalse;
- }
- else
- {
- if(value<0|| value>(pageNums-1)* pageWidth)returnfalse;
- }
- value=Mathf.Abs(value);
- mPageIndex=(int)(value/ pageWidth)+1;
- returntrue;
- }
- #region 公共介面 遊*客*學*院
- ///
- /// 上一頁
- ///
- publicvoidPreviousPage()
- {
- if(isHorizontal)
- {
- if(mPageIndex>1)Page(pageWidth);
- }
- else
- {
- if(mPageIndex< pageNums)Page(pageWidth);
- }
- }
- ///
- /// 下一頁
- ///
- publicvoidNextPage()
- {
- if(isHorizontal)
- {
- if(mPageIndex< pageNums)Page(-pageWidth);
- }
- else
- {
- if(mPageIndex>1)Page(-pageWidth);
- }
- }
- #endregion
- }
//UGUI..............................................\
using UnityEngine;
using System.Collections;
using System.Collections.Generic;
using UnityEngine.UI;
public class GridItem {
public string cnName;
public string usName;
public GridItem(string cnN,string usN) {
cnName = cnN;
usName = usN;
}
}
public class PaginationPanel : MonoBehaviour
{
/// <summary>
/// 當前頁面索引
/// </summary>
public int m_PageIndex = 1;
/// <summary>
/// 總頁數
/// </summary>
public int m_PageCount = 0;
/// <summary>
/// 每頁元素數
/// </summary>
public int m_PerPageCount = 0;
/// <summary>
/// 元素總個數
/// </summary>
public int m_ItemsCount = 0;
/// <summary>
/// 元素列表
/// </summary>
public List<GridItem> m_ItemsList;
/// <summary>
/// 上一頁
/// </summary>
public Button m_BtnPrevious;
/// <summary>
/// 下一頁
/// </summary>
public Button m_BtnNext;
/// <summary>
/// 顯示當前頁數的標籤
/// </summary>
public Text m_PanelText;
public Transform m_FrontPanel;
public Transform m_BackPanel;
public bool m_IsTouching;
[Range(-1,1)]
public float m_TouchDelta;
public float m_MoveSpeed = 5f;
public float m_FadeDistance;
public Vector3 m_PrePos;
public Vector3 m_CenterPos;
public Vector3 m_NextPos;
public bool m_DoPrevious;
public bool m_DoNext;
public float m_CurrAlpha;
private bool m_HasPrevious;
private bool m_HasNext;
private bool m_IsSaveBeforeTouch;
public int m_FrontPanelPageIndex;
private bool m_CanChangePage;
private bool m_IsBackPageIndex;
void Start()
{
InitGUI();
InitItems();
}
/// <summary>
/// 初始化GUI
/// </summary>
private void InitGUI()
{
//m_BtnNext = GameObject.Find("Canvas/Panel/BtnNext").GetComponent<Button>();
//m_BtnPrevious = GameObject.Find("Canvas/Panel/BtnPrevious").GetComponent<Button>();
//m_PanelText = GameObject.Find("Canvas/Panel/Text").GetComponent<Text>();
//為上一頁和下一頁新增事件
m_BtnNext.onClick.AddListener(() => { OnNextBtnClick(); });
m_BtnPrevious.onClick.AddListener(() => { OnPreviousBtnClick(); });
m_PerPageCount = m_FrontPanel.childCount;
m_FadeDistance = Mathf.Abs(m_FrontPanel.localPosition.y - m_BackPanel.localPosition.y);
m_PrePos = m_FrontPanel.localPosition;
m_PrePos.y += m_FadeDistance;
m_NextPos = m_FrontPanel.localPosition;
m_NextPos.y -= m_FadeDistance;
m_CenterPos = m_FrontPanel.localPosition;
m_CanChangePage = true;
m_FrontPanelPageIndex = 1;
}
/// <summary>
/// 初始化元素
/// </summary>
private void InitItems()
{
//準備一個儲存著12生肖資訊的陣列
GridItem[] items = new GridItem[]
{
new GridItem("鼠","Mouse"),
new GridItem("牛","Ox"),
new GridItem("虎","Tiger"),
new GridItem("兔","Rabbit"),
new GridItem("龍","Dragon"),
new GridItem("蛇","Snake"),
new GridItem("馬","Horse"),
new GridItem("羊","Goat"),
new GridItem("猴","Monkey"),
new GridItem("雞","Rooster"),
new GridItem("狗","Dog"),
new GridItem("豬","Pig")
};
//利用12生肖陣列來隨機生成列表
m_ItemsList = new List<GridItem>();
for (int i = 0; i < items.Length; i++)
{
m_ItemsList.Add(items[i]);
}
//計算元素總個數
m_ItemsCount = m_ItemsList.Count;
//計算總頁數
m_PageCount = (m_ItemsCount % m_PerPageCount) == 0 ? m_ItemsCount / m_PerPageCount : (m_ItemsCount / m_PerPageCount) + 1;
BindPage(m_FrontPanel, m_PageIndex);
//更新介面頁數
m_PanelText.text = string.Format("{0}/{1}", m_PageIndex.ToString(), m_PageCount.ToString());
}
private void Update()
{
if (m_IsTouching)
{
if (!m_IsSaveBeforeTouch) {
m_IsSaveBeforeTouch = true;
m_FrontPanelPageIndex = m_PageIndex;
}
if (m_TouchDelta > 0)
{
if (!m_HasPrevious && m_FrontPanelPageIndex > 1)
{
m_HasNext = false;
m_HasPrevious = true;
TouchPrevious();
}
if (m_DoPrevious)
{
m_IsBackPageIndex = false;
m_BackPanel.localPosition = Vector3.Lerp(m_PrePos, m_CenterPos, Mathf.Abs(m_TouchDelta));
m_BackPanel.GetComponent<CanvasGroup>().alpha = Mathf.Abs(m_TouchDelta);
}
m_FrontPanel.localPosition = Vector3.Lerp(m_CenterPos, m_NextPos, Mathf.Abs(m_TouchDelta));
m_FrontPanel.GetComponent<CanvasGroup>().alpha = 1 - Mathf.Abs(m_TouchDelta);
}
else if (m_TouchDelta < 0)
{
if (!m_HasNext && m_FrontPanelPageIndex < m_PageCount)
{
m_HasNext = true;
m_HasPrevious = false;
TouchNext();
}
if (m_DoNext)
{
m_IsBackPageIndex = false;
m_BackPanel.localPosition = Vector3.Lerp(m_NextPos, m_CenterPos, Mathf.Abs(m_TouchDelta));
m_BackPanel.GetComponent<CanvasGroup>().alpha = Mathf.Abs(m_TouchDelta);
}
m_FrontPanel.localPosition = Vector3.Lerp(m_CenterPos, m_PrePos, Mathf.Abs(m_TouchDelta));
m_FrontPanel.GetComponent<CanvasGroup>().alpha = 1 - Mathf.Abs(m_TouchDelta);
}
}
else {
m_HasNext = false;
m_HasPrevious = false;
m_IsSaveBeforeTouch = false;
float a = Mathf.Abs(m_FrontPanel.localPosition.y - m_CenterPos.y) / m_FadeDistance;
m_CurrAlpha = a;
if (m_TouchDelta >= 0.5f)
{
//float a = Mathf.Abs(m_FrontPanel.localPosition.y - m_CenterPos.y) / m_FadeDistance;
if (m_DoPrevious)
{
m_BackPanel.localPosition = Vector3.Lerp(m_BackPanel.localPosition, m_CenterPos, m_MoveSpeed * Time.deltaTime);
m_BackPanel.GetComponent<CanvasGroup>().alpha = a;
m_FrontPanel.localPosition = Vector3.Lerp(m_FrontPanel.localPosition, m_NextPos, m_MoveSpeed * Time.deltaTime);
m_FrontPanel.GetComponent<CanvasGroup>().alpha = 1 - a;
if (1 - a < 0.01f)
{
m_TouchDelta = 0;
SwitchPanel();
}
}
else {
m_TouchDelta = 0;
}
}
else if (m_TouchDelta <= -0.5f)
{
//float a = Mathf.Abs(m_FrontPanel.localPosition.y - m_CenterPos.y) / m_FadeDistance;
if (m_DoNext)
{
m_BackPanel.localPosition = Vector3.Lerp(m_BackPanel.localPosition, m_CenterPos, m_MoveSpeed * Time.deltaTime);
m_BackPanel.GetComponent<CanvasGroup>().alpha = a;
m_FrontPanel.localPosition = Vector3.Lerp(m_FrontPanel.localPosition, m_PrePos, m_MoveSpeed * Time.deltaTime);
m_FrontPanel.GetComponent<CanvasGroup>().alpha = 1 - a;
if (1 - a < 0.01f)
{
m_TouchDelta = 0;
SwitchPanel();
}
}
else {
m_TouchDelta = 0;
}
}
else {
//float a = Mathf.Abs(m_FrontPanel.localPosition.y - m_CenterPos.y) / m_FadeDistance;
if (m_DoPrevious)
{
if (!m_IsBackPageIndex) {
m_IsBackPageIndex = true;
m_PageIndex = m_FrontPanelPageIndex;
}
if (m_PageIndex < m_PageCount && m_PageIndex > 1) {
m_BackPanel.localPosition = Vector3.Lerp(m_BackPanel.localPosition, m_PrePos, m_MoveSpeed * Time.deltaTime);
m_BackPanel.GetComponent<CanvasGroup>().alpha = a;
}
}
else if (m_DoNext) {
if (!m_IsBackPageIndex)
{
m_IsBackPageIndex = true;
m_PageIndex = m_FrontPanelPageIndex;
}
if (m_PageIndex < m_PageCount && m_PageIndex > 1) {
m_BackPanel.localPosition = Vector3.Lerp(m_BackPanel.localPosition, m_NextPos, m_MoveSpeed * Time.deltaTime);
m_BackPanel.GetComponent<CanvasGroup>().alpha = a;
}
}
m_FrontPanel.localPosition = Vector3.Lerp(m_FrontPanel.localPosition,m_CenterPos, m_MoveSpeed * Time.deltaTime);
m_FrontPanel.GetComponent<CanvasGroup>().alpha = 1 - a;
if (m_TouchDelta != 0 && a < 0.01f)
{
m_TouchDelta = 0;
m_DoNext = false;
m_DoPrevious = false;
m_CanChangePage = true;
}
}
}
}
private void SwitchPanel() {
m_DoPrevious = false;
m_DoNext = false;
Transform temp = m_FrontPanel;
m_FrontPanel = m_BackPanel;
m_BackPanel = temp;
m_CanChangePage = true;
}
public void OnNextBtnClick() {
if (!m_CanChangePage) return;
m_TouchDelta = -0.6f;
Next();
}
/// <summary>
/// 下一頁
/// </summary>
public void Next()
{
if (m_PageCount <= 0)
return;
//最後一頁禁止向後翻頁
if (m_PageIndex >= m_PageCount)
return;
m_CanChangePage = false;
m_PageIndex += 1;
if (m_PageIndex >= m_PageCount)
m_PageIndex = m_PageCount;
m_BackPanel.localPosition = m_NextPos;
BindPage(m_BackPanel, m_PageIndex);
m_DoNext = true;
m_DoPrevious = false;
//更新介面頁數
m_PanelText.text = string.Format("{0}/{1}", m_PageIndex.ToString(), m_PageCount.ToString());
}
/// <summary>
/// 下一頁
/// </summary>
public void TouchNext()
{
if (m_PageCount <= 0)
return;
//最後一頁禁止向後翻頁
if (m_FrontPanelPageIndex >= m_PageCount)
return;
m_CanChangePage = false;
m_PageIndex = m_FrontPanelPageIndex + 1;
if (m_PageIndex >= m_PageCount)
m_PageIndex = m_PageCount;
m_BackPanel.localPosition = m_NextPos;
BindPage(m_BackPanel, m_PageIndex);
m_DoNext = true;
m_DoPrevious = false;
//更新介面頁數
m_PanelText.text = string.Format("{0}/{1}", m_PageIndex.ToString(), m_PageCount.ToString());
}
public void OnPreviousBtnClick() {
if (!m_CanChangePage) return;
m_TouchDelta = 0.6f;
Previous();
}
/// <summary>
/// 上一頁
/// </summary>
public void Previous()
{
if (m_PageCount <= 0)
return;
//第一頁時禁止向前翻頁
if (m_PageIndex <= 1)
return;
m_CanChangePage = false;
m_PageIndex -= 1;
if (m_PageIndex < 1)
m_PageIndex = 1;
m_BackPanel.localPosition = m_PrePos;
BindPage(m_BackPanel, m_PageIndex);
m_DoPrevious = true;
m_DoNext = false;
//更新介面頁數
m_PanelText.text = string.Format("{0}/{1}", m_PageIndex.ToString(), m_PageCount.ToString());
}
/// <summary>
/// 上一頁
/// </summary>
public void TouchPrevious()
{
if (m_PageCount <= 0)
return;
//第一頁時禁止向前翻頁
if (m_FrontPanelPageIndex <= 1)
return;
m_CanChangePage = false;
m_PageIndex = m_FrontPanelPageIndex -1;
if (m_PageIndex < 1)
m_PageIndex = 1;
m_BackPanel.localPosition = m_PrePos;
BindPage(m_BackPanel, m_PageIndex);
m_DoPrevious = true;
m_DoNext = false;
//更新介面頁數
m_PanelText.text = string.Format("{0}/{1}", m_PageIndex.ToString(), m_PageCount.ToString());
}
/// <summary>
/// 繫結指定索引處的頁面元素
/// </summary>
/// <param name="index">頁面索引</param>
private void BindPage(Transform tran,int index)
{
//列表處理
if (m_ItemsList == null || m_ItemsCount <= 0)
return;
//索引處理
if (index < 0 || index > m_ItemsCount)
return;
//按照元素個數可以分為1頁和1頁以上兩種情況
if (m_PageCount == 1)
{
int canDisplay = 0;
for (int i = m_PerPageCount; i > 0; i--)
{
if (canDisplay < m_PerPageCount && canDisplay< m_ItemsList.Count)
{
BindGridItem(tran.GetChild(canDisplay), m_ItemsList[m_PerPageCount - i]);
tran.GetChild(canDisplay).gameObject.SetActive(true);
}
else
{
//對超過canDispaly的物體實施隱藏
tran.GetChild(canDisplay).gameObject.SetActive(false);
}
canDisplay += 1;
}
}
else if (m_PageCount > 1)
{
//1頁以上需要特別處理的是最後1頁
//和1頁時的情況類似判斷最後一頁剩下的元素數目
//第1頁時顯然剩下的為12所以不用處理
if (index == m_PageCount)
{
int canDisplay = 0;
for (int i = m_PerPageCount; i > 0; i--)
{
//最後一頁剩下的元素數目為 m_ItemsCount - 12 * (index-1)
if (canDisplay < m_ItemsCount - m_PerPageCount * (index - 1))
{
BindGridItem(tran.GetChild(canDisplay), m_ItemsList[m_PerPageCount * index - i]);
tran.GetChild(canDisplay).gameObject.SetActive(true);
}
else
{
//對超過canDispaly的物體實施隱藏
tran.GetChild(canDisplay).gameObject.SetActive(false);
}
canDisplay += 1;
}
}
else
{
for (int i = m_PerPageCount; i > 0; i--)
{
BindGridItem(tran.GetChild(m_PerPageCount - i), m_ItemsList[m_PerPageCount * index - i]);
tran.GetChild(m_PerPageCount - i).gameObject.SetActive(true);
}
}
}
}
/// <summary>
/// 載入一個Sprite
/// </summary>
/// <param name="assetName">資源名稱</param>
private Sprite LoadSprite(string assetName)
{
Texture texture = (Texture)Resources.Load(assetName);
Sprite sprite = Sprite.Create((Texture2D)texture, new Rect(0, 0, texture.width, texture.height), new Vector2(0.5f, 0.5f));
return sprite;
}
/// <summary>
/// 將一個GridItem例項繫結到指定的Transform上
/// </summary>
/// <param name="trans"></param>
/// <param name="gridItem"></param>
private void BindGridItem(Transform trans, GridItem gridItem)
{
//trans.GetComponent<Image>().sprite = LoadSprite(gridItem.ItemSprite);
trans.GetComponent<Text>().text = gridItem.cnName;
}
}