// Use this for initialization void Start() { //clean all foreach (Transform child in transform) { GameObject.Destroy(child.gameObject); } //中心 Bean.Bean bean = createInitBean(); bean.row = 0; bean.col = 0; allBeans["0_0"] = bean; for (int index = 0; index < 6; index++) { Bean.Bean round = createInitBean(); Vector2 correctDt = Utils.getVecByAngle(index * 60) * (bean.getRadius() + round.getRadius()); round.transform.localPosition = bean.transform.localPosition + (Vector3)correctDt; AddBean(bean, round); } }
public void AddBean(Bean.Bean touchBean, Bean.Bean bean) { bean.transform.parent = transform; bean.planet = this; //校验修正位置 Vector2 dt = bean.transform.localPosition - touchBean.transform.localPosition; float ang = Utils.getAngleByVec2(dt); int index = Mathf.FloorToInt((ang + 30) / 60) % 6; float correctAng = index * 60; Vector2 correctDt = Utils.getVecByAngle(correctAng) * (bean.getRadius() + touchBean.getRadius()); bean.transform.localPosition = touchBean.transform.localPosition + (Vector3)correctDt; //加入roundbeans //touchBean.roundBeans[index] = bean; //int otherSideIndex = (index + 3)%6; //bean.roundBeans[otherSideIndex] = touchBean; //行列 int[] coord = getCoordByIndex(touchBean.row, touchBean.col, index); int newRow = coord[0]; int newCol = coord[1]; bean.row = newRow; bean.col = newCol; string key = newRow.ToString() + "_" + newCol.ToString(); allBeans[key] = bean; }