public void ResetAllShoot() { foreach (GameObject obj in _cardlist) { UICard card = obj.GetComponent <UICard>(); card.SetShoot(false); card.SetMask(false); } }
public void GetShootCard(ref byte[] cards, ref byte count) { foreach (GameObject obj in _cardlist) { UICard card = obj.GetComponent <UICard>(); if (card.Selected) { cards[count++] = card.CardData; } } }
public void SetShootCard(byte[] cards, byte count) { ResetAllShoot(); for (byte i = 0; i < count; i++) { //Debug.LogError("cards[i] = " + cards[i] % 16); 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 = (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); obj.transform.localScale = CardScale; 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(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); } 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); } } }
private void OnGUI() { if (Event.current.type == EventType.MouseDown) { //记录鼠标按下的位置 _first = Input.mousePosition; _second = Input.mousePosition; templist.Clear(); } if (Event.current.type == EventType.mouseDrag) { //记录鼠标拖动的位置 _second = Input.mousePosition; if (transform.name == "ctr_hand_cards" && UIGame.isCanSmart == true) { if (_cardlist.Count >= 2) { UICard tempCardOne = transform.GetChild(0).GetComponent <UICard>(); Vector3 psOne = UICamera.currentCamera.WorldToScreenPoint(tempCardOne.transform.position); UICard tempCardTwo = transform.GetChild(1).GetComponent <UICard>(); Vector3 psTwo = UICamera.currentCamera.WorldToScreenPoint(tempCardTwo.transform.position); float Xdelta = System.Math.Abs(psTwo.x - psOne.x); foreach (GameObject obj in _cardlist) { if (obj != null) { UICard card = obj.GetComponent <UICard>(); Vector3 cardPosition = UICamera.currentCamera.WorldToScreenPoint(card.transform.position); if ( ((Input.mousePosition.x > cardPosition.x - 54) && (Input.mousePosition.x < cardPosition.x - 54 + Xdelta)) && ((Input.mousePosition.y > cardPosition.y - 72) && (Input.mousePosition.y < cardPosition.y + 72)) ) { card.SetMask(true); templist[card.name] = card; } } } } } } if (Event.current.type == EventType.MouseUp) { if (_second.y > 160 && AllowDropCard && (_second.y - _first.y) > 10) { _first = Vector3.zero; _second = Vector3.zero; foreach (GameObject obj in _cardlist) { obj.GetComponent <UICard>().SetMask(false); } if (MoveUpEvent != "" && target != null) { target.SendMessage(MoveUpEvent); } return; } List <byte> newCards = new List <byte>(); foreach (KeyValuePair <string, UICard> kv in templist) { if (kv.Value.CardData > 0) { newCards.Add(kv.Value.CardData); } } byte[] myCards = new byte[20]; if (newCards.Count > 0) { Help.PokerHelper.SmartPickupCard(newCards.ToArray(), ref myCards); SetShootCard(myCards, (byte)(myCards.Length)); /* * Debug.LogError("count = " + newCards.Count); * Debug.LogError("选中的牌"); * for (byte i = 0; i < newCards.Count; i++) * { * Debug.LogError("newCards = " + newCards[i]%16); * } * Debug.LogError("返回的牌"); * for (byte i = 0; i < (byte)(myCards.Length); i++) * { * Debug.LogError("myCards = " + myCards[i]%16); * } */ } _first = Vector3.zero; _second = Vector3.zero; templist.Clear(); if (MoveSelectEvent != "" && target != null) { target.SendMessage(MoveSelectEvent); } } }
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); }