public override void Update() { base.Update(); if (type != last) { last = type; MazeTool maze = transform.parent.parent.GetComponent <MazeTool>(); if (maze != null) { maze.toString = maze.ToString(); } } }
/// <summary> /// Parses the given maze, and fits it into the data based off of the translate function. /// </summary> private void ParseMazeTool(MazeTool maze, Func <int, int, Point3> translate) { for (int i = 0; i < maze.walls.GetLength(0); ++i) { for (int j = 0; j < maze.walls.GetLength(1); ++j) { Point3 pos = translate(i, j); // parse walls MazeToolWall wall = maze.walls[i, j]; if (wall != null) { data[pos.x, pos.y, pos.z] = wall.gameObject.activeSelf; switch (wall.type) { case MazeToolWall.WallType.door: door = pos; break; case MazeToolWall.WallType.sliding: sliding.Add(pos); break; } if (wall.type == MazeToolWall.WallType.door) { door = pos; } } // parse cells MazeToolCell cell = maze.cells[i, j]; if (cell != null) { switch (cell.type) { case MazeToolCell.CellType.startPos: startPos = pos; break; case MazeToolCell.CellType.monsterPos: monsterPos = pos; break; case MazeToolCell.CellType.key: key = pos; break; } } } } }
public MazeStructure(MazeTool top, MazeTool bottom, MazeTool left, MazeTool right, MazeTool front, MazeTool back, float radius) { // initialize data this.mazeTool = top; data = new bool[2 + mazeTool.walls.GetLength(0), 2 + mazeTool.walls.GetLength(0), 2 + mazeTool.walls.GetLength(1)]; for (int i = 0; i < data.GetLength(0); ++i) { for (int j = 0; j < data.GetLength(1); ++j) { for (int k = 0; k < data.GetLength(2); ++k) { data[i, j, k] = true; } } } // verify that MazeTools have the same dimensions this.radius = radius; length = top.walls.GetLength(0); if (top.walls.GetLength(0) != length || top.walls.GetLength(1) != length || bottom.walls.GetLength(0) != length || bottom.walls.GetLength(1) != length || left.walls.GetLength(0) != length || left.walls.GetLength(1) != length || right.walls.GetLength(0) != length || right.walls.GetLength(1) != length || front.walls.GetLength(0) != length || front.walls.GetLength(1) != length || back.walls.GetLength(0) != length || back.walls.GetLength(1) != length) { throw new Exception("MazeTool lengths don't match."); } length = 1 + length / 2; // parse all the mazeTools int high = data.GetLength(0) - 2; ParseMazeTool(top, (i, j) => new Point3(i + 1, high, high - j)); ParseMazeTool(bottom, (i, j) => new Point3(i + 1, 1, j + 1)); ParseMazeTool(left, (i, j) => new Point3(1, j + 1, i + 1)); ParseMazeTool(right, (i, j) => new Point3(high, j + 1, high - i)); ParseMazeTool(front, (i, j) => new Point3(high - i, j + 1, 1)); ParseMazeTool(back, (i, j) => new Point3(i + 1, j + 1, high)); Debug.Log("key: " + key + "; start: " + startPos + "; monster: " + monsterPos + "; door: " + door); }
public void Init() { levelIndex = (int)MazeTool.errorFloat; Reset(); FileTool fileTool = new FileTool(); ArrayList list = fileTool.LoadFile(Application.persistentDataPath, fileName); if (list != null) { object msgObj = new object(); if (SimpleJson.SimpleJson.TryDeserializeObject(list [0].ToString(), out msgObj)) { JsonObject msgJson = (JsonObject)msgObj; object levelIndexObj; if (msgJson.TryGetValue("levelIndex", out levelIndexObj)) { int.TryParse(levelIndexObj.ToString(), out levelIndex); } object bornPositionObj; if (msgJson.TryGetValue("bornPosition", out bornPositionObj)) { bornPosition = MazeTool.StringToVector3(bornPositionObj.ToString()); } object bodyRotationObj; if (msgJson.TryGetValue("bodyRotation", out bodyRotationObj)) { bodyRotation = MazeTool.StringToQuaternion(bodyRotationObj.ToString()); } object headRotationObj; if (msgJson.TryGetValue("headRotation", out headRotationObj)) { headRotation = MazeTool.StringToQuaternion(headRotationObj.ToString()); } object projectorMessageListObj; if (msgJson.TryGetValue("projectorMessageList", out projectorMessageListObj)) { JsonArray projectorMessageArray = (JsonArray)projectorMessageListObj; for (int i = 0; i < projectorMessageArray.Count; i++) { JsonObject json = (JsonObject)projectorMessageArray [i]; ProjectorMessage pm = new ProjectorMessage(); object positionObj; if (json.TryGetValue("position", out positionObj)) { pm.position = MazeTool.StringToVector3(positionObj.ToString()); } object rotationObj; if (json.TryGetValue("rotation", out rotationObj)) { pm.rotation = MazeTool.StringToQuaternion(rotationObj.ToString()); } object typeObj; if (json.TryGetValue("type", out typeObj)) { pm.type = (PaintType)System.Enum.Parse(typeof(PaintType), typeObj.ToString()); } projectorMessageList.Add(pm); } } } } // Log (); }
void Update() { // calculate up, forwards and right Vector3 up = -transform.position.normalized; Vector3 forwards = Vector3.RotateTowards(up, transform.forward, Mathf.PI / 2, 1).normalized; if (Vector3.Angle(up, forwards) < 90) { forwards = Vector3.RotateTowards(-up, transform.forward, Mathf.PI / 2, 1).normalized; } Vector3 rights = Vector3.Cross(forwards, up).normalized; // handle left-right camera movement (from mouse) if (Input.GetAxis("Mouse X") > 0) { forwards = Vector3.RotateTowards(forwards, -rights, Input.GetAxis("Mouse X") / 4, 1); } else { forwards = Vector3.RotateTowards(forwards, rights, -Input.GetAxis("Mouse X") / 4, 1); } rights = Vector3.Cross(forwards, up).normalized; // sum the WASD/Arrows movement float forward = 0, right = 0; if (Input.GetKey(KeyCode.W) || Input.GetKey(KeyCode.UpArrow)) { forward += 1; } if (Input.GetKey(KeyCode.S) || Input.GetKey(KeyCode.DownArrow)) { forward -= 1; } if (Input.GetKey(KeyCode.D) || Input.GetKey(KeyCode.RightArrow)) { right += 1; } if (Input.GetKey(KeyCode.A) || Input.GetKey(KeyCode.LeftArrow)) { right -= 1; } // calculate where to move, then move Vector3 dest = transform.position + (forward * forwards + right * transform.right.normalized).normalized * 0.4f; this.playerRigid.velocity = (dest - transform.position) / Time.fixedDeltaTime; this.playerRigid.MovePosition(this.playerRigid.position.normalized * (radius - 3.5f)); // handle up-down camera movement (from mouse, from sphere) if (angle < Mathf.PI / 2) { forwards = Vector3.RotateTowards(up, forwards, angle, 1); } else { forwards = Vector3.RotateTowards(forwards, -up, angle - Mathf.PI / 2, 1); } transform.localRotation = Quaternion.LookRotation(forwards, -transform.position); angle = Mathf.Max(Mathf.Min(angle - Input.GetAxis("Mouse Y") / 4, 0.99f * Mathf.PI), 0.01f * Mathf.PI); }