public void SetShootCard(byte[] cards, byte count) { ResetAllShoot(); for (byte i = 0; i < count; i++) { foreach (GameObject obj in _cardlist) { UICard card = obj.GetComponent <UICard>(); if (cards[i] == card.CardData) { card.SetShoot(true); } } } }
public void SetCardData(byte[] cards, byte count) { //清空 if (count == 0) { Array.Clear(_cardata, 0, _cardata.Length); _cardcount = 0; foreach (GameObject card in _cardlist) { Destroy(card); } _cardlist.Clear(); return; } //牌数据 Buffer.BlockCopy(cards, 0, _cardata, 0, count); _cardcount = count; int nColSpace = CardColSpace; if (AutoCalColSpace) { if (count < 2) { nColSpace = (int)(CardSize.x / 2); } else { nColSpace = (int)((800 - (int)CardSize.x) / (count - 1)); if (nColSpace > (int)(CardSize.x / 2)) { nColSpace = (int)(CardSize.x / 2); } } } //初始化 foreach (GameObject card in _cardlist) { Destroy(card); } _cardlist.Clear(); if (gameObject.activeSelf == false) { gameObject.SetActive(true); } //创建牌 for (int i = 0; i < _cardcount; i++) { GameObject obj = GetCardPrefabs(); 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); obj.transform.localPosition = new Vector3(nColSpace * nCol, CardRowSpace * nRow * (-1), 0); 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.SetShoot(false); card.SetMask(false); //Sprite UISlicedSprite sp = obj.GetComponentInChildren <UISlicedSprite>(); sp.depth = BaseDepth + i; if (DisplayItem) { if (_cardata[i] == 253) { sp.spriteName = "card_look"; } else if (_cardata[i] == 254) { sp.spriteName = "card_giveup"; } else if (_cardata[i] == 252) { sp.spriteName = "card_lose"; } else { sp.spriteName = GetCardTex(_cardata[i]); //显示牌型 } } else { if (_cardata[i] == 253) { sp.spriteName = "card_look"; } else if (_cardata[i] == 254) { sp.spriteName = "card_giveup"; } else if (_cardata[i] == 252) { sp.spriteName = "card_lose"; } else { sp.spriteName = "card_back"; } } //事件 //UIButtonMessage msg = obj.GetComponent<UIButtonMessage>(); //msg.functionName = ClickEvent; //msg.target = target; _cardlist.Add(obj); } if (Align == ccAlignType.CENTER) { float nXRate = transform.localScale.x; if (_cardcount > RowMaxCards) { int nX = (-1) * (((int)((RowMaxCards - 1) * nColSpace * nXRate) + (int)CardSize.x) / 2 - ((int)CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else { int nX = (-1) * (((int)((_cardcount - 1) * nColSpace * nXRate) + (int)CardSize.x) / 2 - ((int)CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } } else if (Align == ccAlignType.LEFT) { int nX = (-1) * (int)(CardSize.x / 2); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else if (Align == ccAlignType.RIGHT) { float nXRate = transform.localScale.x; if (_cardcount > RowMaxCards) { int nX = (-1) * (int)(((int)((RowMaxCards - 1) * nColSpace * nXRate) + CardSize.x) / 2 - (CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else { int nX = (-1) * (int)(((int)((_cardcount - 1) * nColSpace * nXRate) + CardSize.x) / 2 - (CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } } }
//发牌 public void AppendHandCard(byte bViewId, 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 = GetCardPrefabs(); 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; switch (bViewId) { case 0: { OldPos = new Vector3(120, 250, 0); break; } case 1: { OldPos = new Vector3(-230, 100, 0); break; } case 2: { OldPos = new Vector3(-230, -100, 0); break; } case 3: { OldPos = new Vector3(300, -100, 0); break; } case 4: { OldPos = new Vector3(300, 100, 0); break; } } Vector3 NewPos = new Vector3(nColSpace * nCol, CardRowSpace * nRow * (-1), 0); obj.transform.localPosition = OldPos; TweenPosition.Begin(obj, 0.4f, NewPos); //TweenRotation.Begin(obj,0.5f,Quaternion.Euler(new Vector3(0,0,180))); obj.name = "card_" + i.ToString(); //Card UICard card = obj.GetComponent <UICard>(); if (card == null) { card = obj.AddComponent <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) { if (_cardata[i] == 253) { sp.spriteName = "card_look"; } else if (_cardata[i] == 254) { sp.spriteName = "card_giveup"; } else if (_cardata[i] == 252) { sp.spriteName = "card_lose"; } else { sp.spriteName = GetCardTex(_cardata[i]); //Debug.LogWarning("_cardata["+i+"] = " + _cardata[i]); } } else { if (_cardata[i] == 253) { sp.spriteName = "card_look"; } else if (_cardata[i] == 254) { sp.spriteName = "card_giveup"; } else if (_cardata[i] == 252) { sp.spriteName = "card_lose"; } else { sp.spriteName = "card_back"; } } //事件 //UIButtonMessage msg = obj.GetComponent<UIButtonMessage>(); //msg.functionName = ClickEvent; //msg.target = target; _cardlist.Add(obj); } if (Align == ccAlignType.CENTER) { float nXRate = transform.localScale.x; if (_cardcount > RowMaxCards) { int nX = (-1) * (((int)((RowMaxCards - 1) * nColSpace * nXRate) + (int)CardSize.x) / 2 - ((int)CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else { int nX = (-1) * (((int)((_cardcount - 1) * nColSpace * nXRate) + (int)CardSize.x) / 2 - ((int)CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } } else if (Align == ccAlignType.LEFT) { int nX = (-1) * (int)(CardSize.x / 2); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else if (Align == ccAlignType.RIGHT) { float nXRate = transform.localScale.x; if (_cardcount > RowMaxCards) { int nX = (-1) * (int)(((int)((RowMaxCards - 1) * nColSpace * nXRate) + CardSize.x) / 2 - (CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else { int nX = (-1) * (int)(((int)((_cardcount - 1) * nColSpace * nXRate) + CardSize.x) / 2 - (CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } } }
public void OpenCardData(byte[] cards, byte count, int cardCount, bool displayItem) { //清空 if (count == 0) { Array.Clear(_cardata, 0, _cardata.Length); _cardcount = 0; foreach (GameObject card in _cardlist) { Destroy(card); } _cardlist.Clear(); return; } //牌数据 Buffer.BlockCopy(cards, 0, _cardata, 0, count); _cardcount = count; int nColSpace = CardColSpace; if (AutoCalColSpace) { if (count < 2) { nColSpace = (int)(CardSize.x / 2); } else { nColSpace = (int)((800 - (int)CardSize.x) / (count - 1)); if (nColSpace > (int)(CardSize.x / 2)) { nColSpace = (int)(CardSize.x / 2); } } } //初始化 foreach (GameObject card in _cardlist) { Destroy(card); } _cardlist.Clear(); //创建牌 for (int i = 0; i < _cardcount; i++) { GameObject obj = GetCardPrefabs(); 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); obj.transform.localPosition = new Vector3(nColSpace * nCol, CardRowSpace * nRow * (-1), 0); //头牌和尾牌隔开点 if (i >= 2) { obj.transform.localPosition += new Vector3(distancePos, 0, 0); } 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.SetShoot(false); card.SetMask(false); //Sprite UISlicedSprite sp = obj.GetComponentInChildren <UISlicedSprite>(); if (sp == null) { continue; } sp.depth = BaseDepth + i; if (displayItem) { if (_cardata[i] == 253) { sp.spriteName = "card_look"; } else if (_cardata[i] == 254) { sp.spriteName = "card_giveup"; } else if (_cardata[i] == 252) { sp.spriteName = "card_lose"; } else if (i >= cardCount) { sp.spriteName = GetCardTex(_cardata[i]); } else { sp.spriteName = "card_back"; } } else { if (_cardata[i] == 253) { sp.spriteName = "card_look"; } else if (_cardata[i] == 254) { sp.spriteName = "card_giveup"; } else if (_cardata[i] == 252) { sp.spriteName = "card_lose"; } else { sp.spriteName = "card_back"; } } _cardlist.Add(obj); } if (count == GameLogic.MAX_COUNT && displayItem == true) { if (cardCount == 0) { SetHeadTrialType(cards, count); } else { SetTrialType(cards, count); } } if (Align == ccAlignType.CENTER) { float nXRate = transform.localScale.x; if (_cardcount > RowMaxCards) { int nX = (-1) * (((int)((RowMaxCards - 1) * nColSpace * nXRate) + (int)CardSize.x) / 2 - ((int)CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else { int nX = (-1) * (((int)((_cardcount - 1) * nColSpace * nXRate) + (int)CardSize.x) / 2 - ((int)CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } } else if (Align == ccAlignType.LEFT) { int nX = (-1) * (int)(CardSize.x / 2); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else if (Align == ccAlignType.RIGHT) { float nXRate = transform.localScale.x; if (_cardcount > RowMaxCards) { int nX = (-1) * (int)(((int)((RowMaxCards - 1) * nColSpace * nXRate) + CardSize.x) / 2 - (CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } else { int nX = (-1) * (int)(((int)((_cardcount - 1) * nColSpace * nXRate) + CardSize.x) / 2 - (CardSize.x / 2)); transform.localPosition = _oldPostion + new Vector3(nX, 0, 0); } } }