Example #1
0
        private void SetCameraFromBackdrop()
        {
            if (_parentTransform == null)
            {
                CameraSystemDebug.PrintParentTransformNotFound();
                return;
            }

            if (Backdrop == null)
            {
                CameraSystemDebug.PrintBackdropNotAttached();
                return;
            }

            print("Setting Backdrop Bound");

            Vector3 pPos    = _parentTransform.transform.position;
            Vector3 pLocPos = _parentTransform.transform.localPosition;

            Vector3 bdPos    = Backdrop.transform.position;
            Vector3 bdLocPos = Backdrop.transform.localPosition;

            float parentWidth = bdPos.y - pLocPos.y;

            MinVector = new Vector2(pPos.x - parentWidth, pPos.y);
            MaxVector = new Vector2(pPos.x, MinVector.y + 2 * bdLocPos.y);
        }
Example #2
0
        public void LateUpdate()
        {
            if (!EnableCameraBoundaries)
            {
                return;
            }

            if (_player == null)
            {
                CameraSystemDebug.PrintPlayerNotFound();
                return;
            }

            Vector3 playerPos             = _player.transform.position;
            Vector2 offsetPos             = playerPos + new Vector3(PlayerOffset.x, PlayerOffset.y);
            float   x                     = Mathf.Clamp(offsetPos.x, MinVector.x, MaxVector.x);
            float   y                     = Mathf.Clamp(offsetPos.y, MinVector.y, MaxVector.y);
            Vector3 newCameraPosition     = new Vector3(x, y, gameObject.transform.position.z);
            Vector3 currentCameraPosition = gameObject.transform.position;
            Vector3 zero                  = Vector3.zero;

            gameObject.transform.position = Vector3.SmoothDamp(currentCameraPosition,
                                                               newCameraPosition,
                                                               ref zero, SmoothTime);
        }
Example #3
0
        public void SetDefaults()
        {
            if (_player == null)
            {
                CameraSystemDebug.PrintPlayerNotFound();
                return;
            }

            print("Setting default Bound");

            Vector3 playerPos = _player.transform.position;

            MinVector = new Vector2(-50 + playerPos.x, -10 + playerPos.y);
            MaxVector = new Vector2(50 + playerPos.x, 50 + playerPos.y);
        }
Example #4
0
        public void Start()
        {
            _player          = transform.parent.gameObject.GetComponentInChildren <Player>();
            _parentTransform = GetComponentInParent <Transform>();

            SetCameraFromBackdrop();

            if (MinVector.Equals(new Vector2()) && MaxVector.Equals(new Vector2()))
            {
                SetDefaults();
            }

            CameraSystemDebug.PrintBounds(MinVector, MaxVector);

            _originalMinVector = MinVector;
            _originalMaxVector = MaxVector;
        }
Example #5
0
 public void ResetCamera()
 {
     MinVector = _originalMinVector;
     MaxVector = _originalMaxVector;
     CameraSystemDebug.PrintBounds(MinVector, MaxVector);
 }