private static Camera FindOrCreateCamera() { _sceneCamera = SceneUtils.GetObjectsInScene <SceneCamera>(true).FirstOrDefault(); if (_sceneCamera == null) { GameObject cameraPreview = new GameObject("[Camera Preview]"); cameraPreview.transform.SetParent(_worldDescriptor.transform, true); cameraPreview.transform.position = new Vector3(0, 1, 0); _sceneCamera = cameraPreview.AddComponent <SceneCamera>(); _sceneCamera.Width = PreviewSize; _sceneCamera.Height = PreviewSize; _sceneCamera.GetComponent <Camera>().targetTexture = new RenderTexture(512, 512, 16); } else { _sceneCamera.gameObject.name = "[Camera Preview]"; _sceneCamera.transform.SetParent(_worldDescriptor.transform, true); } _sceneCamera.gameObject.SetActive(true); _camera = _sceneCamera.GetComponent <Camera>(); _camera.enabled = true; return(_camera); }
private static void FindOrCreateWorldDescriptor() { _worldDescriptor = SceneUtils.GetObjectsInScene <WorldDescriptor>(true).FirstOrDefault(); if (_worldDescriptor != null) { _worldDescriptor.gameObject.SetActive(true); FindOrCreateSpawnPoint(_worldDescriptor); return; } GameObject worldDescriptorGo = new GameObject("[World Descriptor]"); worldDescriptorGo.transform.position = Vector3.zero; worldDescriptorGo.transform.rotation = Quaternion.identity; worldDescriptorGo.transform.localScale = Vector3.one; _worldDescriptor = worldDescriptorGo.AddComponent <WorldDescriptor>(); FindOrCreateSpawnPoint(_worldDescriptor); }