using System; using SUISSEngine; using UnityEngine; public class CIGMovingUnit : MonoBehaviour { public IsometricGrid grid { get { return this._grid; } } public GridPoint position { get { return this._location; } } public GridPoint movement { get { return this._movement; } } private void Awake() { this._renderer = base.GetComponent(); } private void Update() { float deltaTime = Time.deltaTime; GridPoint gridPoint = this._targetLocation - this._location; float num = this._movementSpeed * deltaTime; float num2 = this._location.DistanceTo(this._targetLocation); if (num >= num2) { this._location = this._targetLocation; this._animatedUnit.SetMoving(false); } else { this._movement = gridPoint.normalized.times(num); this._location += this._movement; this._animatedUnit.SetDirection(new Vector2(this._movement.u, this._movement.v), true); } this.UpdateTransform(); } public virtual void SpawnAt(IsometricGrid citygrid, GridPoint startLocation) { this._grid = citygrid; this._location = startLocation; this._targetLocation = startLocation; this.UpdateTransform(); } public void Stop() { this._targetLocation = this._location; } public void SetTargetLocation(GridPoint newTarget) { GridIndex index = new GridIndex(newTarget); if (!this._grid.IsWithinBounds(index) || this._grid[index].Unlocked) { this.Stop(); } else { this._targetLocation = newTarget; } } private void UpdateTransform() { base.transform.localPosition = this._grid.GetPositionForGridPoint(this._location); this._renderer.sortingOrder = GridTile.GetSortingOrder(new GridIndex(this._location), new GridSize(1, 1)); } [SelfReference] public CIGAnimatedCreature _animatedUnit; public float _movementSpeed; private IsometricGrid _grid; private GridPoint _movement = new GridPoint(0f, 0f); private GridPoint _location = new GridPoint(0f, 0f); private GridPoint _targetLocation = new GridPoint(0f, 0f); private Renderer _renderer; }