chrisgregan
11 years ago
14 changed files with 235 additions and 1 deletions
Binary file not shown.
@ -0,0 +1,4 @@
|
||||
fileFormatVersion: 2 |
||||
guid: fbafb8431307c42c9b1bfb9b27f6bd98 |
||||
NativeFormatImporter: |
||||
userData: |
@ -0,0 +1,60 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
|
||||
namespace Fungus |
||||
{ |
||||
/** |
||||
* Attach this component to a sprite object to apply a simple parallax scrolling effect. |
||||
* The parallax offset is calculated based on the distance from the camera to the position of the parent Room. |
||||
*/ |
||||
public class Parallax : MonoBehaviour |
||||
{ |
||||
/** |
||||
* Scale factor for calculating the parallax offset. |
||||
*/ |
||||
public float parallaxFactor; |
||||
|
||||
Vector3 startPosition; |
||||
|
||||
Room parentRoom; |
||||
|
||||
void Start () |
||||
{ |
||||
// Store the starting position of the sprite object |
||||
startPosition = transform.position; |
||||
|
||||
// Store a reference to the parent Room object |
||||
Transform ancestor = transform.parent; |
||||
while (ancestor != null) |
||||
{ |
||||
Room room = ancestor.GetComponent<Room>(); |
||||
if (room != null) |
||||
{ |
||||
parentRoom = room; |
||||
break; |
||||
} |
||||
ancestor = ancestor.transform.parent; |
||||
} |
||||
} |
||||
|
||||
void Update () |
||||
{ |
||||
if (parentRoom == null) |
||||
{ |
||||
// Don't apply offset if the sprite is not a child of a Room |
||||
return; |
||||
} |
||||
|
||||
if (Game.GetInstance().activeRoom != parentRoom) |
||||
{ |
||||
// Early out if this sprite is not in the currently active Room |
||||
return; |
||||
} |
||||
|
||||
Vector3 offset = Game.GetInstance().GetParallaxOffset(parallaxFactor); |
||||
|
||||
// Set new position for sprite |
||||
transform.position = startPosition + offset; |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,8 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 3afab7986c14e4b7cbd982245a28b9a5 |
||||
MonoImporter: |
||||
serializedVersion: 2 |
||||
defaultReferences: [] |
||||
executionOrder: 0 |
||||
icon: {instanceID: 0} |
||||
userData: |
Binary file not shown.
@ -0,0 +1,45 @@
|
||||
fileFormatVersion: 2 |
||||
guid: 0a068860829d14b48a48e6245e0e591c |
||||
TextureImporter: |
||||
serializedVersion: 2 |
||||
mipmaps: |
||||
mipMapMode: 0 |
||||
enableMipMap: 0 |
||||
linearTexture: 0 |
||||
correctGamma: 0 |
||||
fadeOut: 0 |
||||
borderMipMap: 0 |
||||
mipMapFadeDistanceStart: 1 |
||||
mipMapFadeDistanceEnd: 3 |
||||
bumpmap: |
||||
convertToNormalMap: 0 |
||||
externalNormalMap: 0 |
||||
heightScale: .25 |
||||
normalMapFilter: 0 |
||||
isReadable: 0 |
||||
grayScaleToAlpha: 0 |
||||
generateCubemap: 0 |
||||
seamlessCubemap: 0 |
||||
textureFormat: -3 |
||||
maxTextureSize: 1024 |
||||
textureSettings: |
||||
filterMode: -1 |
||||
aniso: 1 |
||||
mipBias: -1 |
||||
wrapMode: 1 |
||||
nPOTScale: 0 |
||||
lightmap: 0 |
||||
compressionQuality: 50 |
||||
spriteMode: 1 |
||||
spriteExtrude: 1 |
||||
spriteMeshType: 1 |
||||
alignment: 0 |
||||
spritePivot: {x: .5, y: .5} |
||||
spritePixelsToUnits: 100 |
||||
alphaIsTransparency: 1 |
||||
textureType: 8 |
||||
buildTargetSettings: [] |
||||
spriteSheet: |
||||
sprites: [] |
||||
spritePackingTag: |
||||
userData: |
After Width: | Height: | Size: 27 KiB |
@ -0,0 +1,45 @@
|
||||
fileFormatVersion: 2 |
||||
guid: ea8f56c43254d41728f5ac4e8299b6c9 |
||||
TextureImporter: |
||||
serializedVersion: 2 |
||||
mipmaps: |
||||
mipMapMode: 0 |
||||
enableMipMap: 0 |
||||
linearTexture: 0 |
||||
correctGamma: 0 |
||||
fadeOut: 0 |
||||
borderMipMap: 0 |
||||
mipMapFadeDistanceStart: 1 |
||||
mipMapFadeDistanceEnd: 3 |
||||
bumpmap: |
||||
convertToNormalMap: 0 |
||||
externalNormalMap: 0 |
||||
heightScale: .25 |
||||
normalMapFilter: 0 |
||||
isReadable: 0 |
||||
grayScaleToAlpha: 0 |
||||
generateCubemap: 0 |
||||
seamlessCubemap: 0 |
||||
textureFormat: -3 |
||||
maxTextureSize: 1024 |
||||
textureSettings: |
||||
filterMode: -1 |
||||
aniso: 1 |
||||
mipBias: -1 |
||||
wrapMode: 1 |
||||
nPOTScale: 0 |
||||
lightmap: 0 |
||||
compressionQuality: 50 |
||||
spriteMode: 1 |
||||
spriteExtrude: 1 |
||||
spriteMeshType: 1 |
||||
alignment: 0 |
||||
spritePivot: {x: .5, y: .5} |
||||
spritePixelsToUnits: 100 |
||||
alphaIsTransparency: 1 |
||||
textureType: 8 |
||||
buildTargetSettings: [] |
||||
spriteSheet: |
||||
sprites: [] |
||||
spritePackingTag: |
||||
userData: |
Binary file not shown.
@ -0,0 +1,28 @@
|
||||
using UnityEngine; |
||||
using System.Collections; |
||||
using Fungus; |
||||
|
||||
// The parallax effect is achieved by attaching a Parallax script to each sprite that requires a |
||||
// parallax offset. The offset is then applied automatically whenever the camera moves around the active Room. |
||||
// There is a handy parallax sprite prefab in Fungus/Prefabs/ParallaxSprite.prefab |
||||
|
||||
public class ParallaxRoom : Room |
||||
{ |
||||
public View mainView; |
||||
public View zoomView; |
||||
|
||||
public Room menuRoom; |
||||
|
||||
void OnEnter() |
||||
{ |
||||
SetView(mainView); |
||||
|
||||
Say("Let's zoom in!"); |
||||
PanToView(zoomView, 2); |
||||
Say("Oooh! Nice parallax!"); |
||||
PanToView(mainView, 2); |
||||
Say("Mmmm... purdy!"); |
||||
|
||||
MoveToRoom(menuRoom); |
||||
} |
||||
} |
Loading…
Reference in new issue