|
一般我是这样的
// Filename: XXXPanel.cs
// Summary: XXX界面
// Version: 1.0.0
// Author: xxx
// Date: 2016/05/04 11:37
#region
using System.Collections.Generic;
using MyExtensionMethod;
using Network;
using UnityEngine;
#endregion
public class XXXPanel : MonoBehaviour
{
#region 变量定义
private GameObject m_rankItem;
private UIGrid m_grid;
private UIScrollView m_scrollView;
private GameObject m_leftArrow;
private GameObject m_rightArrow;
private ComponentList<ArenaRankItem, stPlayerInfoSub> m_rankIList;
/// <summary>
/// 翻页
/// </summary>
private PageTurn m_pageTurn;
private const int m_perPageCount = 6;
private const int m_perCellWidth = 160;
#endregion
#region 获取控件
private void FindObject(Transform tr)
{
tr.Find(ref m_rankItem, &#34;RankList/RankItem&#34;);
tr.Find(ref m_grid, &#34;RankList/ScrollView/Fill/Grid&#34;);
tr.Find(ref m_scrollView, &#34;RankList/ScrollView&#34;);
tr.Find(ref m_leftArrow, &#34;RankList/LeftArrow&#34;);
tr.Find(ref m_rightArrow, &#34;RankList/RightArrow&#34;);
}
#endregion
private void Awake()
{
FindObject(transform);
m_rankIList = new ComponentList<ArenaRankItem, stPlayerInfoSub>(m_grid.gameObject, m_rankItem);
}
public void UpdateWin(bool isShow = true)
{
if (!isShow)
{
Hidden(null);
return;
}
gameObject.SetVisiable(true);
m_rankIList.UpdateData(CData.arena.rankData.playerList);
LoadLookFaceImage();
int count = CData.arena.rankData.playerList.Count;
m_pageTurn = new PageTurn(m_scrollView, m_leftArrow, m_rightArrow, count, m_perPageCount, m_perCellWidth);
m_grid.onReposition = m_pageTurn.UpdateButtonState;
m_scrollView.ResetPosition();
m_grid.Reposition();
MoveListCurrPosToTarget(count);
m_scrollView.GetComponent<UIPanel>().onClipMove = OnListPanelClipMove;
m_canOpt = true;
}
private void MoveListCurrPosToTarget(int count)
{
// 主界面启动,对所有抽取的选手排名进行排序确定玩家所处的顺位。
// 当玩家顺位为最后三位时,则主界面初始显示最后6位;
// 当玩家顺位非最后三位时,主界面初始显示,玩家前4位、玩家、玩家后1位;
// 当玩家排名为前6位,主界面初始显示前6位。
int index = CData.arena.myIndexInList + 1;
if (count - index < 3)
{
Vector3 offset = new Vector3(-(count - m_perPageCount) * m_perCellWidth, 0);
m_scrollView.MoveRelative(offset);
m_pageTurn.UpdateButtonState();
}
else if (index > 6)
{
Vector3 offset = new Vector3(-(index + 1 - m_perPageCount) * m_perCellWidth, 0);
m_scrollView.MoveRelative(offset);
m_pageTurn.UpdateButtonState();
}
}
private void OnListPanelClipMove(UIPanel panel)
{
float offsetx = panel.clipOffset.x;
EventDispatcher.GameWorld.DispatchEvent(EventDefine.STR_ARENA_SCROLLVIEW_MOVE, offsetx);
}
} |
|