From da314746c301feeb4d9e0aed29cac039964454e7 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Thu, 26 Jun 2014 17:34:01 +0100 Subject: [PATCH] Can now run other commands in parallel to PanToView() --- Assets/Fungus/Scripts/CameraController.cs | 3 ++ .../Fungus/Scripts/Commands/CameraCommands.cs | 30 ++++++++++++++----- Assets/Fungus/Scripts/GameController.cs | 10 ++++--- Assets/FungusExample/Scripts/ViewRoom.cs | 3 +- 4 files changed, 33 insertions(+), 13 deletions(-) diff --git a/Assets/Fungus/Scripts/CameraController.cs b/Assets/Fungus/Scripts/CameraController.cs index 530bdff3..287909b0 100644 --- a/Assets/Fungus/Scripts/CameraController.cs +++ b/Assets/Fungus/Scripts/CameraController.cs @@ -171,6 +171,9 @@ namespace Fungus */ public void PanToPosition(Vector3 targetPosition, Quaternion targetRotation, float targetSize, float duration, Action arriveAction) { + // Stop any pan that is currently active + StopAllCoroutines(); + swipePanActive = false; if (duration == 0f) diff --git a/Assets/Fungus/Scripts/Commands/CameraCommands.cs b/Assets/Fungus/Scripts/Commands/CameraCommands.cs index 3b932c6f..c2fe261d 100644 --- a/Assets/Fungus/Scripts/Commands/CameraCommands.cs +++ b/Assets/Fungus/Scripts/Commands/CameraCommands.cs @@ -49,30 +49,44 @@ namespace Fungus Quaternion targetRotation; float targetSize; float duration; + bool wait; - public PanToPosition(Vector3 _targetPosition, Quaternion _targetRotation, float _targetSize, float _duration) + public PanToPosition(Vector3 _targetPosition, Quaternion _targetRotation, float _targetSize, float _duration, bool _wait) { targetPosition = _targetPosition; targetRotation = _targetRotation; targetSize = _targetSize; duration = _duration; + wait = _wait; } public override void Execute(CommandQueue commandQueue, Action onComplete) { Game game = Game.GetInstance(); - - game.waiting = true; - + + if (wait) + { + game.waiting = true; + } + game.cameraController.PanToPosition(targetPosition, targetRotation, targetSize, duration, delegate { - - game.waiting = false; - + if (wait) + { + game.waiting = false; + if (onComplete != null) + { + onComplete(); + } + } + }); + + if (!wait) + { if (onComplete != null) { onComplete(); } - }); + } } } diff --git a/Assets/Fungus/Scripts/GameController.cs b/Assets/Fungus/Scripts/GameController.cs index 0a162f42..43fca200 100644 --- a/Assets/Fungus/Scripts/GameController.cs +++ b/Assets/Fungus/Scripts/GameController.cs @@ -138,10 +138,11 @@ namespace Fungus * This method returns immediately but it queues an asynchronous command for later execution. * @param targetView The View to pan the camera to. * @param duration The length of time in seconds needed to complete the pan. + * @param wait Wait for pan to finish before executing next command. */ - public static void PanToView(View targetView, float duration) + public static void PanToView(View targetView, float duration, bool wait = true) { - PanToPosition(targetView.transform.position, targetView.transform.rotation, targetView.viewSize, duration); + PanToPosition(targetView.transform.position, targetView.transform.rotation, targetView.viewSize, duration, wait); } /** @@ -153,11 +154,12 @@ namespace Fungus * @param targetRotation The rotation to pan the camera to. * @param targetSize The orthographic size to pan the camera to. * @param duration The length of time in seconds needed to complete the pan. + * @param wait Wait for pan to finish before executing next command. */ - public static void PanToPosition(Vector3 targetPosition, Quaternion targetRotation, float targetSize, float duration) + public static void PanToPosition(Vector3 targetPosition, Quaternion targetRotation, float targetSize, float duration, bool wait) { CommandQueue commandQueue = Game.GetInstance().commandQueue; - commandQueue.AddCommand(new Command.PanToPosition(targetPosition, targetRotation, targetSize, duration)); + commandQueue.AddCommand(new Command.PanToPosition(targetPosition, targetRotation, targetSize, duration, wait)); } /** diff --git a/Assets/FungusExample/Scripts/ViewRoom.cs b/Assets/FungusExample/Scripts/ViewRoom.cs index ec25ed76..6473778a 100644 --- a/Assets/FungusExample/Scripts/ViewRoom.cs +++ b/Assets/FungusExample/Scripts/ViewRoom.cs @@ -31,7 +31,8 @@ namespace Fungus.Example { PanToView(logoView, 2f); Wait(2); - PanToView(mainView, 2f); + PanToView(mainView, 2f, false); // Don't wait for pan to finish before executing next command + Say("Wow - nice logo!"); Call(OnEnter); }