using UnityEngine; using System.Collections; using System.Collections.Generic; public struct WelfareEveryDaySingInItemInfo { public int _ItemId; public int _ItemCount; public int _ItemState; public int _NodeId; public int _SubNodeId; public bool _IsDouble; public int _Day; // 日期 public bool _isSpecial; public string _vipDoubleIconPath; public WelfareEveryDaySingInItemInfo(int _ItemId, int _ItemCount, int _ItemState, int _NodeId, int _SubNodeId, int _IsDouble, int _Day, int _isSpecial, string vipDoubleIconPath) { this._ItemId = _ItemId; this._ItemCount = _ItemCount; this._ItemState = _ItemState; this._NodeId = _NodeId; this._SubNodeId = _SubNodeId; this._IsDouble = _IsDouble == 1; this._Day = _Day; this._isSpecial = _isSpecial == 1; this._vipDoubleIconPath = vipDoubleIconPath; } } public class WelfareEveryDaySinginCtr : WelfarePageBaseCS { public GameObject[] decorates; // 左侧装饰物体 public static WelfareEveryDaySinginCtr Instance; private void Awake() { Instance = this; } private void OnDestroy() { Instance = null; } public override void OnPacketRec(NodePageInfoRet packet) { base.OnPacketRec(packet); if (_RewList.Count < packet._SubNodeList.Count) { InitSubNode(); } else { RefreshItemState(); } } public void RefreshItemState() { _RewList = new List(); for (int index = 0; index < _Packet._SubNodeList.Count; index++) { WelfareEveryDaySingInItemInfo info = new WelfareEveryDaySingInItemInfo( _Packet._SubNodeList[index]._RewList[0]._ItemId, _Packet._SubNodeList[index]._RewList[0]._ItemNum, _Packet._SubNodeList[index]._SubNodeState, _Packet._NodeId, _Packet._SubNodeList[index]._SubNodeId, _Packet._SubNodeList[index]._IsDouble, index + 1, _Packet._SubNodeList[index].isSpecialRew, _Packet._SubNodeList[index].vipDoubleIconPath); _RewList.Add(info); } _SubNodeContainer.ForeachActiveItem(item => { for(int index = 0; index < _RewList.Count; index++) { if(_RewList[index]._NodeId == item._NodeId && _RewList[index]._SubNodeId == item._SubNodeId) { item._ItemState = _RewList[index]._ItemState; item.InitRewState(); } } }); // 更新左侧物体数目 RefreshDecorates(); ShowFirstCanGetAward(); } List _RewList = new List(); public void InitSubNode() { _RewList = new List(); for (int index = 0; index < _Packet._SubNodeList.Count; index++) { WelfareEveryDaySingInItemInfo info = new WelfareEveryDaySingInItemInfo( _Packet._SubNodeList[index]._RewList[0]._ItemId, _Packet._SubNodeList[index]._RewList[0]._ItemNum, _Packet._SubNodeList[index]._SubNodeState, _Packet._NodeId, _Packet._SubNodeList[index]._SubNodeId, _Packet._SubNodeList[index]._IsDouble, index + 1, _Packet._SubNodeList[index].isSpecialRew, _Packet._SubNodeList[index].vipDoubleIconPath); _RewList.Add(info); } _SubNodeContainer.InitContentItem(_RewList); // 更新左侧物体数目 RefreshDecorates(); //定位到第一个可以领取的Award ShowFirstCanGetAward(); } public void ShowFirstCanGetAward() { bool _hasFind = false; for(int index = 0; index < _RewList.Count; index++) { if(_RewList[index]._ItemState == 1 //可以领取 || _RewList[index]._ItemState == 3 && gameObject.activeInHierarchy) //可以补签 { _hasFind = true; StartCoroutine(ShowCanGetAward(_RewList[index]._SubNodeId)); break; } } if(!_hasFind && _RewList !=null && _RewList.Count > 0 && gameObject.activeInHierarchy) //默认显示第一个 StartCoroutine(ShowCanGetAward(_RewList[0]._SubNodeId)); } public void RefreshDecorates() { // 更新左侧物体数目 int count = Mathf.CeilToInt(_Packet._SubNodeList.Count / 7.0f); for (int i = 0; i < decorates.Length; ++i) { if (i < count) { decorates[i].SetActive(true); } else { decorates[i].SetActive(false); } } } public RectTransform _containerObjRec; public Transform _containerObjTrans; public RectTransform _viewPortRectTrans; private float minDis = 0.0f; IEnumerator ShowCanGetAward(int subNodeId) { yield return new WaitForEndOfFrame(); var _showItemAnchoredPosY = 0.0f; _SubNodeContainer.ForeachActiveItem(item =>{ if(item._SubNodeId == subNodeId) { var itemRec = item.gameObject.GetComponent(); _showItemAnchoredPosY = Mathf.Abs(itemRec.anchoredPosition.y); var needShowAnchoredPosY = Mathf.Clamp(_showItemAnchoredPosY, minDis, _containerObjRec.sizeDelta.y - _viewPortRectTrans.sizeDelta.y > minDis ? _containerObjRec.sizeDelta.y - _viewPortRectTrans.sizeDelta.y : minDis); _containerObjRec.anchoredPosition = new Vector2(0, needShowAnchoredPosY - _SubNodeContainer._LayoutGroup.padding.top); } }); yield break; } }