You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
2.2 KiB

  1. using System.Collections;
  2. using UnityEngine;
  3. /// <summary>
  4. /// Logic block which deals with moving a character in a direction
  5. /// </summary>
  6. [CreateAssetMenu(menuName = "Major Project/Rotate Block")]
  7. [System.Serializable]
  8. public class Rotate : LogicBlock
  9. {
  10. #region Inspector Fields
  11. [SerializeField]
  12. [Header("Rotate Settings")]
  13. [Tooltip("Direction to rotate in")]
  14. protected Direction direction;
  15. [SerializeField]
  16. [Tooltip("Angle in Degrees")]
  17. protected int Angle = 90;
  18. #endregion Inspector Fields
  19. #region Class Functions
  20. /// <summary>
  21. /// Rotates the player in the direction specified by this block
  22. /// </summary>
  23. /// <param name="player">Player to rotate</param>
  24. protected override IEnumerator BlockLogic(Character player, float animationTime, bool useBlockDirection = false)
  25. {
  26. yield return player.StartCoroutine(player.RotateInDirection(direction,Angle, Character.Animation.Jump, animationTime));
  27. }
  28. /// <summary>
  29. /// Returns the block that the character will endUp on after they use this logic element
  30. /// </summary>
  31. /// <param name="startBlock">block character is on</param>
  32. /// <param name="layerMask">layers to ignore</param>
  33. /// <returns>block which character will finish on after performing this function </returns>
  34. public override Block GetEndBlock(Block startBlock,Transform transform, LayerMask layerMask)
  35. {
  36. //no movement when rotating
  37. return startBlock;
  38. }
  39. public override void CopyToken(BlockToken token)
  40. {
  41. base.CopyToken(token);
  42. direction = ((RotateToken)token).direction;
  43. Angle = ((RotateToken)token).angle;
  44. }
  45. public override BlockToken ToToken(BlockToken token = null)
  46. {
  47. if (token == null)
  48. token = new RotateToken(this);
  49. RotateToken retVal = (RotateToken)base.ToToken(token);
  50. retVal.direction = direction;
  51. retVal.angle = Angle;
  52. return retVal;
  53. }
  54. #endregion Class Functions
  55. }
  56. [System.Serializable]
  57. public class RotateToken : BlockToken
  58. {
  59. public Direction direction;
  60. public int angle;
  61. public RotateToken(LogicBlock block) : base(block) { }
  62. }