private void CreatSortNodes(int length) { float width, interval, pos;//结点宽度,间距,起始生成位置 List <int> list = MyTools.GetList(DataType, length); //计算合理宽高 if (length < 10) { width = 100f; interval = width; pos = -(width * length) / 2; } else { width = DemoArea_length / (length + 2); interval = width; pos = -(1100 / 2 - width - width / 2); } Node.width = width; Node.verticalStandard = 100f; //计算合适的起始生成位置(锚点在中下) //生成结点 bool ShowNumFlag = true; if (length > 30) { ShowNumFlag = false; } for (int i = 0; i < length; i++) { GO_nodes.Add(Instantiate(view.NODE, view.DemoArea.transform)); nodes.Add(new Node(GO_nodes[i], list[i], i, ShowNumFlag)); //设置锚点,第三个参数为沿插入方向的宽度,在这里也就是高度 //设置高度,0-- > 高度100,15-- > 高度295 nodes[i].rect.SetInsetAndSizeFromParentEdge(RectTransform.Edge.Bottom, 0, 200);//100 + 195 / 15 * nodes[i].num nodes[i].rect.sizeDelta = new Vector2(width, nodes[i].rect.sizeDelta.y); nodes[i].rect.pivot = new Vector2(0.5f, 0f); nodes[i].rect.anchoredPosition = new Vector2(pos, 0); //生成位置移动到下一个 pos += interval; } //形变动画 float height = 35;//最短高度规定为35 int mmax = MyTools.GetListMax(list); float HeightOffset = (200 - height) / mmax; for (int i = 0; i < nodes.Count; i++) { nodes[i].Reshape(direction.VERTICAL, height + HeightOffset * nodes[i].num); } }