/// <summary> /// Set bounds by values of online players. /// </summary> /// <param name="_bounds">New bounds value.</param> public void SetBoundsByOnline(Vector4 _bounds) { if ((_bounds.x > -999) && (_bounds.x != currentBounds.XMin)) { leftBoundVector = new Vector3(_bounds.x, currentBounds.XMinVector.y, currentBounds.XMinVector.z); OnXMinBoundChanged?.Invoke(); } if ((_bounds.y > -999) && (_bounds.y != currentBounds.XMax)) { rightBoundVector = new Vector3(_bounds.y, currentBounds.XMaxVector.y, currentBounds.XMaxVector.z); } if ((_bounds.z > -999) && (_bounds.z != currentBounds.ZMin)) { bottomBoundVector = new Vector3(currentBounds.ZMinVector.x, currentBounds.ZMinVector.y, _bounds.z); } if ((_bounds.w > -999) && (_bounds.w != currentBounds.ZMax)) { topBoundVector = new Vector3(currentBounds.ZMaxVector.x, currentBounds.ZMaxVector.y, _bounds.w); } }
/// <summary> /// Wait to set bounds if minimum x value is visible by the camera or to its right. /// </summary> /// <param name="_bounds">Bounds to set.</param> /// <returns></returns> private IEnumerator SetBoundsInTime(TDS_Bounds _bounds) { // Get the movement direction of the bounds int[] _boundsMovement = new int[4]; _boundsMovement[0] = _bounds.XMin > currentBounds.XMin ? 1 : _bounds.XMin < currentBounds.XMin ? -1 : 0; _boundsMovement[1] = _bounds.XMax > currentBounds.XMax ? 1 : _bounds.XMax < currentBounds.XMax ? -1 : 0; _boundsMovement[2] = _bounds.ZMin > currentBounds.ZMin ? 1 : _bounds.ZMin < currentBounds.ZMin ? -1 : 0; _boundsMovement[3] = _bounds.ZMax > currentBounds.ZMax ? 1 : _bounds.ZMax < currentBounds.ZMax ? -1 : 0; Vector3 _localPlayerPosition = new Vector3(); Vector3[] _playerPositions = new Vector3[TDS_LevelManager.Instance.OtherPlayers.Count]; // While all the bounds are not in the right place, set their position while (_boundsMovement.Any(m => m != 0)) { // Get all players position if (!PhotonNetwork.offlineMode) { _localPlayerPosition = TDS_LevelManager.Instance.LocalPlayer.transform.position; for (int _i = 0; _i < TDS_LevelManager.Instance.OtherPlayers.Count; _i++) { _playerPositions[_i] = TDS_LevelManager.Instance.OtherPlayers[_i].transform.position; } } // Left bound move if (_boundsMovement[0] != 0) { if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.x > _localPlayerPosition.x)) { float _xMin = camera.WorldToViewportPoint(_bounds.XMinVector).x; if (_xMin < .0001f) { leftBoundVector = _bounds.XMinVector; _boundsMovement[0] = 0; OnXMinBoundChanged?.Invoke(); // Set X Min bound value to send online onlineSendingBounds.x = currentBounds.XMin; } else { _xMin = transform.position.x - CameraXRatio; if (_xMin != currentBounds.XMin) { leftBoundVector = new Vector3(_xMin, leftBound.transform.position.y, leftBound.transform.position.z); OnXMinBoundChanged?.Invoke(); // Set X Min bound value to send online onlineSendingBounds.x = currentBounds.XMin; } } } else if (currentBounds.XMin == _bounds.XMin) { _boundsMovement[0] = 0; } } // Right bound move if (_boundsMovement[1] != 0) { if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.x < _localPlayerPosition.x)) { float _xMax = camera.WorldToViewportPoint(_bounds.XMaxVector).x; if (_xMax > .9999f) { rightBoundVector = _bounds.XMaxVector; _boundsMovement[1] = 0; // Set X Max bound value to send online onlineSendingBounds.y = currentBounds.XMax; } else { _xMax = transform.position.x + CameraXRatio; if (_xMax != currentBounds.XMax) { rightBoundVector = new Vector3(_xMax, rightBound.transform.position.y, rightBound.transform.position.z); // Set X Max bound value to send online onlineSendingBounds.y = currentBounds.XMax; } } } else if (currentBounds.XMax == _bounds.XMax) { _boundsMovement[1] = 0; } } // Bottom bound move if (_boundsMovement[2] != 0) { if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.z > _localPlayerPosition.z)) { float _zMin = camera.WorldToViewportPoint(_bounds.ZMinVector).y; if (_zMin < .0001f) { bottomBoundVector = _bounds.ZMinVector; _boundsMovement[2] = 0; // Set Z Min bound value to send online onlineSendingBounds.z = currentBounds.ZMin; } else { _zMin = bottomBound.transform.position.z - (camera.orthographicSize * 2 * camera.WorldToViewportPoint(currentBounds.ZMinVector).y *VIEWPORT_CALCL_Y_COEF); if (_zMin != currentBounds.ZMin) { bottomBoundVector = new Vector3(bottomBound.transform.position.x, bottomBound.transform.position.y, _zMin); // Set Z Min bound value to send online onlineSendingBounds.z = currentBounds.ZMin; } } } else if (currentBounds.ZMin == _bounds.ZMin) { _boundsMovement[2] = 0; } } // Top bound move if (_boundsMovement[3] != 0) { if (PhotonNetwork.offlineMode || (_playerPositions.Length == 0) || _playerPositions.All(p => p.z < _localPlayerPosition.z)) { float _mostUpPlayer = PhotonNetwork.offlineMode ? players.OrderBy(p => p.transform.position.z).Last().transform.position.z : target.position.z; float _zMax = camera.WorldToViewportPoint(_bounds.ZMaxVector).y; if ((_zMax > (ViewportYMacBoundValue - .0001f)) && (_mostUpPlayer + 1 < _bounds.ZMax)) { topBoundVector = _bounds.ZMaxVector; _boundsMovement[3] = 0; // Set Z Max bound value to send online onlineSendingBounds.w = currentBounds.ZMax; } else { _zMax = topBound.transform.position.z + (camera.orthographicSize * 2 * (ViewportYMacBoundValue - camera.WorldToViewportPoint(currentBounds.ZMaxVector).y) * VIEWPORT_CALCL_Y_COEF); if ((_zMax != currentBounds.ZMax) && (_mostUpPlayer + 1 < _zMax)) { topBoundVector = new Vector3(topBound.transform.position.x, topBound.transform.position.y, _zMax); // Set Z Max bound value to send online onlineSendingBounds.w = currentBounds.ZMax; } } } else if (currentBounds.ZMax == _bounds.ZMax) { _boundsMovement[3] = 0; } } yield return(null); } setBoundsCoroutine = null; }