public void DoDescendWallTween(WallPieceView wallPieceView, Vector3 direction) { _tweening = true; rigidbody.velocity = Vector3.zero; rigidbody.detectCollisions = false; TweenOffWall(wallPieceView, direction); }
public void DoAscendWallTween(WallPieceView wallPieceView) { _tweening = true; rigidbody.velocity = Vector3.zero; rigidbody.detectCollisions = false; TweenToWallHeight(wallPieceView); }
public void SetModel(Wall wall) { _model = wall; foreach (WallPiece wallPiece in wall.WallPieces) { bool onCorner = _model.OnCorner(wallPiece.Coord); string prefabName = (onCorner ? "WoodWallCornerView" : "WoodWallSideView"); WallPieceView wallPieceView = UnityUtils.LoadResource <GameObject>("Prefabs/" + prefabName, true).GetComponent <WallPieceView>(); Vector3 pos = new Vector3(wallPiece.Coord.X * GameConfig.BLOCK_SIZE, 0, wallPiece.Coord.Y * GameConfig.BLOCK_SIZE); wallPieceView.transform.position = pos; float angle = 0; if (onCorner) { if (wallPiece.Coord.X == -wall.Radius && wallPiece.Coord.Y == -wall.Radius) { angle = 90.0f; } else if (wallPiece.Coord.X == -wall.Radius && wallPiece.Coord.Y == wall.Radius) { angle = 180.0f; } else if (wallPiece.Coord.X == wall.Radius && wallPiece.Coord.Y == wall.Radius) { angle = 270.0f; } } else { if (wallPiece.Coord.X == -wall.Radius) { angle = 90.0f; } else if (wallPiece.Coord.Y == wall.Radius) { angle = 180.0f; } else if (wallPiece.Coord.X == wall.Radius) { angle = 270.0f; } } wallPieceView.transform.Rotate(new Vector3(0, angle, 0)); //wallPieceView.transform.localScale = new Vector3(GameConfig.BLOCK_SIZE, GameConfig.BLOCK_SIZE, GameConfig.BLOCK_SIZE); wallPieceView.transform.parent = gameObject.transform; _wallPieceViews.Add(wallPieceView); } }
private void TweenToWallHeight(WallPieceView wallPieceView) { Vector3 pos = transform.position; TweenParms parms = new TweenParms(); parms.Prop("position", new Vector3(pos.x, wallPieceView.Height, pos.z)); parms.Ease(EaseType.Linear); parms.OnComplete(OnTweenToWallHeightComplete, wallPieceView.transform.position); HOTween.To(gameObject.transform, 0.5f, parms); }
private void OnConfirmPress() { if (_playerView.Dead) { _playerView.gameObject.transform.position = Vector3.zero; _playerView.Resurrect(); return; } WallPieceView touchedPiece = _mapView.WallView.GetTouchedPiece(); if (!_playerView.Model.OnWall) { if (touchedPiece != null) { _playerView.DoAscendWallTween(touchedPiece); GameManager.Instance.GameModel.Player.OnWall = true; } } else { if (touchedPiece != null) { Vector3 pos = _playerView.transform.position; XY mapCoord = _mapView.GetMapCoordFromWorldCoord(pos); bool onCorner = GameManager.Instance.GameModel.Map.Wall.OnCorner(mapCoord); bool onHori = GameManager.Instance.GameModel.Map.Wall.OnHorizontal(mapCoord); bool onVert = GameManager.Instance.GameModel.Map.Wall.OnVertical(mapCoord); float h = Input.GetAxis("Horizontal"); float v = Input.GetAxis("Vertical"); Camera camera = GameManager.Instance.PlayerCamera.camera; Vector3 forward = camera.transform.forward; Vector3 direction = camera.transform.right * h + new Vector3(forward.x, 0, forward.z) * v; if (onCorner && (direction.z != 0 || direction.x != 0)) { // TODO: ascend corners } else if (onHori && direction.z != 0) { DescendFromWall(touchedPiece, new Vector3(0, 0, direction.z < 0 ? -1 : 1)); } else if (onVert && direction.x != 0) { DescendFromWall(touchedPiece, new Vector3(direction.x < 0 ? -1 : 1, 0, 0)); } } } }
private void TweenOffWall(WallPieceView wallPieceView, Vector3 direction) { Vector3 target = (wallPieceView.transform.position + new Vector3(0, wallPieceView.Height, 0)) + (direction * GameConfig.BLOCK_SIZE) * (0.75f); Vector3 aboveGroundPos = wallPieceView.transform.position + (direction * GameConfig.BLOCK_SIZE); Vector3 groundPos = new Vector3(aboveGroundPos.x, 0, aboveGroundPos.z); TweenParms parms = new TweenParms(); parms.Prop("position", target); parms.Ease(EaseType.Linear); parms.OnComplete(OnTweenOffWallComplete, groundPos); HOTween.To(gameObject.transform, 0.5f, parms); }
private void DescendFromWall(WallPieceView wallPieceView, Vector3 direction) { GameManager.Instance.GameModel.Player.OnWall = false; _playerView.DoDescendWallTween(wallPieceView, direction); }