Browse Source

Added PanToViewPath() command to smoothly pan along a path

- Added iTween to support camera tweening. It’s in the Fungus namespace
so shouldn’t interfere with any other iTween instance in your game.
- Added an option on Views room to show PanToPath()
master
chrisgregan 11 years ago
parent
commit
7d9eaafe40
  1. 51
      Assets/Fungus/Scripts/CameraController.cs
  2. 46
      Assets/Fungus/Scripts/Commands.cs
  3. 2
      Assets/Fungus/Scripts/Commands.cs.meta
  4. 8
      Assets/Fungus/Scripts/Room.cs
  5. 7510
      Assets/Fungus/Scripts/iTween.cs
  6. 8
      Assets/Fungus/Scripts/iTween.cs.meta
  7. BIN
      Assets/FungusExample/Scenes/Example.unity
  8. 9
      Assets/FungusExample/Scripts/ViewsRoom.cs

51
Assets/Fungus/Scripts/CameraController.cs

@ -1,6 +1,7 @@
using UnityEngine;
using System;
using System.Collections;
using System.Collections.Generic;
using Fungus;
namespace Fungus
@ -165,6 +166,56 @@ namespace Fungus
}
}
public void PanToPath(View[] viewList, float duration, Action arriveAction)
{
List<Vector3> pathList = new List<Vector3>();
// Note: We use the z coord to tween the camera orthographic size
// Add current camera position as first point in path
Vector3 startPos = new Vector3(mainCamera.transform.position.x,
mainCamera.transform.position.y,
mainCamera.orthographicSize);
pathList.Add(startPos);
for (int i = 0; i < viewList.Length; ++i)
{
View view = viewList[i];
Vector3 viewPos = new Vector3(view.transform.position.x,
view.transform.position.y,
view.viewSize);
pathList.Add(viewPos);
}
StartCoroutine(PanToPathInternal(duration, arriveAction, pathList.ToArray()));
}
IEnumerator PanToPathInternal(float duration, Action arriveAction, Vector3[] path)
{
float timer = 0;
while (timer < duration)
{
timer += Time.deltaTime;
timer = Mathf.Min(timer, duration);
float percent = timer / duration;
Vector3 point = iTween.PointOnPath(path, percent);
mainCamera.transform.position = new Vector3(point.x, point.y, 0);
mainCamera.orthographicSize = point.z;
SetCameraZ();
yield return null;
}
if (arriveAction != null)
{
arriveAction();
}
}
void SetCameraZ()
{
mainCamera.transform.position = new Vector3(mainCamera.transform.position.x, mainCamera.transform.position.y, cameraZ);

46
Assets/Fungus/Scripts/Commands.cs

@ -482,6 +482,52 @@ namespace Fungus
}
}
// Pans the camera through a sequence of views over a period of time.
public class PanToPathCommand : CommandQueue.Command
{
View[] views;
float duration;
public PanToPathCommand(View[] _views,
float _duration)
{
if (_views.Length == 0)
{
Debug.LogError("View list must not be empty.");
return;
}
views = _views;
duration = _duration;
}
public override void Execute(CommandQueue commandQueue, Action onComplete)
{
commandQueue.cameraController.PanToPath(views, duration, delegate {
if (views.Length > 0)
{
Game game = Game.GetInstance();
game.activeView = views[views.Length - 1];
// Try to find a page that is a child of the active view.
// If there are multiple child pages then it is the client's responsibility
// to set the correct active page in the room script.
Page defaultPage = game.activeView.gameObject.GetComponentInChildren<Page>();
if (defaultPage)
{
game.activePage = defaultPage;
}
}
if (onComplete != null)
{
onComplete();
}
});
}
}
// Fades the camera to a view over a period of time.
public class FadeToViewCommand : CommandQueue.Command
{

2
Assets/Fungus/Scripts/Commands.cs.meta

@ -1,5 +1,5 @@
fileFormatVersion: 2
guid: b221bfbeec06a47aab4bce90937db5e8
guid: c82cac70434cd411b973a4c590386c63
MonoImporter:
serializedVersion: 2
defaultReferences: []

8
Assets/Fungus/Scripts/Room.cs

@ -341,12 +341,18 @@ namespace Fungus
commandQueue.AddCommand(new SetAnimatorTriggerCommand(animator, triggerName));
}
// Pans the camera to the target view of a period of time
// Pans the camera to the target view over a period of time
public void PanToView(View targetView, float duration)
{
commandQueue.AddCommand(new PanToViewCommand(targetView, duration));
}
// Pans the camera through a sequence of target views over a period of time
public void PanToPath(float duration, params View[] targetViews)
{
commandQueue.AddCommand(new PanToPathCommand(targetViews, duration));
}
// Snaps the camera to the target view immediately
public void SnapToView(View targetView)
{

7510
Assets/Fungus/Scripts/iTween.cs

File diff suppressed because it is too large Load Diff

8
Assets/Fungus/Scripts/iTween.cs.meta

@ -0,0 +1,8 @@
fileFormatVersion: 2
guid: 4f492eaa0cef64fe98fb2b58845bbbd5
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:

BIN
Assets/FungusExample/Scenes/Example.unity

Binary file not shown.

9
Assets/FungusExample/Scripts/ViewsRoom.cs

@ -16,6 +16,7 @@ public class ViewsRoom : Room
AddOption("Lets look at the logo", LookLogo);
AddOption("That's a nice toadstool over there", LookToadstool);
AddOption ("Give me the full tour", FullTour);
AddOption("Back to menu", MoveToMenu);
Choose("Wanna move the camera?");
@ -41,4 +42,12 @@ public class ViewsRoom : Room
Say("Hey - let's go look at that logo");
Call(LookLogo);
}
void FullTour()
{
Say("Let's have a look around here");
PanToPath(10f, logoView, toadstoolView, mainView);
Say("And we're back!");
Call(OnEnter);
}
}

Loading…
Cancel
Save