private void SetDOFEnabled(bool value) { CameraController cameraController = camera.GetComponent <CameraController>(); cameraController.EnableDOF = value; if (null == cameraController.colimator) { if (value) { CreateColimator(camera); Vector3 globalColimatorPosition = cameraController.transform.position - cameraController.transform.forward * cameraController.Focus; SceneManager.SetObjectTransform(cameraController.colimator.gameObject, cameraController.transform.InverseTransformPoint(globalColimatorPosition), cameraController.colimator.localRotation, cameraController.colimator.localScale); SceneManager.SendCameraInfo(camera.transform); } } else { if (value) { cameraController.colimator.gameObject.SetActive(true); SceneManager.RestoreObject(cameraController.colimator.gameObject, camera.transform); Vector3 globalColimatorPosition = cameraController.transform.position - cameraController.transform.forward * cameraController.Focus; SceneManager.SetObjectTransform(cameraController.colimator.gameObject, cameraController.transform.InverseTransformPoint(globalColimatorPosition), cameraController.colimator.localRotation, cameraController.colimator.localScale); SceneManager.SendCameraInfo(camera.transform); } else { if (null != cameraController.colimator) { ColimatorController colimatorController = cameraController.colimator.GetComponent <ColimatorController>(); colimatorController.gameObject.SetActive(false); if (colimatorController.isVRtist) { DestroyColimator(camera); } } SceneManager.SendCameraInfo(camera.transform); } } }
public GameObject CreateColimator() { if (null == colimatorPrefab) { colimatorPrefab = Resources.Load <GameObject>("Prefabs/UI/Colimator"); } GameObject colimatorObject = SceneManager.InstantiateUnityPrefab(colimatorPrefab); colimatorObject = SceneManager.AddObject(colimatorObject); SceneManager.SetObjectParent(colimatorObject, gameObject); colimator = colimatorObject.transform; ColimatorController colimatorController = colimatorObject.GetComponent <ColimatorController>(); colimatorController.isVRtist = true; UpdateDOFGizmo(); return(colimatorObject); }