public GameObject GetWall(WallPos p) { switch (p) { case WallPos.top: return(midTopWall); case WallPos.bot: return(midBotWall); case WallPos.left: return(midLeftWall); case WallPos.right: return(midRightWall); case WallPos.topLeft: return(topLeftWall); case WallPos.topRight: return(topRightWall); case WallPos.botLeft: return(botLeftWall); case WallPos.botRight: return(botRightWall); } return(floor); }
//设置墙与地板的索引,输入 墙的对象,地块的世界坐标,墙在地板中的位置 private void setWallIndex(GameObject wallObj, Vector3Int placePos, WallPos tmpWallPos) { placeWall tmpSpaceWall = placeGrid[placePos]; //获得地块对象 if (tmpSpaceWall != null) { switch (tmpWallPos) { case WallPos.Top: { tmpSpaceWall.topWall = wallObj; wallObj.name = tmpSpaceWall.gameObject.name + "Top"; } break; case WallPos.Bottom: { tmpSpaceWall.bottomWall = wallObj; wallObj.name = tmpSpaceWall.gameObject.name + "Bottom"; } break; case WallPos.Left: { tmpSpaceWall.leftWall = wallObj; wallObj.name = tmpSpaceWall.gameObject.name + "Left"; } break; case WallPos.Right: { tmpSpaceWall.rightWall = wallObj; wallObj.name = tmpSpaceWall.gameObject.name + "Right"; } break; // default: { } break; } } else { string msg = "setWallIndex error! Wall not find ! pos " + DebugMsg.instance.Msg(placePos) + "\n"; Debug.LogError(msg); } }
void Start() { walls = new List <WallPos>(); line.positionCount = (transform.childCount + 1) * RECT_LINES * STRAIGHT_LINES; // Walls的数量加上最外围的墙 emptyVector3s = new Vector3[line.positionCount]; for (int i = 0; i < emptyVector3s.Length; ++i) { emptyVector3s[i] = Vector3.zero; } for (int i = 0; i < this.transform.childCount; ++i) { // 点的计算 WallPos wallPos = new WallPos(); var wall = this.transform.GetChild(i); var tmp_x = wall.localScale.x / 2; var tmp_y = wall.localScale.y / 2; var angle = wall.localEulerAngles.z * PI / 180; wallPos.pos_00 = GetPositionByAngle3(-tmp_x, -tmp_y, angle, wall); wallPos.pos_01 = GetPositionByAngle3(-tmp_x, tmp_y, angle, wall); wallPos.pos_10 = GetPositionByAngle3(tmp_x, -tmp_y, angle, wall); wallPos.pos_11 = GetPositionByAngle3(tmp_x, tmp_y, angle, wall); walls.Add(wallPos); } }
public bool direction; // false = 0 degree, true = 90 degree public Wall(Grid a, Grid b, bool d) { A = a; B = b; exist = true; direction = d; Vector2i sum = A.pos + B.pos; pos = new WallPos((float)sum.x / 2, (float)sum.y / 2, direction); }
//传入地板的世界坐标, 墙的位置, 返回墙的gameobject private GameObject getWallObj(Vector3Int pPos, WallPos pWallPos) { GameObject res = null; placeWall tmpPlaceWall = placeGrid[pPos]; if (pWallPos == WallPos.Bottom) { res = tmpPlaceWall.bottomWall; } else if (pWallPos == WallPos.Top) { res = tmpPlaceWall.topWall; } else if (pWallPos == WallPos.Left) { res = tmpPlaceWall.leftWall; } else if (pWallPos == WallPos.Right) { res = tmpPlaceWall.rightWall; } return(res); }