override protected void Awake() { base.Awake(); _cameraMoveInColliderBoundaries = new MoveInColliderBoundaries(ProCamera2D); _cameraMoveInColliderBoundaries.CameraTransform = _transform; _cameraMoveInColliderBoundaries.CameraSize = ProCamera2D.ScreenSizeInWorldCoordinates; _cameraMoveInColliderBoundaries.CameraCollisionMask = BoundariesLayerMask; }
override protected void Start() { base.Start(); _cameraMoveInColliderBoundaries = new MoveInColliderBoundaries(ProCamera2D); _cameraMoveInColliderBoundaries.CameraTransform = _transform; _cameraMoveInColliderBoundaries.CameraSize = ProCamera2D.ScreenSizeInWorldCoordinates; _cameraMoveInColliderBoundaries.CameraCollisionMask = BoundariesLayerMask; }
override protected void Awake() { base.Awake(); _cameraMoveInColliderBoundaries = new MoveInColliderBoundaries(ProCamera2D); _cameraMoveInColliderBoundaries.CameraTransform = ProCamera2D.transform; _cameraMoveInColliderBoundaries.CameraCollisionMask = BoundariesLayerMask; ProCamera2D.AddPositionDeltaChanger(this); }
void Awake() { _instance = this; _transform = transform; if (GameCamera == null) { GameCamera = GetComponent <Camera>(); } if (GameCamera == null) { Debug.LogError("Unity Camera not set and not found on the GameObject: " + gameObject.name); } #if PC2D_TK2D_SUPPORT Tk2dCam = GetComponent <tk2dCamera>(); #endif switch (Axis) { case MovementAxis.XY: Vector3H = vector => vector.x; Vector3V = vector => vector.y; Vector3D = vector => vector.z; VectorHV = (h, v) => new Vector3(h, v, 0); VectorHVD = (h, v, d) => new Vector3(h, v, d); break; case MovementAxis.XZ: Vector3H = vector => vector.x; Vector3V = vector => vector.z; Vector3D = vector => vector.y; VectorHV = (h, v) => new Vector3(h, 0, v); VectorHVD = (h, v, d) => new Vector3(h, d, v); break; case MovementAxis.YZ: Vector3H = vector => vector.z; Vector3V = vector => vector.y; Vector3D = vector => vector.x; VectorHV = (h, v) => new Vector3(0, v, h); VectorHVD = (h, v, d) => new Vector3(d, v, h); break; } // Remove empty targets for (int i = 0; i < CameraTargets.Count; i++) { if (CameraTargets [i].TargetTransform == null) { CameraTargets.RemoveAt(i); } } ScreenSizeInWorldCoordinates = Utils.GetScreenSizeInWorldCoords(GameCamera, Mathf.Abs(Vector3D(_transform.localPosition))); _cameraWindowRectInWorldCoords = GetRectAroundTransf(CameraWindowRect, ScreenSizeInWorldCoordinates, _transform); _cameraMoveInColliderBoundaries = new MoveInColliderBoundaries(this); _cameraMoveInColliderBoundaries.CameraTransform = _transform; _cameraMoveInColliderBoundaries.CameraSize = ScreenSizeInWorldCoordinates; _cameraMoveInColliderBoundaries.CameraCollisionMask = BoundariesLayerMask; _originalCameraDepthSign = Mathf.Sign(Vector3D(_transform.localPosition)); _transform.parent = new GameObject(gameObject.name + " Container").transform; // Center on target if (CenterTargetOnStart && CameraTargets.Count > 0) { var targetPos = GetTargetsWeightedMidPoint(CameraTargets); var cameraTargetPositionX = FollowHorizontal ? Vector3H(targetPos) : Vector3H(_transform.localPosition); var cameraTargetPositionY = FollowVertical ? Vector3V(targetPos) : Vector3V(_transform.localPosition); targetPos = VectorHV(cameraTargetPositionX, cameraTargetPositionY); targetPos += VectorHV(OverallOffset.x, OverallOffset.y); MoveCameraInstantlyToPosition(targetPos); } else { _cameraTargetPosition = _transform.localPosition; _cameraTargetHorizontalPositionSmoothed = Vector3H(_cameraTargetPosition); _previousCameraTargetHorizontalPositionSmoothed = _cameraTargetHorizontalPositionSmoothed; _cameraTargetVerticalPositionSmoothed = Vector3V(_cameraTargetPosition); _previousCameraTargetVerticalPositionSmoothed = _cameraTargetVerticalPositionSmoothed; } }