public void AchieveHandGrid(GameContainerItem handGridItem, bool myself) { //清除 foreach (HandCellView handCellView in handCellViews) { handCellPool.Push(handCellView); } //重新 for (int i = 0; i < handGridItem.cardEntryList.Count(); i++) { CardEntry handCellItem = handGridItem.cardEntryList[i]; Vector3 position = new Vector3(); //position = HandMetrics.erectPosition(position, handCellItem.X); //创建一个格子实例 // HandCellView cell = Instantiate<HandCellView>(cellPrefab); HandCellView cell = handCellPool.Pop(); //设置图片 //cell.GetComponent<HandCellInstance>().SetImage(); cell.transform.SetParent(transform, false); cell.transform.localPosition = position; cell.myself = myself; cell.LoadHandCellItem(handCellItem); handCellViews.Add(cell); } //渲染需要放在格子生成完毕后 //不再渲染,改为用贴图 //handMesh.Triangulate(handCellViews); }
//确定顶点 void Triangulate(HandCellView cell) { Vector3 center = cell.transform.localPosition; Vector3[] arrayCorners = HandMetrics.getCorners(); for (int i = 0; i < 4; i++) { AddTriangle( center, center + arrayCorners[i], center + arrayCorners[i + 1] ); AddTriangleColor(Color.white); } }
//添加一张牌的动画 public IEnumerator PlayerDrawOneCardEnumerator(CardEntry handCellItem, UnityAction callBack) { Vector3 position = new Vector3(); //position = HandMetrics.erectPosition(position, handCellItem.X); //创建一个格子实例 // HandCellView cell = Instantiate<HandCellView>(cellPrefab); HandCellView cell = handCellPool.Pop(); //设置图片 //cell.GetComponent<HandCellInstance>().SetImage(); cell.transform.SetParent(transform, false); cell.transform.localPosition = position; cell.myself = myself; cell.LoadHandCellItem(handCellItem); handCellViews.Add(cell); yield return(new WaitForSeconds(0.25f)); callBack(); }
//移除一张牌 public void PlayerRemoveOneCard(CardEntry handCellItem, UnityAction callBack) { //清除 int needRemoveNum = -1; for (int num = 0; num < handCellViews.Count; num++) { HandCellView handCellView = handCellViews[num]; if (handCellView.handCellItem.uuid == handCellItem.uuid) { needRemoveNum = num; handCellPool.Push(handCellView); break; } } if (needRemoveNum > -1) { handCellViews.RemoveAt(needRemoveNum); } callBack(); }