/// <summary> /// 位置調整 /// </summary> private void PositionAdjustment(){ cardPosition = new List<Vector2>(); // 控制在一定寬度內 float _width = cardWidth + maxSpacing; if(ownCards.Count > 5){ _width = _width / (1f + (ownCards.Count - 5) / (5 - 1) ); } //是否為奇數 float odd = 1f; if(ownCards.Count % 2 == 1){ odd = 0; } //最左邊的位置 float x = -((_width * (int)(ownCards.Count / 2))) + _width / 2 * odd; //4為最左邊牌的旋轉角度,5為當滿五張牌時,最旁邊的牌角度為4 //也就是改成6,滿六張牌旁邊才會為4 float z = 4f / (5f - 1f) * (ownCards.Count - 1f); z = z > 4f? 4f: z; for (int i = 0; i < ownCards.Count; i++) { float z1 = ((float)ownCards.Count - 1f); z1 = z1 == 0 ? 1 : z1; cardLocation[i].transform.rotation = Quaternion.Euler(0f, 0f, z - (z * 2f) / z1 * i); cardPosition.Add(new Vector2(x + _width * i, transform.position.y)); } } |

cardPosition = new List<Vector2>(); // 控制在一定寬度內 float _width = cardWidth + maxSpacing; //最旁邊的位置 float _x = ((_width * (int)(5 / 2))); //最左邊 Vector3 a = new Vector3(-_x, 1f, 0); //最右邊 Vector3 b = new Vector3(_x, 1f, 0); //改變弧度值 float c = 1000f; //弧度中心點 Vector3 center = (a + b) * 0.5f; center -= new Vector3(0, c, 0); a -= center; b -= center; for (int i = 1; i < ownCards.Count + 1; i++) { Vector3 v3 = Vector3.Slerp(a, b,i * (1f / (ownCards.Count + 1))); //減掉改變弧度時多餘的高度c v3 = new Vector3(v3.x, v3.y - c, v3.z); cardPosition.Add(v3); } |