Browse Source

Can now run other commands in parallel to PanToView()

master
chrisgregan 11 years ago
parent
commit
da314746c3
  1. 3
      Assets/Fungus/Scripts/CameraController.cs
  2. 20
      Assets/Fungus/Scripts/Commands/CameraCommands.cs
  3. 10
      Assets/Fungus/Scripts/GameController.cs
  4. 3
      Assets/FungusExample/Scripts/ViewRoom.cs

3
Assets/Fungus/Scripts/CameraController.cs

@ -171,6 +171,9 @@ namespace Fungus
*/ */
public void PanToPosition(Vector3 targetPosition, Quaternion targetRotation, float targetSize, float duration, Action arriveAction) public void PanToPosition(Vector3 targetPosition, Quaternion targetRotation, float targetSize, float duration, Action arriveAction)
{ {
// Stop any pan that is currently active
StopAllCoroutines();
swipePanActive = false; swipePanActive = false;
if (duration == 0f) if (duration == 0f)

20
Assets/Fungus/Scripts/Commands/CameraCommands.cs

@ -49,30 +49,44 @@ namespace Fungus
Quaternion targetRotation; Quaternion targetRotation;
float targetSize; float targetSize;
float duration; 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; targetPosition = _targetPosition;
targetRotation = _targetRotation; targetRotation = _targetRotation;
targetSize = _targetSize; targetSize = _targetSize;
duration = _duration; duration = _duration;
wait = _wait;
} }
public override void Execute(CommandQueue commandQueue, Action onComplete) public override void Execute(CommandQueue commandQueue, Action onComplete)
{ {
Game game = Game.GetInstance(); Game game = Game.GetInstance();
if (wait)
{
game.waiting = true; game.waiting = true;
}
game.cameraController.PanToPosition(targetPosition, targetRotation, targetSize, duration, delegate { game.cameraController.PanToPosition(targetPosition, targetRotation, targetSize, duration, delegate {
if (wait)
{
game.waiting = false; game.waiting = false;
if (onComplete != null) if (onComplete != null)
{ {
onComplete(); onComplete();
} }
}
}); });
if (!wait)
{
if (onComplete != null)
{
onComplete();
}
}
} }
} }

10
Assets/Fungus/Scripts/GameController.cs

@ -138,10 +138,11 @@ namespace Fungus
* This method returns immediately but it queues an asynchronous command for later execution. * This method returns immediately but it queues an asynchronous command for later execution.
* @param targetView The View to pan the camera to. * @param targetView The View to pan the camera to.
* @param duration The length of time in seconds needed to complete the pan. * @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 targetRotation The rotation to pan the camera to.
* @param targetSize The orthographic size 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 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 commandQueue = Game.GetInstance().commandQueue;
commandQueue.AddCommand(new Command.PanToPosition(targetPosition, targetRotation, targetSize, duration)); commandQueue.AddCommand(new Command.PanToPosition(targetPosition, targetRotation, targetSize, duration, wait));
} }
/** /**

3
Assets/FungusExample/Scripts/ViewRoom.cs

@ -31,7 +31,8 @@ namespace Fungus.Example
{ {
PanToView(logoView, 2f); PanToView(logoView, 2f);
Wait(2); 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); Call(OnEnter);
} }

Loading…
Cancel
Save