From 8b6820a52968d79dddf3444d36f3398b6631ff10 Mon Sep 17 00:00:00 2001 From: chrisgregan Date: Wed, 20 Aug 2014 14:23:19 +0100 Subject: [PATCH] CameraController is now a singleton --- Assets/Fungus/Camera/Commands/SetView.cs | 15 +++--- .../Fungus/Camera/Scripts/CameraController.cs | 44 +++++++++++++++++- .../Camera/Scripts/CameraController.cs.meta | 3 +- .../Fungus/Camera/Sprites/ScreenFade.png.meta | 4 +- Assets/Fungus/Legacy/Scripts/Game.cs | 31 ++---------- Assets/Fungus/Sprite/Commands/FadeSprite.cs | 6 +-- Assets/Shuttle/ShuttleGame.unity | Bin 87636 -> 85940 bytes 7 files changed, 62 insertions(+), 41 deletions(-) diff --git a/Assets/Fungus/Camera/Commands/SetView.cs b/Assets/Fungus/Camera/Commands/SetView.cs index 9cee2969..d44a0b67 100644 --- a/Assets/Fungus/Camera/Commands/SetView.cs +++ b/Assets/Fungus/Camera/Commands/SetView.cs @@ -18,22 +18,25 @@ namespace Fungus.Script public float duration; public Fungus.View targetView; public bool waitUntilFinished = true; + public Color fadeColor = Color.black; public override void OnEnter() { - Game game = Game.GetInstance(); + CameraController cameraController = CameraController.GetInstance(); if (waitUntilFinished) { - game.waiting = true; + cameraController.waiting = true; } if (transition == Transition.Fade) { - game.cameraController.FadeToView(targetView, duration, delegate { + cameraController.screenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32); + + cameraController.FadeToView(targetView, duration, delegate { if (waitUntilFinished) { - game.waiting = false; + cameraController.waiting = false; Continue(); } }); @@ -44,10 +47,10 @@ namespace Fungus.Script Quaternion targetRotation = targetView.transform.rotation; float targetSize = targetView.viewSize; - game.cameraController.PanToPosition(targetPosition, targetRotation, targetSize, duration, delegate { + cameraController.PanToPosition(targetPosition, targetRotation, targetSize, duration, delegate { if (waitUntilFinished) { - game.waiting = false; + cameraController.waiting = false; Continue(); } }); diff --git a/Assets/Fungus/Camera/Scripts/CameraController.cs b/Assets/Fungus/Camera/Scripts/CameraController.cs index 287909b0..fbf0fa7a 100644 --- a/Assets/Fungus/Camera/Scripts/CameraController.cs +++ b/Assets/Fungus/Camera/Scripts/CameraController.cs @@ -36,6 +36,9 @@ namespace Fungus [HideInInspector] public bool swipePanActive; + [HideInInspector] + public bool waiting; + float fadeAlpha = 0f; // Swipe panning control @@ -52,6 +55,37 @@ namespace Fungus Dictionary storedViews = new Dictionary(); + static CameraController instance; + + /** + * Returns the CameraController singleton instance. + * Will create a CameraController game object if none currently exists. + */ + static public CameraController GetInstance() + { + if (instance == null) + { + GameObject go = new GameObject("CameraController"); + instance = go.AddComponent(); + } + + return instance; + } + + public static Texture2D CreateColorTexture(Color color, int width, int height) + { + Color[] pixels = new Color[width * height]; + for (int i = 0; i < pixels.Length; i++) + { + pixels[i] = color; + } + Texture2D texture = new Texture2D(width, height, TextureFormat.ARGB32, false); + texture.SetPixels(pixels); + texture.Apply(); + + return texture; + } + void OnGUI() { if (swipePanActive) @@ -75,7 +109,8 @@ namespace Fungus } // Draw full screen fade texture - if (fadeAlpha < 1f) + if (fadeAlpha < 1f && + screenFadeTexture != null) { // 1 = scene fully visible // 0 = scene fully obscured @@ -166,6 +201,11 @@ namespace Fungus SetCameraZ(); } + public void PanToView(View view, float duration, Action arriveAction) + { + PanToPosition(view.transform.position, view.transform.rotation, view.viewSize, duration, arriveAction); + } + /** * Moves camera from current position to a target position over a period of time. */ @@ -267,7 +307,7 @@ namespace Fungus Camera.main.transform.position = Vector3.Lerp(startPos, endPos, Mathf.SmoothStep(0f, 1f, t)); Camera.main.transform.rotation = Quaternion.Lerp(startRot, endRot, Mathf.SmoothStep(0f, 1f, t)); SetCameraZ(); - + if (arrived && arriveAction != null) { diff --git a/Assets/Fungus/Camera/Scripts/CameraController.cs.meta b/Assets/Fungus/Camera/Scripts/CameraController.cs.meta index 319781b7..9c68508f 100644 --- a/Assets/Fungus/Camera/Scripts/CameraController.cs.meta +++ b/Assets/Fungus/Camera/Scripts/CameraController.cs.meta @@ -3,7 +3,8 @@ guid: efb7bb24722d4469bbd789bd2e01db19 MonoImporter: serializedVersion: 2 defaultReferences: - - fadeTexture: {fileID: 2800000, guid: f6c7b1f3a78a24703b70c746d8b9c768, type: 3} + - screenFadeTexture: {fileID: 2800000, guid: f6c7b1f3a78a24703b70c746d8b9c768, type: 3} + - swipePanIcon: {fileID: 2800000, guid: 41bc737f4dc1b40db872aca00bcd7d4b, type: 3} executionOrder: 0 icon: {instanceID: 0} userData: diff --git a/Assets/Fungus/Camera/Sprites/ScreenFade.png.meta b/Assets/Fungus/Camera/Sprites/ScreenFade.png.meta index d9920191..6284b274 100644 --- a/Assets/Fungus/Camera/Sprites/ScreenFade.png.meta +++ b/Assets/Fungus/Camera/Sprites/ScreenFade.png.meta @@ -1,6 +1,7 @@ fileFormatVersion: 2 guid: f6c7b1f3a78a24703b70c746d8b9c768 TextureImporter: + fileIDToRecycleName: {} serializedVersion: 2 mipmaps: mipMapMode: 0 @@ -20,7 +21,7 @@ TextureImporter: grayScaleToAlpha: 0 generateCubemap: 0 seamlessCubemap: 0 - textureFormat: -1 + textureFormat: -3 maxTextureSize: 1024 textureSettings: filterMode: -1 @@ -35,6 +36,7 @@ TextureImporter: spriteMeshType: 1 alignment: 0 spritePivot: {x: .5, y: .5} + spriteBorder: {x: 0, y: 0, z: 0, w: 0} spritePixelsToUnits: 100 alphaIsTransparency: 0 textureType: -1 diff --git a/Assets/Fungus/Legacy/Scripts/Game.cs b/Assets/Fungus/Legacy/Scripts/Game.cs index 8dbe9efb..ced06878 100644 --- a/Assets/Fungus/Legacy/Scripts/Game.cs +++ b/Assets/Fungus/Legacy/Scripts/Game.cs @@ -16,22 +16,8 @@ namespace Fungus * Manages global game state and movement between rooms. */ [RequireComponent(typeof(Dialog))] - [RequireComponent(typeof(CameraController))] public class Game : MonoBehaviour { - /** - * Show links between Rooms in scene view. - */ - [Tooltip("Show links between Rooms in scene view.")] - public bool showLinks = true; - - /** - * Fade transition time when moving between Rooms. - */ - [Range(0,5)] - [Tooltip("Fade transition time when moving between Rooms.")] - public float roomFadeDuration = 1f; - /** * Fade transition time when hiding/showing buttons. */ @@ -58,15 +44,6 @@ namespace Fungus [Tooltip("Loading image displayed when loading a scene using MoveToScene() command.")] public Texture2D loadingImage; - [HideInInspector] - public CameraController cameraController; - - /** - * True when executing a Wait() or WaitForTap() command - */ - [HideInInspector] - public bool waiting; - float autoHideButtonTimer; static Game instance; @@ -90,10 +67,6 @@ namespace Fungus public virtual void Start() { - // Acquire references to required components - - cameraController = gameObject.GetComponent(); - // Auto-hide buttons should be visible at start of game autoHideButtonTimer = autoHideButtonDuration; } @@ -125,7 +98,9 @@ namespace Fungus */ public bool GetShowAutoButtons() { - if (waiting) + CameraController cameraController = CameraController.GetInstance(); + + if (cameraController.waiting) { return false; } diff --git a/Assets/Fungus/Sprite/Commands/FadeSprite.cs b/Assets/Fungus/Sprite/Commands/FadeSprite.cs index 6a6666ba..d90a3476 100644 --- a/Assets/Fungus/Sprite/Commands/FadeSprite.cs +++ b/Assets/Fungus/Sprite/Commands/FadeSprite.cs @@ -15,17 +15,17 @@ namespace Fungus.Script public override void OnEnter() { - Game game = Game.GetInstance(); + CameraController cameraController = CameraController.GetInstance(); if (waitUntilFinished) { - game.waiting = true; + cameraController.waiting = true; } SpriteFader.FadeSprite(spriteRenderer, targetColor, duration, Vector2.zero, delegate { if (waitUntilFinished) { - game.waiting = false; + cameraController.waiting = false; Continue(); } }); diff --git a/Assets/Shuttle/ShuttleGame.unity b/Assets/Shuttle/ShuttleGame.unity index 9d19030da1f0175ad92c09e9fec7e17b0f9c1fa8..0466e4970ad9dbc0e7ef0b1fb06b1ed9d857ec9b 100644 GIT binary patch delta 3701 zcmZA3drVu`9S87pcoh;}#tx5!hY61u48){hOas9{(;CtOp=n2&j7OK|vAB(ix`a(p z4N+Oi)~qzA$uV6fOj}KC%2ZP`nM!R+q)lNe-T0$jnYK30nq)*;7p6flX$kvY`jl;~ zSm@TC8H#kzMP8@#mfva+0|wEAP#W5-(`ud5{oyA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