|
- using System;
- using UnityEngine;
-
- namespace SUISSEngine
- {
- public class Parallax : MonoBehaviour
- {
- private void Start()
- {
- if (!this.defaultPositionSet)
- {
- this.defaultPosition = base.transform.position;
- }
- }
-
- private void LateUpdate()
- {
- Camera islandCamera = this.island.islandCamera;
- Bounds islandWorldBounds = this.island.islandWorldBounds;
- Vector2 vector;
- vector.y = islandCamera.orthographicSize;
- if (vector.y > islandWorldBounds.extents.y)
- {
- vector.y = islandWorldBounds.extents.y;
- }
- vector.x = vector.y * islandCamera.aspect;
- Vector3 position = islandCamera.transform.position;
- position.x += (this.pivot.x - 0.5f) * 2f * vector.x;
- position.y += (this.pivot.y - 0.5f) * 2f * vector.y;
- Vector2 vector2;
- vector2.x = (this._defaultPosition.x - this.pivot.x * islandWorldBounds.extents.x * 2f) * (1f - this.speed.x);
- vector2.y = (this._defaultPosition.y - this.pivot.y * islandWorldBounds.extents.y * 2f) * (1f - this.speed.y);
- Vector3 position2;
- position2.x = this._defaultPosition.x + (position.x - this._defaultPosition.x) * (1f - this.speed.x) + vector2.x;
- position2.y = this._defaultPosition.y + (position.y - this._defaultPosition.y) * (1f - this.speed.y) + vector2.y;
- position2.z = this._defaultPosition.z;
- base.transform.position = position2;
- }
-
- public Vector3 defaultPosition
- {
- get
- {
- return this._defaultPosition;
- }
- set
- {
- this._defaultPosition = value;
- this.defaultPositionSet = true;
- }
- }
-
- public Vector2 speed = new Vector2(1f, 1f);
-
- public Vector2 pivot = new Vector2(0.5f, 0.5f);
-
- [ParentReference]
- public IsometricIsland island;
-
- private bool defaultPositionSet;
-
- private Vector3 _defaultPosition = Vector3.zero;
- }
- }
|