public void ArrayHandCards(byte[] cards, byte count) { //计算间距 int nColSpace = CardColSpace; if (gameObject.activeSelf == false) { gameObject.SetActive(true); } foreach (GameObject obj in _cardlist) { UICard car = obj.GetComponent <UICard>(); int nIdx = GetCardIndex(cards, count, car.CardData); if (nIdx != -1) { float zValue = ((float)nIdx) / 100 + 1; obj.transform.localScale = new Vector3(1, 1, zValue); int nRow = (int)(nIdx / RowMaxCards); int nCol = (int)(nIdx % RowMaxCards); Vector3 NewPos = new Vector3(nColSpace * nCol, CardRowSpace * nRow * (-1), 0); TweenPosition.Begin(obj, 0.8f, NewPos); car.SetPos(NewPos); car.recvclick = true; obj.name = "card_" + nIdx.ToString(); UISlicedSprite sp = obj.GetComponentInChildren <UISlicedSprite>(); sp.depth = BaseDepth + nIdx; } } }
public void AppendHandCard(byte[] cards, byte count) { if (cards == null || count == 0) { return; } //牌数据 Buffer.BlockCopy(cards, 0, _cardata, _cardcount, count); _cardcount += count; //计算间距 int nColSpace = CardColSpace; if (gameObject.activeSelf == false) { gameObject.SetActive(true); } //牌对象 for (int i = _cardcount - count; i < _cardcount; i++) { // GameObject obj = (GameObject) Instantiate(Resources.Load(CardPrefabs)); GameObject obj = Instantiate(CardPrefabs); obj.transform.parent = transform; float zValue = ((float)i) / 100 + 1; obj.transform.localScale = new Vector3(1, 1, zValue); int nRow = (int)(i / RowMaxCards); int nCol = (int)(i % RowMaxCards); Vector3 OldPos = Vector3.zero; if (Align == ccAlignType.CENTER) { OldPos = new Vector3(0, -200, 0); } else if (Align == ccAlignType.LEFT) { OldPos = new Vector3(-100, -100, 0); } else if (Align == ccAlignType.RIGHT) { OldPos = new Vector3(100, -100, 0); } Vector3 NewPos = new Vector3(nColSpace * nCol, CardRowSpace * nRow * (-1), 0); obj.transform.localPosition = OldPos; TweenPosition.Begin(obj, 0.2f, NewPos); obj.name = "card_" + i.ToString(); //Card UICard card = obj.GetComponent <UICard>(); card.shoot = new Vector3(0, ShootSpace, 0); card.recvclick = Positively; card.duration = Duration; card.CardData = _cardata[i]; card.SetPos(NewPos); card.SetShoot(false); card.SetMask(false); card.recvclick = false; //Sprite UISlicedSprite sp = obj.GetComponentInChildren <UISlicedSprite>(); sp.depth = BaseDepth + i; /*if(Align == ccAlignType.CENTER) * { * sp.pivot = UIWidget.Pivot.Center; * } * else if(Align == ccAlignType.LEFT) * { * sp.pivot = UIWidget.Pivot.Left; * } * else if(Align == ccAlignType.RIGHT) * { * sp.pivot = UIWidget.Pivot.Right; * }*/ if (DisplayItem) { sp.spriteName = GetCardTex(_cardata[i]); } else { sp.spriteName = "card_back"; } //事件 UIButtonMessage msg = obj.GetComponent <UIButtonMessage>(); msg.functionName = ClickEvent; msg.target = target; _cardlist.Add(obj); } int nX = (-1) * (int)(CardSize.x / 2); transform.localPosition = _oldPostion + new Vector3(nX - 400 + 110, 0, 0); }