Skip to content

Instantly share code, notes, and snippets.

@wtrebella
Created July 10, 2013 14:59
Show Gist options
  • Save wtrebella/5967038 to your computer and use it in GitHub Desktop.
Save wtrebella/5967038 to your computer and use it in GitHub Desktop.
Subclass of FContainer that has some cool zoom-in and out effects.
using UnityEngine;
using System.Collections;
public class WTAbstractSceneContainer : FContainer {
public SceneType sceneType;
public SceneType nextSceneType;
public bool isActive = true;
public FContainer everythingContainer = new FContainer();
public FSprite backgroundLayer;
public WTAbstractSceneContainer() {
backgroundLayer = new FSprite("whiteSquare");
backgroundLayer.width = Futile.screen.width * 2;
backgroundLayer.height = Futile.screen.height * 2;
backgroundLayer.color = Color.black;
backgroundLayer.SetPosition(Futile.screen.halfWidth, Futile.screen.halfHeight);
AddChild(backgroundLayer);
AddChild(everythingContainer);
}
virtual public void EnterScene(bool withZoom = true) {
isActive = false;
if (withZoom) {
everythingContainer.scale = 0;
everythingContainer.SetPosition(Futile.screen.halfWidth, Futile.screen.halfHeight);
Go.to(everythingContainer, 0.3f, new GoTweenConfig().floatProp("scale", 1).floatProp("x", 0).floatProp("y", 0).onComplete(HandleFinishedEnteringScene));
}
else HandleFinishedEnteringScene(null);
}
virtual public void ExitScene(SceneType nextSceneType, float dur = 0.3f, bool withZoom = true, bool withRotation = false) {
this.nextSceneType = nextSceneType;
if (withZoom) {
isActive = false;
if (withRotation) {
GoTween startScalingTween = new GoTween(this, 1.0f, new GoTweenConfig().floatProp("scale", 0.7f));
GoTween finishScalingTween = new GoTween(everythingContainer, dur, new GoTweenConfig().floatProp("scale", 0).floatProp("x", 0).floatProp("y", 0).onComplete(HandleFinishedExitingScene));
GoTween rotateTween = new GoTween(this, dur, new GoTweenConfig().setEaseType(GoEaseType.SineIn).floatProp("rotation", 360*5, true));
GoTweenFlow flow = new GoTweenFlow();
flow.insert(0, startScalingTween);
flow.insert(1.0f, finishScalingTween);
flow.insert(1.0f, rotateTween);
Go.addTween(flow);
flow.play();
}
else {
Go.to(everythingContainer, dur, new GoTweenConfig().floatProp("scale", 0).floatProp("x", Futile.screen.halfWidth).floatProp("y", Futile.screen.halfHeight).onComplete(HandleFinishedExitingScene));
}
}
else HandleFinishedExitingScene(null);
}
virtual public void HandleAppLostFocus() {
}
virtual public void HandleAppResumedFocus() {
}
virtual public void HandleFinishedEnteringScene(AbstractGoTween tween) {
isActive = true;
}
virtual public void HandleFinishedExitingScene(AbstractGoTween tween) {
WTMain.SwitchToScene(nextSceneType);
}
virtual public void HandleInput() {
}
virtual public void HandleUpdate() {
}
virtual public void HandleMultiTouch(FTouch[] touches) {
}
}
// In another class somewhere that stores the current scene, subclass MonoBehaviour and put the following code in:
// void OnApplicationPause(bool pauseStatus) {
// if (currentScene == null) return;
//
// if (pauseStatus) currentScene.HandleAppLostFocus();
// else currentScene.HandleAppResumedFocus();
// }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment