void OnPress(bool isPressed) { if (NumberOfTruckOnTop > 0) { return; } if (numberOfComingTrucks > 0) { return; } if (freeze) { return; } if (!isPressed) { return; } if (!isClickable) { return; } switch (TypeOfRotation) { case RoadRotationType.Green: myAnimator.SetBool("Next", true); StartingGreenRotation = StartingGreenRotation.Next(); _direction = StartingGreenRotation.toRoadDirection(); break; case RoadRotationType.Blue: myAnimator.SetBool("Next", true); StartingGreenRotation = StartingGreenRotation.Next(); StartingBlueRotation = StartingGreenRotation.GreenToBlue(); _direction = StartingBlueRotation.toRoadDirection(); break; case RoadRotationType.Purple: roadStartingPurple = roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection); direction = RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple); TurnOffAllSprites(); if (direction == RoadDirection.EW || direction == RoadDirection.NS) { RecalculateSprites(RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection))); } break; case RoadRotationType.Gold: direction = possibleGoldRotations[0]; possibleGoldRotations.RemoveAt(0); possibleGoldRotations.Add(direction); RecalculateSprites(); break; default: break; } }
/// <summary> /// Initializes the starting position of the animator if the road is Clickable /// and other things /// </summary> void InitializeAnimator() { TurnOffAllSprites(); if (!isClickable || myAnimator == null) { return; } switch (TypeOfRotation) { case RoadRotationType.Green: _direction = StartingGreenRotation.toRoadDirection(); ChangeVisuals(RoadDirection.NE); if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName("90_" + greenDirtoString(StartingGreenRotation) + "_state")) { break; } myAnimator.SetBool("NoAnim", true); myAnimator.SetBool("GoTo" + greenDirtoString(StartingGreenRotation), true); break; case RoadRotationType.Blue: _direction = StartingBlueRotation.toRoadDirection(); StartingGreenRotation = StartingBlueRotation.BlueToGreen(); ChangeVisuals(RoadDirection.EW); if (myAnimator.GetCurrentAnimatorStateInfo(0).IsName("90_" + greenDirtoString(StartingBlueRotation.BlueToGreen()) + "_State")) { break; } myAnimator.SetBool("NoAnim", true); myAnimator.SetBool("GoTo" + greenDirtoString(StartingBlueRotation.BlueToGreen()), true); break; case RoadRotationType.Purple: //This is "not" animator, but it's an initializatin needed for Purple type of clickable roads if (roadAnchorPurple == roadStartingPurple) { roadStartingPurple = roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection); } direction = RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple); RecalculateSprites(RoadDirectionExtensions.ComposeRoadDirection(roadAnchorPurple, roadStartingPurple.NextPurpleCardinalPoint(roadAnchorPurple, ref purpleDirection))); break; case RoadRotationType.Gold: direction = possibleGoldRotations[0]; possibleGoldRotations.RemoveAt(0); possibleGoldRotations.Add(direction); RecalculateSprites(); break; default: break; } }