Não pode escolher mais do que 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.
 
 
 

103 linhas
2.1 KiB

  1. using System;
  2. using SUISSEngine;
  3. using UnityEngine;
  4. public class CIGMovingUnit : MonoBehaviour
  5. {
  6. public IsometricGrid grid
  7. {
  8. get
  9. {
  10. return this._grid;
  11. }
  12. }
  13. public GridPoint position
  14. {
  15. get
  16. {
  17. return this._location;
  18. }
  19. }
  20. public GridPoint movement
  21. {
  22. get
  23. {
  24. return this._movement;
  25. }
  26. }
  27. private void Awake()
  28. {
  29. this._renderer = base.GetComponent<Renderer>();
  30. }
  31. private void Update()
  32. {
  33. float deltaTime = Time.deltaTime;
  34. GridPoint gridPoint = this._targetLocation - this._location;
  35. float num = this._movementSpeed * deltaTime;
  36. float num2 = this._location.DistanceTo(this._targetLocation);
  37. if (num >= num2)
  38. {
  39. this._location = this._targetLocation;
  40. this._animatedUnit.SetMoving(false);
  41. }
  42. else
  43. {
  44. this._movement = gridPoint.normalized.times(num);
  45. this._location += this._movement;
  46. this._animatedUnit.SetDirection(new Vector2(this._movement.u, this._movement.v), true);
  47. }
  48. this.UpdateTransform();
  49. }
  50. public virtual void SpawnAt(IsometricGrid citygrid, GridPoint startLocation)
  51. {
  52. this._grid = citygrid;
  53. this._location = startLocation;
  54. this._targetLocation = startLocation;
  55. this.UpdateTransform();
  56. }
  57. public void Stop()
  58. {
  59. this._targetLocation = this._location;
  60. }
  61. public void SetTargetLocation(GridPoint newTarget)
  62. {
  63. GridIndex index = new GridIndex(newTarget);
  64. if (!this._grid.IsWithinBounds(index) || this._grid[index].Unlocked)
  65. {
  66. this.Stop();
  67. }
  68. else
  69. {
  70. this._targetLocation = newTarget;
  71. }
  72. }
  73. private void UpdateTransform()
  74. {
  75. base.transform.localPosition = this._grid.GetPositionForGridPoint(this._location);
  76. this._renderer.sortingOrder = GridTile.GetSortingOrder(new GridIndex(this._location), new GridSize(1, 1));
  77. }
  78. [SelfReference]
  79. public CIGAnimatedCreature _animatedUnit;
  80. public float _movementSpeed;
  81. private IsometricGrid _grid;
  82. private GridPoint _movement = new GridPoint(0f, 0f);
  83. private GridPoint _location = new GridPoint(0f, 0f);
  84. private GridPoint _targetLocation = new GridPoint(0f, 0f);
  85. private Renderer _renderer;
  86. }