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 9d19030d..0466e497 100644 Binary files a/Assets/Shuttle/ShuttleGame.unity and b/Assets/Shuttle/ShuttleGame.unity differ