protected override void OnTimeUp() { TilePosition newBuildPosition = BorderPointHelper.FindValidInflateOneBorderPoint(this.m_TargetInfo); if (newBuildPosition.Equals(this.m_BuildPosition)) { this.Initial(); } else { BuilderBuildHoverState hoverState = new BuilderBuildHoverState(this.m_TargetInfo, this.m_MapData, newBuildPosition, this.m_AIBehavior); //this.m_TargetInfo, newBuildPosition, this.m_AIBehavior); this.m_AIBehavior.ChangeState(hoverState); } }
public override void AICalculate() { if (this.m_LinePath.Count == 0) { this.OnTargetReached(); } else { Vector2 sourcePosition = this.m_AIBehavior.transform.position; Vector2 destinationPosition = (Vector2)PositionConvertor.GetWorldPositionFromActorTileIndex(this.m_LinePath.Peek()); if (this.m_LinePath.Count == 1) { destinationPosition += this.m_TargetOffset; } float move = this.WalkVelocity; float distance = Vector2.Distance(sourcePosition, destinationPosition); Vector2 result = Vector2.zero; Vector2 deltaVector = destinationPosition - sourcePosition; while (distance <= move) { this.m_LinePath.Dequeue(); result += deltaVector; move -= distance; sourcePosition = destinationPosition; if (this.m_LinePath.Count == 0) { distance = 0; break; } destinationPosition = (Vector2)PositionConvertor.GetWorldPositionFromActorTileIndex(this.m_LinePath.Peek()); if (this.m_LinePath.Count == 1) { destinationPosition += this.m_TargetOffset; } distance = Vector2.Distance(sourcePosition, destinationPosition); deltaVector = destinationPosition - sourcePosition; } if (distance.IsZero()) { result = deltaVector; } else { float percentage = move / distance; result += deltaVector * percentage; } this.m_MoveVector = result; this.m_AIBehavior.transform.position += new Vector3(result.x, result.y, 0); TilePosition currentPosition = PositionConvertor.GetActorTileIndexFromWorldPosition(this.m_AIBehavior.transform.position); if (!currentPosition.Equals(this.m_PreviousPosition)) { this.OnPositionTileChanged(this.m_PreviousPosition, currentPosition); this.m_PreviousPosition = currentPosition; } this.m_AnimationController.PlayWalkAnimation(this.m_MoveVector); } }
private MoveDirection GetDirection(TilePosition holePosition, TilePosition target) { if (!holePosition.Equals(target)) { if (holePosition.HComponent == target.HComponent) { if (holePosition.VComponent > target.VComponent) { return MoveDirection.Down; } else { return MoveDirection.Up; } } else if (holePosition.VComponent == target.VComponent) { if (holePosition.HComponent > target.HComponent) { return MoveDirection.Right; } else { return MoveDirection.Left; } } } return MoveDirection.None; }