public void ResetMainCameraWillEnableTheInitialMainCamera() { Camera initialCam = ComponentCreator.Create <Camera>(); Camera sceneCam = ComponentCreator.Create <Camera>(); ICameraController stubController = Substitute.For <ICameraController>(); stubController.FetchAttachedCamera().Returns(sceneCam); stubController.FetchCameras().Returns(new [] { initialCam, sceneCam }); stubController.FetchMainCamera().Returns(initialCam); initialCam.enabled = true; sceneCam.enabled = true; MainCameraSwitcherLogic logic = new MainCameraSwitcherLogic(); logic.SetCameraController(stubController); logic.Initialize(); Assert.IsFalse(initialCam.enabled); Assert.IsTrue(sceneCam.enabled); logic.ResetMainCamera(); Assert.IsTrue(initialCam.enabled); Assert.IsFalse(sceneCam.enabled); }
// Callback methods that the game engine will call at appropriate times // Must be here, since they are called on every MonoBehaviour attached to game objects private void OnEnable() { logic = new MainCameraSwitcherLogic(); // this class is an implementation of ICameraController, so it can be set in the following way logic.SetCameraController(this); logic.Initialize(); }
public void InitializationCallsCorrectMethods() { ICameraController stubController = Substitute.For <ICameraController>(); MainCameraSwitcherLogic logic = new MainCameraSwitcherLogic(); logic.SetCameraController(stubController); stubController.Received(0).FetchMainCamera(); stubController.Received(0).FetchCameras(); stubController.Received(0).FetchAttachedCamera(); logic.Initialize(); stubController.Received(1).FetchMainCamera(); stubController.Received(1).FetchCameras(); stubController.Received(1).FetchAttachedCamera(); }
public void InitializeDoesNotDisableMainCameraIfItIsAttached() { Camera mainCamera = ComponentCreator.Create <Camera>(); mainCamera.enabled = true; ICameraController stubController = Substitute.For <ICameraController>(); stubController.FetchCameras().Returns(new[] { mainCamera, ComponentCreator.Create <Camera>(), ComponentCreator.Create <Camera>() }); stubController.FetchAttachedCamera().Returns(mainCamera); stubController.FetchMainCamera().Returns(mainCamera); MainCameraSwitcherLogic logic = new MainCameraSwitcherLogic(); logic.SetCameraController(stubController); logic.Initialize(); Assert.IsTrue(mainCamera.enabled); }