// Called when the camera view changes protected virtual void OnCameraViewChanged(CameraView cameraView) { for (int i = 0; i < cameraViewParentingItems.Count; ++i) { for (int j = 0; j < cameraViewParentingItems[i].cameraViews.Count; ++j) { if (cameraViewParentingItems[i].cameraViews[j] == cameraView) { switch (cameraViewParentingItems[i].parentType) { case CameraViewParentType.Transform: cameraViewParentingItems[i].m_Transform.SetParent(cameraViewParentingItems[i].parentTransform); break; case CameraViewParentType.Camera: if (cameraEntity != null) { cameraViewParentingItems[i].m_Transform.SetParent(cameraEntity.MainCamera.transform); } break; case CameraViewParentType.None: cameraViewParentingItems[i].m_Transform.SetParent(null); break; } // Position if (cameraViewParentingItems[i].setLocalPosition) { cameraViewParentingItems[i].m_Transform.localPosition = cameraViewParentingItems[i].localPosition; } // Rotation if (cameraViewParentingItems[i].setLocalRotation) { cameraViewParentingItems[i].m_Transform.transform.localRotation = Quaternion.Euler(cameraViewParentingItems[i].localRotationEulerAngles); } //Scale if (cameraViewParentingItems[i].setLocalScale) { cameraViewParentingItems[i].m_Transform.localScale = cameraViewParentingItems[i].localScale; } } } } }
protected virtual void OnCameraViewChanged(CameraView cameraView) { for (int i = 0; i < viewSettings.Count; ++i) { if (viewSettings[i].cameraView == cameraView) { for (int j = 0; j < viewSettings[i].viewSettings.Count; ++j) { viewSettings[i].viewSettings[j].child.SetParent(viewSettings[i].viewSettings[j].parent); viewSettings[i].viewSettings[j].child.transform.localPosition = Vector3.zero; viewSettings[i].viewSettings[j].child.localRotation = Quaternion.identity; if (viewSettings[i].viewSettings[j].resetScale) { viewSettings[i].viewSettings[j].child.localScale = new Vector3(1, 1, 1); } } } } }
/// <summary> /// Select a new camera view. /// </summary> /// <param name="newView">The new camera view.</param> public virtual void SetView(CameraView newView) { // If no camera target or null view, set to null and exit. if (newView == null || cameraTarget == null) { SetCameraViewTarget(null); return; } // Search all camera views on camera target for desired view for (int i = 0; i < cameraTarget.CameraViewTargets.Count; ++i) { if (cameraTarget.CameraViewTargets[i].CameraView == newView) { SetCameraViewTarget(cameraTarget.CameraViewTargets[i]); return; } } // If none found, default to the first available if (cameraTarget.CameraViewTargets.Count > 0) { // Set the first available Camera View Target SetCameraViewTarget(cameraTarget.CameraViewTargets[0]); if (newView != null) { // Issue a warning Debug.LogWarning("No CameraViewTarget found for Camera View type " + newView.ToString() + ". Defaulting to " + currentViewTarget.CameraView.ToString()); } } else { SetView(null); // Issue a warning Debug.LogWarning("No CameraViewTarget found on the camera target object, camera will not work. Please add one or more CameraViewTarget components to the camera target object's hierarchy."); } }