public static Vector2 ToVector2(this EightDirection self) { switch (self) { case EightDirection.None: return(Vector2.zero); case EightDirection.Up: return(new Vector2(0, 1)); case EightDirection.UpRight: return(new Vector2(1, 1).normalized); case EightDirection.Right: return(new Vector2(1, 0)); case EightDirection.DownRight: return(new Vector2(1, -1).normalized); case EightDirection.Down: return(new Vector2(0, -1)); case EightDirection.UpLeft: return(new Vector2(-1, 1).normalized); case EightDirection.Left: return(new Vector2(-1, 0)); case EightDirection.DownLeft: return(new Vector2(-1, -1).normalized); default: return(Vector2.zero); } }
protected override bool Trigger() { if (Input.GetButtonDown("Dash")) { this.inputDirection = EightDirectionExtensions.InputToDirection(Input.GetAxis("Horizontal"), Input.GetAxis("Vertical")); return(true); } return(false); }
private void DoDash(EightDirection direction) { // 速度変化 Vector2 directionVector = direction.ToVector2(); this.Agent.RigidbodyCache.velocity = directionVector * this.Speed; // ダッシュの開始 this.IsDashing = true; this.dashingFrames = 0; this.DashingDirection = inputDirection; }
protected override void OnTrigger() { if (this.inputDirection == EightDirection.None) { this.inputDirection = this.Agent.Direction == AgentDirection.Right ? EightDirection.Right : EightDirection.Left; } // 地上で下方向ダッシュはできなくする if (this.inputDirection == EightDirection.Down || this.inputDirection == EightDirection.DownLeft || this.inputDirection == EightDirection.DownRight) { if (this.Agent.IsGround) { return; } } this.DoDash(this.inputDirection); }
/// <summary> /// 노드가 Jump Point인지 검사한다. /// </summary> /// <returns>블럭이 있다. 없다.</returns> private bool ScanAround(Node2D current, EightDirection dir) { if (dir != EightDirection.Up && dir != EightDirection.Down) { for (int y = -1; y < 2; y += 2) // up and down { int newY = current.Y + y; if (newY < 0 || newY >= _cells.CountY) { continue; } if (_map[newY, current.X].CanGo == false) // obstacle { int newX = current.X; if (dir == EightDirection.Right) { newX += 1; } else if (dir == EightDirection.Left) { newX -= 1; } else if (dir == EightDirection.UpLeft || dir == EightDirection.DownRight) { newX += y == -1 ? -1 : 1; } else if (dir == EightDirection.UpRight || dir == EightDirection.DownLeft) { newX += y == -1 ? 1 : -1; } if (newX < 0 || newX >= _cells.CountX) { continue; } if (System.Math.Abs(current.Height - _map[newY, newX].Height) >= _cells.HeightLimit) { continue; } if (_map[newY, newX].CanGo == true) { return(true); } } } } else { for (int x = -1; x < 2; x += 2) { int newX = current.X + x; if (newX < 0 || newX >= _cells.CountX) { continue; } if (_map[current.Y, newX].CanGo == false) // obstacle { int newY = current.Y; if (dir == EightDirection.Up) { newY += 1; } else if (dir == EightDirection.Down) { newY -= 1; } if (newY < 0 || newY >= _cells.CountY) { continue; } if (_map[newY, newX].CanGo == true) { return(true); } } } } return(false); }
private bool ScanDiagonal(Node2D current) { foreach (Diagonal dia in System.Enum.GetValues(typeof(Diagonal))) { for (int count = 1; ; ++count) { int newX = current.X; int newY = current.Y; EightDirection edir = EightDirection.UpRight; switch (dia) { case Diagonal.UpRight: newX += count; newY += count; edir = EightDirection.UpRight; break; case Diagonal.UpLeft: newX -= count; newY += count; edir = EightDirection.UpLeft; break; case Diagonal.DownRight: newX += count; newY -= count; edir = EightDirection.DownRight; break; case Diagonal.DownLeft: newX -= count; newY -= count; edir = EightDirection.DownLeft; break; } if (newX < 0 || newX >= _cells.CountX) { break; } if (newY < 0 || newY >= _cells.CountY) { break; } if (_map[newY, newX] == _end) { _end.Parent = current; return(true); } if (_map[newY, newX].CanGo == false) { break; } if (_closedList[_map[newY, newX].ID] != null) { break; } if (_map[newY, newX].Parent != null) { break; } if (ScanAround(_map[newY, newX], edir)) { JumpPointAdd(_map[newY, newX], current); break; } bool jp; _map[newY, newX].Parent = current; if (ScanStraightViaDiag(_map[newY, newX], current, out jp)) { _end.Parent = _map[newY, newX]; return(true); } if (!jp) { ClosedListAdd(_map[newY, newX]); } } } return(false); }
private bool ScanStraightViaDiag(Node2D current, Node2D from, out bool findJP) { findJP = false; foreach (Direction dir in System.Enum.GetValues(typeof(Direction))) // 사방 검사. { for (int count = 1; ; ++count) { int newX = current.X; int newY = current.Y; EightDirection edir = EightDirection.Up; switch (dir) { case Direction.Up: newY += count; edir = EightDirection.Up; break; case Direction.Down: newY -= count; edir = EightDirection.Down; break; case Direction.Left: newX -= count; edir = EightDirection.Left; break; case Direction.Right: newX += count; edir = EightDirection.Right; break; } // Border checks. if (newX < 0 || newX >= _cells.CountX) { break; } if (newY < 0 || newY >= _cells.CountY) { break; } // Goal checks. if (_map[newY, newX] == _end) { _end.Parent = current; return(true); } // Obstacle checks. if (_map[newY, newX].CanGo == false) { break; } // if (_closedList[_map[newY, newX].ID] != null) { break; } if (_map[newY, newX].Parent != null) { break; } if (ScanAround(_map[newY, newX], edir)) { JumpPointAdd(current, from); JumpPointAdd(_map[newY, newX], current); findJP = true; break; } ClosedListAdd(_map[newY, newX]); } } return(false); }