/// <summary> /// Set a new camera view, specifying a camera view target. /// </summary> /// <param name="cameraViewTarget">The new camera view target.</param> public virtual void SetView(CameraViewTarget cameraViewTarget) { if (cameraViewTarget == null) { return; } // Update the current view target info selectedCameraViewTarget = cameraViewTarget; // Update the flag hasCameraViewTarget = selectedCameraViewTarget != null; if (cameraViewTarget.ParentCamera) { transform.SetParent(cameraViewTarget.transform); transform.localPosition = Vector3.zero; transform.localRotation = Quaternion.identity; } else { transform.SetParent(null); } onVehicleCameraViewTargetChanged.Invoke(selectedCameraViewTarget); }
/// <summary> /// Called when the camera view target changes on the vehicle camera. /// </summary> /// <param name="newCameraViewTarget"></param> public void OnCameraViewTargetChanged(CameraViewTarget newCameraViewTarget) { if (newCameraViewTarget != null) { currentView = newCameraViewTarget.CameraView; } }
public virtual void OnCameraViewChanged(CameraViewTarget newCameraViewTarget) { int settingsIndex = -1; if (newCameraViewTarget != null) { for (int j = 0; j < cameraViewSettings.Count; ++j) { // Check that the HUDComponent is set to be shown in the current camera view if (cameraViewSettings[j].cameraView == newCameraViewTarget.CameraView) { settingsIndex = j; break; } } } if (settingsIndex == -1) { Deactivate(); } else { switch (CameraViewSettings[settingsIndex].anchorTypeForView) { case HUDAnchorType.AnchorTransform: transform.SetParent(cameraViewSettings[settingsIndex].anchorTransform); transform.localPosition = cameraViewSettings[settingsIndex].positionOffset; transform.localRotation = Quaternion.identity; transform.localScale = new Vector3(1, 1, 1); break; case HUDAnchorType.Camera: transform.SetParent(hudCamera.transform); transform.localPosition = cameraViewSettings[settingsIndex].positionOffset; transform.localRotation = Quaternion.identity; transform.localScale = new Vector3(1, 1, 1); break; default: // None transform.SetParent(null); break; } if (CameraViewSettings[settingsIndex].shownInView) { Activate(); } else { Deactivate(); } } }