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.
 
 
 

65 lines
1.8 KiB

  1. using System;
  2. using UnityEngine;
  3. namespace SUISSEngine
  4. {
  5. public class Parallax : MonoBehaviour
  6. {
  7. private void Start()
  8. {
  9. if (!this.defaultPositionSet)
  10. {
  11. this.defaultPosition = base.transform.position;
  12. }
  13. }
  14. private void LateUpdate()
  15. {
  16. Camera islandCamera = this.island.islandCamera;
  17. Bounds islandWorldBounds = this.island.islandWorldBounds;
  18. Vector2 vector;
  19. vector.y = islandCamera.orthographicSize;
  20. if (vector.y > islandWorldBounds.extents.y)
  21. {
  22. vector.y = islandWorldBounds.extents.y;
  23. }
  24. vector.x = vector.y * islandCamera.aspect;
  25. Vector3 position = islandCamera.transform.position;
  26. position.x += (this.pivot.x - 0.5f) * 2f * vector.x;
  27. position.y += (this.pivot.y - 0.5f) * 2f * vector.y;
  28. Vector2 vector2;
  29. vector2.x = (this._defaultPosition.x - this.pivot.x * islandWorldBounds.extents.x * 2f) * (1f - this.speed.x);
  30. vector2.y = (this._defaultPosition.y - this.pivot.y * islandWorldBounds.extents.y * 2f) * (1f - this.speed.y);
  31. Vector3 position2;
  32. position2.x = this._defaultPosition.x + (position.x - this._defaultPosition.x) * (1f - this.speed.x) + vector2.x;
  33. position2.y = this._defaultPosition.y + (position.y - this._defaultPosition.y) * (1f - this.speed.y) + vector2.y;
  34. position2.z = this._defaultPosition.z;
  35. base.transform.position = position2;
  36. }
  37. public Vector3 defaultPosition
  38. {
  39. get
  40. {
  41. return this._defaultPosition;
  42. }
  43. set
  44. {
  45. this._defaultPosition = value;
  46. this.defaultPositionSet = true;
  47. }
  48. }
  49. public Vector2 speed = new Vector2(1f, 1f);
  50. public Vector2 pivot = new Vector2(0.5f, 0.5f);
  51. [ParentReference]
  52. public IsometricIsland island;
  53. private bool defaultPositionSet;
  54. private Vector3 _defaultPosition = Vector3.zero;
  55. }
  56. }