|
- using System;
- using SUISSEngine;
- using UnityEngine;
-
- public class UnlockVehicleShadowController : MonoBehaviour
- {
- public UnlockVehicleShadowController()
- {
- Vector3 vector = new Vector3(0f, 1f);
- this._flyingHeightUnit = vector.normalized;
-
- }
-
- protected virtual void Awake()
- {
- this._spriteRenderer = base.gameObject.GetComponent<SpriteRenderer>();
- this._lastLocation = this._vehicle.Location;
- }
-
- protected virtual void Update()
- {
- if (this._vehicle != null)
- {
- base.transform.localPosition = this._flyingHeightUnit * -this._vehicle.FlyingHeight;
- this._spriteRenderer.sortingOrder = GridTile.GetSortingOrder(new GridIndex(this._vehicle.Location), new GridSize(this._sizeInTilesU, this._sizeInTilesV));
- GridPoint gridPoint = this._vehicle.Location - this._lastLocation;
- this._lastLocation = this._vehicle.Location;
- Vector2 lhs = new Vector2(gridPoint.u, gridPoint.v);
- float num = 0f;
- int num2 = 0;
- int num3 = 0;
- while (num3 < this.spriteDirections.Length && num3 < this.sprites.Length)
- {
- float num4 = Vector2.Dot(lhs, this.spriteDirections[num3]);
- if (num4 > num)
- {
- num = num4;
- num2 = num3;
- }
- num3++;
- }
- this._spriteRenderer.sprite = this.sprites[num2 * this.spriteSheetSize + (int)this.spriteAnimationIndex];
- }
- }
-
- [SerializeField]
- private int spriteSheetSize = 1;
-
- [SerializeField]
- private int _sizeInTilesU;
-
- [SerializeField]
- private int _sizeInTilesV;
-
- [SerializeField]
- private float spriteAnimationIndex;
-
- [SerializeField]
- private Sprite[] sprites;
-
- [SerializeField]
- private Vector2[] spriteDirections = new Vector2[]
- {
- new Vector2(0f, 1f),
- new Vector2(1f, 0f),
- new Vector2(0f, -1f),
- new Vector2(-1f, 0f)
- };
-
- [SerializeField]
- private UnlockBuildingVehicle _vehicle;
-
- private Vector3 _flyingHeightUnit;
-
- private GridPoint _lastLocation;
-
- private SpriteRenderer _spriteRenderer;
- }
|