From 1baf9e6fe50681b6c61fff12f48f4d20bca761d4 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 30 Sep 2016 11:42:38 +0100 Subject: [PATCH 1/3] MusicController and CameraController singletons are now managed by one FungusManager singleton --- Assets/Fungus/Scripts/Commands/FadeScreen.cs | 2 +- Assets/Fungus/Scripts/Commands/FadeToView.cs | 6 +- Assets/Fungus/Scripts/Commands/MoveToView.cs | 6 +- Assets/Fungus/Scripts/Commands/PlayMusic.cs | 10 +-- Assets/Fungus/Scripts/Commands/PlaySound.cs | 8 +- .../Fungus/Scripts/Commands/SetAudioPitch.cs | 8 +- .../Fungus/Scripts/Commands/SetAudioVolume.cs | 18 ++--- Assets/Fungus/Scripts/Commands/StartSwipe.cs | 2 +- Assets/Fungus/Scripts/Commands/StopMusic.cs | 8 +- Assets/Fungus/Scripts/Commands/StopSwipe.cs | 2 +- .../Scripts/Components/CameraController.cs | 17 ---- .../Scripts/Components/FungusManager.cs | 78 +++++++++++++++++++ .../Scripts/Components/FungusManager.cs.meta | 12 +++ .../Scripts/Components/MusicController.cs | 18 ----- Assets/Fungus/Scripts/Components/Writer.cs | 3 +- 15 files changed, 124 insertions(+), 74 deletions(-) create mode 100644 Assets/Fungus/Scripts/Components/FungusManager.cs create mode 100644 Assets/Fungus/Scripts/Components/FungusManager.cs.meta diff --git a/Assets/Fungus/Scripts/Commands/FadeScreen.cs b/Assets/Fungus/Scripts/Commands/FadeScreen.cs index e00a3b11..b44c35fd 100644 --- a/Assets/Fungus/Scripts/Commands/FadeScreen.cs +++ b/Assets/Fungus/Scripts/Commands/FadeScreen.cs @@ -35,7 +35,7 @@ namespace Fungus.Commands public override void OnEnter() { - var cameraController = CameraController.GetInstance(); + var cameraController = FungusManager.Instance.Camera; if (fadeTexture) { diff --git a/Assets/Fungus/Scripts/Commands/FadeToView.cs b/Assets/Fungus/Scripts/Commands/FadeToView.cs index d49d9e2a..a9363863 100644 --- a/Assets/Fungus/Scripts/Commands/FadeToView.cs +++ b/Assets/Fungus/Scripts/Commands/FadeToView.cs @@ -71,7 +71,7 @@ namespace Fungus.Commands return; } - var cameraController = CameraController.GetInstance(); + var cameraController = FungusManager.Instance.Camera; if (fadeTexture) { @@ -97,7 +97,9 @@ namespace Fungus.Commands public override void OnStopExecuting() { - CameraController.GetInstance().Stop(); + var cameraController = FungusManager.Instance.Camera; + + cameraController.Stop(); } public override string GetSummary() diff --git a/Assets/Fungus/Scripts/Commands/MoveToView.cs b/Assets/Fungus/Scripts/Commands/MoveToView.cs index ba14ce11..3521a9cb 100644 --- a/Assets/Fungus/Scripts/Commands/MoveToView.cs +++ b/Assets/Fungus/Scripts/Commands/MoveToView.cs @@ -58,7 +58,7 @@ namespace Fungus.Commands return; } - var cameraController = CameraController.GetInstance(); + var cameraController = FungusManager.Instance.Camera; Vector3 targetPosition = targetView.transform.position; Quaternion targetRotation = targetView.transform.rotation; @@ -79,7 +79,9 @@ namespace Fungus.Commands public override void OnStopExecuting() { - CameraController.GetInstance().Stop(); + var cameraController = FungusManager.Instance.Camera; + + cameraController.Stop(); } public override string GetSummary() diff --git a/Assets/Fungus/Scripts/Commands/PlayMusic.cs b/Assets/Fungus/Scripts/Commands/PlayMusic.cs index 3add80cd..69aab315 100644 --- a/Assets/Fungus/Scripts/Commands/PlayMusic.cs +++ b/Assets/Fungus/Scripts/Commands/PlayMusic.cs @@ -30,12 +30,10 @@ namespace Fungus.Commands public override void OnEnter() { - var musicController = MusicController.GetInstance(); - if (musicController != null) - { - float startTime = Mathf.Max(0, atTime); - musicController.PlayMusic(musicClip, loop, fadeDuration, startTime); - } + var musicController = FungusManager.Instance.Music; + + float startTime = Mathf.Max(0, atTime); + musicController.PlayMusic(musicClip, loop, fadeDuration, startTime); Continue(); } diff --git a/Assets/Fungus/Scripts/Commands/PlaySound.cs b/Assets/Fungus/Scripts/Commands/PlaySound.cs index 8478fa25..ad6c9446 100644 --- a/Assets/Fungus/Scripts/Commands/PlaySound.cs +++ b/Assets/Fungus/Scripts/Commands/PlaySound.cs @@ -39,11 +39,9 @@ namespace Fungus.Commands return; } - var musicController = MusicController.GetInstance(); - if (musicController != null) - { - musicController.PlaySound(soundClip, volume); - } + var musicController = FungusManager.Instance.Music; + + musicController.PlaySound(soundClip, volume); if (waitUntilFinished) { diff --git a/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs b/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs index 59002c0f..242fe901 100644 --- a/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs +++ b/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs @@ -36,11 +36,9 @@ namespace Fungus.Commands } }; - var musicController = MusicController.GetInstance(); - if (musicController != null) - { - musicController.SetAudioPitch(pitch, fadeDuration, onComplete); - } + var musicController = FungusManager.Instance.Music; + + musicController.SetAudioPitch(pitch, fadeDuration, onComplete); if (!waitUntilFinished) { diff --git a/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs b/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs index f492481c..9e4f3b9a 100644 --- a/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs +++ b/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs @@ -29,16 +29,14 @@ namespace Fungus.Commands public override void OnEnter() { - var musicController = MusicController.GetInstance(); - if (musicController != null) - { - musicController.SetAudioVolume(volume, fadeDuration, () => { - if (waitUntilFinished) - { - Continue(); - } - }); - } + var musicController = FungusManager.Instance.Music; + + musicController.SetAudioVolume(volume, fadeDuration, () => { + if (waitUntilFinished) + { + Continue(); + } + }); if (!waitUntilFinished) { diff --git a/Assets/Fungus/Scripts/Commands/StartSwipe.cs b/Assets/Fungus/Scripts/Commands/StartSwipe.cs index cd69e6a1..b6b12e63 100644 --- a/Assets/Fungus/Scripts/Commands/StartSwipe.cs +++ b/Assets/Fungus/Scripts/Commands/StartSwipe.cs @@ -53,7 +53,7 @@ namespace Fungus.Commands return; } - var cameraController = CameraController.GetInstance(); + var cameraController = FungusManager.Instance.Camera; cameraController.StartSwipePan(targetCamera, viewA, viewB, duration, speedMultiplier, () => Continue() ); } diff --git a/Assets/Fungus/Scripts/Commands/StopMusic.cs b/Assets/Fungus/Scripts/Commands/StopMusic.cs index 5e4abe27..9573721b 100644 --- a/Assets/Fungus/Scripts/Commands/StopMusic.cs +++ b/Assets/Fungus/Scripts/Commands/StopMusic.cs @@ -18,11 +18,9 @@ namespace Fungus.Commands public override void OnEnter() { - var musicController = MusicController.GetInstance(); - if (musicController != null) - { - musicController.StopMusic(); - } + var musicController = FungusManager.Instance.Music; + + musicController.StopMusic(); Continue(); } diff --git a/Assets/Fungus/Scripts/Commands/StopSwipe.cs b/Assets/Fungus/Scripts/Commands/StopSwipe.cs index 53863e5c..88205e19 100644 --- a/Assets/Fungus/Scripts/Commands/StopSwipe.cs +++ b/Assets/Fungus/Scripts/Commands/StopSwipe.cs @@ -18,7 +18,7 @@ namespace Fungus.Commands public override void OnEnter() { - var cameraController = CameraController.GetInstance(); + var cameraController = FungusManager.Instance.Camera; cameraController.StopSwipePan(); diff --git a/Assets/Fungus/Scripts/Components/CameraController.cs b/Assets/Fungus/Scripts/Components/CameraController.cs index b6824157..3bb4c6d0 100644 --- a/Assets/Fungus/Scripts/Components/CameraController.cs +++ b/Assets/Fungus/Scripts/Components/CameraController.cs @@ -51,8 +51,6 @@ namespace Fungus protected Dictionary storedViews = new Dictionary(); - protected static CameraController instance; - protected virtual void OnGUI() { if (swipePanActive) @@ -302,21 +300,6 @@ namespace Fungus #region Public members - /// - /// Returns the CameraController singleton instance. - /// Will create a CameraController game object if none currently exists. - /// - public static CameraController GetInstance() - { - if (instance == null) - { - GameObject go = new GameObject("CameraController"); - instance = go.AddComponent(); - } - - return instance; - } - /// /// Moves camera smoothly through a sequence of Views over a period of time. /// diff --git a/Assets/Fungus/Scripts/Components/FungusManager.cs b/Assets/Fungus/Scripts/Components/FungusManager.cs new file mode 100644 index 00000000..fb068120 --- /dev/null +++ b/Assets/Fungus/Scripts/Components/FungusManager.cs @@ -0,0 +1,78 @@ +using UnityEngine; +using System.Collections; + +namespace Fungus +{ + /// + /// Fungus manager singleton. Manages access to all Fungus singletons in a consistent manner. + /// + [RequireComponent(typeof(CameraController))] + [RequireComponent(typeof(MusicController))] + public sealed class FungusManager : MonoBehaviour + { + static FungusManager instance; + static bool applicationIsQuitting = false; + static object _lock = new object(); + + void Awake() + { + Camera = GetComponent(); + Music = GetComponent(); + } + + /// + /// When Unity quits, it destroys objects in a random order. + /// In principle, a Singleton is only destroyed when application quits. + /// If any script calls Instance after it have been destroyed, + /// it will create a buggy ghost object that will stay on the Editor scene + /// even after stopping playing the Application. Really bad! + /// So, this was made to be sure we're not creating that buggy ghost object. + /// + void OnDestroy () + { + applicationIsQuitting = true; + } + + #region Public methods + + /// + /// Gets the camera manager singleton instance. + /// + public CameraController Camera { get; private set; } + + /// + /// Gets the music manager singleton instance. + /// + public MusicController Music { get; private set; } + + /// + /// Gets the FungusManager singleton instance. + /// + public static FungusManager Instance + { + get + { + if (applicationIsQuitting) + { + Debug.LogWarning("FungusManager.Instance() was called while application is quitting. Returning null instead."); + return null; + } + + lock (_lock) + { + if (instance == null) + { + var go = new GameObject(); + go.name = "FungusManager"; + DontDestroyOnLoad(go); + instance = go.AddComponent(); + } + + return instance; + } + } + } + + #endregion + } +} \ No newline at end of file diff --git a/Assets/Fungus/Scripts/Components/FungusManager.cs.meta b/Assets/Fungus/Scripts/Components/FungusManager.cs.meta new file mode 100644 index 00000000..d643e8ac --- /dev/null +++ b/Assets/Fungus/Scripts/Components/FungusManager.cs.meta @@ -0,0 +1,12 @@ +fileFormatVersion: 2 +guid: fa59a268bb22b4646bd9a89fa66582b1 +timeCreated: 1475164406 +licenseType: Free +MonoImporter: + serializedVersion: 2 + defaultReferences: [] + executionOrder: 0 + icon: {instanceID: 0} + userData: + assetBundleName: + assetBundleVariant: diff --git a/Assets/Fungus/Scripts/Components/MusicController.cs b/Assets/Fungus/Scripts/Components/MusicController.cs index 8f0c655b..5bcb89b6 100644 --- a/Assets/Fungus/Scripts/Components/MusicController.cs +++ b/Assets/Fungus/Scripts/Components/MusicController.cs @@ -12,8 +12,6 @@ namespace Fungus [RequireComponent(typeof(AudioSource))] public class MusicController : MonoBehaviour { - protected static MusicController instance; - protected virtual void Start() { GetComponent().playOnAwake = false; @@ -22,22 +20,6 @@ namespace Fungus #region Public members - /// - /// Returns the MusicController singleton instance. - /// Will create a MusicController game object if none currently exists. - /// - public static MusicController GetInstance() - { - if (instance == null) - { - GameObject go = new GameObject("MusicController"); - DontDestroyOnLoad(go); - instance = go.AddComponent(); - } - - return instance; - } - /// /// Plays game music using an audio clip. /// One music clip may be played at a time. diff --git a/Assets/Fungus/Scripts/Components/Writer.cs b/Assets/Fungus/Scripts/Components/Writer.cs index 4ece9b15..905a128a 100644 --- a/Assets/Fungus/Scripts/Components/Writer.cs +++ b/Assets/Fungus/Scripts/Components/Writer.cs @@ -665,7 +665,8 @@ namespace Fungus protected virtual void Flash(float duration) { - var cameraController = CameraController.GetInstance(); + var cameraController = FungusManager.Instance.Camera; + cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(new Color(1f,1f,1f,1f), 32, 32); cameraController.Fade(1f, duration, delegate { cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(new Color(1f,1f,1f,1f), 32, 32); From 9aaa2de46482433b0575902ba2bebb78d492367e Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 30 Sep 2016 11:52:39 +0100 Subject: [PATCH 2/3] Renamed CameraController to CameraManager and MusicController to MusicManager --- Assets/Fungus/Scripts/Commands/FadeScreen.cs | 8 ++++---- Assets/Fungus/Scripts/Commands/FadeToView.cs | 12 ++++++------ Assets/Fungus/Scripts/Commands/MoveToView.cs | 8 ++++---- Assets/Fungus/Scripts/Commands/PlayMusic.cs | 4 ++-- Assets/Fungus/Scripts/Commands/PlaySound.cs | 4 ++-- Assets/Fungus/Scripts/Commands/SetAudioPitch.cs | 4 ++-- Assets/Fungus/Scripts/Commands/SetAudioVolume.cs | 4 ++-- Assets/Fungus/Scripts/Commands/StartSwipe.cs | 4 ++-- Assets/Fungus/Scripts/Commands/StopMusic.cs | 4 ++-- Assets/Fungus/Scripts/Commands/StopSwipe.cs | 4 ++-- .../{CameraController.cs => CameraManager.cs} | 4 ++-- ...ameraController.cs.meta => CameraManager.cs.meta} | 0 Assets/Fungus/Scripts/Components/FungusManager.cs | 12 ++++++------ .../{MusicController.cs => MusicManager.cs} | 4 ++-- ...{MusicController.cs.meta => MusicManager.cs.meta} | 0 Assets/Fungus/Scripts/Components/Writer.cs | 10 +++++----- 16 files changed, 43 insertions(+), 43 deletions(-) rename Assets/Fungus/Scripts/Components/{CameraController.cs => CameraManager.cs} (99%) rename Assets/Fungus/Scripts/Components/{CameraController.cs.meta => CameraManager.cs.meta} (100%) rename Assets/Fungus/Scripts/Components/{MusicController.cs => MusicManager.cs} (98%) rename Assets/Fungus/Scripts/Components/{MusicController.cs.meta => MusicManager.cs.meta} (100%) diff --git a/Assets/Fungus/Scripts/Commands/FadeScreen.cs b/Assets/Fungus/Scripts/Commands/FadeScreen.cs index b44c35fd..d8300d4b 100644 --- a/Assets/Fungus/Scripts/Commands/FadeScreen.cs +++ b/Assets/Fungus/Scripts/Commands/FadeScreen.cs @@ -35,18 +35,18 @@ namespace Fungus.Commands public override void OnEnter() { - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; if (fadeTexture) { - cameraController.ScreenFadeTexture = fadeTexture; + cameraManager.ScreenFadeTexture = fadeTexture; } else { - cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32); + cameraManager.ScreenFadeTexture = CameraManager.CreateColorTexture(fadeColor, 32, 32); } - cameraController.Fade(targetAlpha, duration, delegate { + cameraManager.Fade(targetAlpha, duration, delegate { if (waitUntilFinished) { Continue(); diff --git a/Assets/Fungus/Scripts/Commands/FadeToView.cs b/Assets/Fungus/Scripts/Commands/FadeToView.cs index a9363863..169895fe 100644 --- a/Assets/Fungus/Scripts/Commands/FadeToView.cs +++ b/Assets/Fungus/Scripts/Commands/FadeToView.cs @@ -71,18 +71,18 @@ namespace Fungus.Commands return; } - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; if (fadeTexture) { - cameraController.ScreenFadeTexture = fadeTexture; + cameraManager.ScreenFadeTexture = fadeTexture; } else { - cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(fadeColor, 32, 32); + cameraManager.ScreenFadeTexture = CameraManager.CreateColorTexture(fadeColor, 32, 32); } - cameraController.FadeToView(targetCamera, targetView, duration, fadeOut, delegate { + cameraManager.FadeToView(targetCamera, targetView, duration, fadeOut, delegate { if (waitUntilFinished) { Continue(); @@ -97,9 +97,9 @@ namespace Fungus.Commands public override void OnStopExecuting() { - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; - cameraController.Stop(); + cameraManager.Stop(); } public override string GetSummary() diff --git a/Assets/Fungus/Scripts/Commands/MoveToView.cs b/Assets/Fungus/Scripts/Commands/MoveToView.cs index 3521a9cb..49aca8b5 100644 --- a/Assets/Fungus/Scripts/Commands/MoveToView.cs +++ b/Assets/Fungus/Scripts/Commands/MoveToView.cs @@ -58,13 +58,13 @@ namespace Fungus.Commands return; } - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; Vector3 targetPosition = targetView.transform.position; Quaternion targetRotation = targetView.transform.rotation; float targetSize = targetView.ViewSize; - cameraController.PanToPosition(targetCamera, targetPosition, targetRotation, targetSize, duration, delegate { + cameraManager.PanToPosition(targetCamera, targetPosition, targetRotation, targetSize, duration, delegate { if (waitUntilFinished) { Continue(); @@ -79,9 +79,9 @@ namespace Fungus.Commands public override void OnStopExecuting() { - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; - cameraController.Stop(); + cameraManager.Stop(); } public override string GetSummary() diff --git a/Assets/Fungus/Scripts/Commands/PlayMusic.cs b/Assets/Fungus/Scripts/Commands/PlayMusic.cs index 69aab315..ddd3bbda 100644 --- a/Assets/Fungus/Scripts/Commands/PlayMusic.cs +++ b/Assets/Fungus/Scripts/Commands/PlayMusic.cs @@ -30,10 +30,10 @@ namespace Fungus.Commands public override void OnEnter() { - var musicController = FungusManager.Instance.Music; + var musicManager = FungusManager.Instance.MusicManager; float startTime = Mathf.Max(0, atTime); - musicController.PlayMusic(musicClip, loop, fadeDuration, startTime); + musicManager.PlayMusic(musicClip, loop, fadeDuration, startTime); Continue(); } diff --git a/Assets/Fungus/Scripts/Commands/PlaySound.cs b/Assets/Fungus/Scripts/Commands/PlaySound.cs index ad6c9446..b929bb2a 100644 --- a/Assets/Fungus/Scripts/Commands/PlaySound.cs +++ b/Assets/Fungus/Scripts/Commands/PlaySound.cs @@ -39,9 +39,9 @@ namespace Fungus.Commands return; } - var musicController = FungusManager.Instance.Music; + var musicManager = FungusManager.Instance.MusicManager; - musicController.PlaySound(soundClip, volume); + musicManager.PlaySound(soundClip, volume); if (waitUntilFinished) { diff --git a/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs b/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs index 242fe901..1052a86e 100644 --- a/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs +++ b/Assets/Fungus/Scripts/Commands/SetAudioPitch.cs @@ -36,9 +36,9 @@ namespace Fungus.Commands } }; - var musicController = FungusManager.Instance.Music; + var musicManager = FungusManager.Instance.MusicManager; - musicController.SetAudioPitch(pitch, fadeDuration, onComplete); + musicManager.SetAudioPitch(pitch, fadeDuration, onComplete); if (!waitUntilFinished) { diff --git a/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs b/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs index 9e4f3b9a..e36c975b 100644 --- a/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs +++ b/Assets/Fungus/Scripts/Commands/SetAudioVolume.cs @@ -29,9 +29,9 @@ namespace Fungus.Commands public override void OnEnter() { - var musicController = FungusManager.Instance.Music; + var musicManager = FungusManager.Instance.MusicManager; - musicController.SetAudioVolume(volume, fadeDuration, () => { + musicManager.SetAudioVolume(volume, fadeDuration, () => { if (waitUntilFinished) { Continue(); diff --git a/Assets/Fungus/Scripts/Commands/StartSwipe.cs b/Assets/Fungus/Scripts/Commands/StartSwipe.cs index b6b12e63..3f775d8d 100644 --- a/Assets/Fungus/Scripts/Commands/StartSwipe.cs +++ b/Assets/Fungus/Scripts/Commands/StartSwipe.cs @@ -53,9 +53,9 @@ namespace Fungus.Commands return; } - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; - cameraController.StartSwipePan(targetCamera, viewA, viewB, duration, speedMultiplier, () => Continue() ); + cameraManager.StartSwipePan(targetCamera, viewA, viewB, duration, speedMultiplier, () => Continue() ); } public override string GetSummary() diff --git a/Assets/Fungus/Scripts/Commands/StopMusic.cs b/Assets/Fungus/Scripts/Commands/StopMusic.cs index 9573721b..59e8d9d8 100644 --- a/Assets/Fungus/Scripts/Commands/StopMusic.cs +++ b/Assets/Fungus/Scripts/Commands/StopMusic.cs @@ -18,9 +18,9 @@ namespace Fungus.Commands public override void OnEnter() { - var musicController = FungusManager.Instance.Music; + var musicManager = FungusManager.Instance.MusicManager; - musicController.StopMusic(); + musicManager.StopMusic(); Continue(); } diff --git a/Assets/Fungus/Scripts/Commands/StopSwipe.cs b/Assets/Fungus/Scripts/Commands/StopSwipe.cs index 88205e19..e947d751 100644 --- a/Assets/Fungus/Scripts/Commands/StopSwipe.cs +++ b/Assets/Fungus/Scripts/Commands/StopSwipe.cs @@ -18,9 +18,9 @@ namespace Fungus.Commands public override void OnEnter() { - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; - cameraController.StopSwipePan(); + cameraManager.StopSwipePan(); Continue(); } diff --git a/Assets/Fungus/Scripts/Components/CameraController.cs b/Assets/Fungus/Scripts/Components/CameraManager.cs similarity index 99% rename from Assets/Fungus/Scripts/Components/CameraController.cs rename to Assets/Fungus/Scripts/Components/CameraManager.cs index 3bb4c6d0..a8bb4751 100644 --- a/Assets/Fungus/Scripts/Components/CameraController.cs +++ b/Assets/Fungus/Scripts/Components/CameraManager.cs @@ -10,9 +10,9 @@ using Fungus; namespace Fungus { /// - /// Controller for main camera.Supports several types of camera transition including snap, pan & fade. + /// Manager for main camera. Supports several types of camera transition including snap, pan & fade. /// - public class CameraController : MonoBehaviour + public class CameraManager : MonoBehaviour { [Tooltip("Full screen texture used for screen fade effect.")] [SerializeField] protected Texture2D screenFadeTexture; diff --git a/Assets/Fungus/Scripts/Components/CameraController.cs.meta b/Assets/Fungus/Scripts/Components/CameraManager.cs.meta similarity index 100% rename from Assets/Fungus/Scripts/Components/CameraController.cs.meta rename to Assets/Fungus/Scripts/Components/CameraManager.cs.meta diff --git a/Assets/Fungus/Scripts/Components/FungusManager.cs b/Assets/Fungus/Scripts/Components/FungusManager.cs index fb068120..65bc0cad 100644 --- a/Assets/Fungus/Scripts/Components/FungusManager.cs +++ b/Assets/Fungus/Scripts/Components/FungusManager.cs @@ -6,8 +6,8 @@ namespace Fungus /// /// Fungus manager singleton. Manages access to all Fungus singletons in a consistent manner. /// - [RequireComponent(typeof(CameraController))] - [RequireComponent(typeof(MusicController))] + [RequireComponent(typeof(CameraManager))] + [RequireComponent(typeof(MusicManager))] public sealed class FungusManager : MonoBehaviour { static FungusManager instance; @@ -16,8 +16,8 @@ namespace Fungus void Awake() { - Camera = GetComponent(); - Music = GetComponent(); + CameraManager = GetComponent(); + MusicManager = GetComponent(); } /// @@ -38,12 +38,12 @@ namespace Fungus /// /// Gets the camera manager singleton instance. /// - public CameraController Camera { get; private set; } + public CameraManager CameraManager { get; private set; } /// /// Gets the music manager singleton instance. /// - public MusicController Music { get; private set; } + public MusicManager MusicManager { get; private set; } /// /// Gets the FungusManager singleton instance. diff --git a/Assets/Fungus/Scripts/Components/MusicController.cs b/Assets/Fungus/Scripts/Components/MusicManager.cs similarity index 98% rename from Assets/Fungus/Scripts/Components/MusicController.cs rename to Assets/Fungus/Scripts/Components/MusicManager.cs index 5bcb89b6..2337870b 100644 --- a/Assets/Fungus/Scripts/Components/MusicController.cs +++ b/Assets/Fungus/Scripts/Components/MusicManager.cs @@ -10,7 +10,7 @@ namespace Fungus /// Music playback persists across scene loads. /// [RequireComponent(typeof(AudioSource))] - public class MusicController : MonoBehaviour + public class MusicManager : MonoBehaviour { protected virtual void Start() { @@ -32,7 +32,7 @@ namespace Fungus return; } - if (fadeDuration == 0f) + if (Mathf.Approximately(fadeDuration, 0f)) { audioSource.clip = musicClip; audioSource.loop = loop; diff --git a/Assets/Fungus/Scripts/Components/MusicController.cs.meta b/Assets/Fungus/Scripts/Components/MusicManager.cs.meta similarity index 100% rename from Assets/Fungus/Scripts/Components/MusicController.cs.meta rename to Assets/Fungus/Scripts/Components/MusicManager.cs.meta diff --git a/Assets/Fungus/Scripts/Components/Writer.cs b/Assets/Fungus/Scripts/Components/Writer.cs index 905a128a..e26baba2 100644 --- a/Assets/Fungus/Scripts/Components/Writer.cs +++ b/Assets/Fungus/Scripts/Components/Writer.cs @@ -665,12 +665,12 @@ namespace Fungus protected virtual void Flash(float duration) { - var cameraController = FungusManager.Instance.Camera; + var cameraManager = FungusManager.Instance.CameraManager; - cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(new Color(1f,1f,1f,1f), 32, 32); - cameraController.Fade(1f, duration, delegate { - cameraController.ScreenFadeTexture = CameraController.CreateColorTexture(new Color(1f,1f,1f,1f), 32, 32); - cameraController.Fade(0f, duration, null); + cameraManager.ScreenFadeTexture = CameraManager.CreateColorTexture(new Color(1f,1f,1f,1f), 32, 32); + cameraManager.Fade(1f, duration, delegate { + cameraManager.ScreenFadeTexture = CameraManager.CreateColorTexture(new Color(1f,1f,1f,1f), 32, 32); + cameraManager.Fade(0f, duration, null); }); } From 44aade812bc71bffac55a891c1c985eb4d86bf47 Mon Sep 17 00:00:00 2001 From: Christopher Date: Fri, 30 Sep 2016 12:03:30 +0100 Subject: [PATCH 3/3] Changed float comparisons to use Mathf.Approximately --- Assets/Fungus/Scripts/Commands/CallMethod.cs | 2 +- Assets/Fungus/Scripts/Commands/FadeUI.cs | 6 +++--- Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs | 2 +- Assets/Fungus/Scripts/Components/CameraManager.cs | 2 +- Assets/Fungus/Scripts/Components/MusicManager.cs | 2 +- Assets/Fungus/Scripts/Components/SayDialog.cs | 2 +- Assets/Fungus/Scripts/Components/SpriteFader.cs | 2 +- 7 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Assets/Fungus/Scripts/Commands/CallMethod.cs b/Assets/Fungus/Scripts/Commands/CallMethod.cs index df7dc2a5..d0d9e718 100644 --- a/Assets/Fungus/Scripts/Commands/CallMethod.cs +++ b/Assets/Fungus/Scripts/Commands/CallMethod.cs @@ -41,7 +41,7 @@ namespace Fungus.Commands return; } - if (delay == 0f) + if (Mathf.Approximately(delay, 0f)) { CallTheMethod(); } diff --git a/Assets/Fungus/Scripts/Commands/FadeUI.cs b/Assets/Fungus/Scripts/Commands/FadeUI.cs index e4978357..6927a91e 100644 --- a/Assets/Fungus/Scripts/Commands/FadeUI.cs +++ b/Assets/Fungus/Scripts/Commands/FadeUI.cs @@ -37,7 +37,7 @@ namespace Fungus.Commands { foreach (Image image in go.GetComponentsInChildren()) { - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { switch (fadeMode) { @@ -67,7 +67,7 @@ namespace Fungus.Commands foreach (Text text in go.GetComponentsInChildren()) { - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { switch (fadeMode) { @@ -97,7 +97,7 @@ namespace Fungus.Commands foreach (TextMesh textMesh in go.GetComponentsInChildren()) { - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { switch (fadeMode) { diff --git a/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs b/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs index 53734c64..764370a2 100644 --- a/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs +++ b/Assets/Fungus/Scripts/Commands/PlayUsfxrSound.cs @@ -56,7 +56,7 @@ using Fungus.Variables; { _synth.SetParentTransform(ParentTransform); _synth.Play(); - if (waitDuration == 0f) + if (Mathf.Approximately(waitDuration, 0f)) { Continue(); } diff --git a/Assets/Fungus/Scripts/Components/CameraManager.cs b/Assets/Fungus/Scripts/Components/CameraManager.cs index a8bb4751..93527250 100644 --- a/Assets/Fungus/Scripts/Components/CameraManager.cs +++ b/Assets/Fungus/Scripts/Components/CameraManager.cs @@ -428,7 +428,7 @@ namespace Fungus swipePanActive = false; - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { // Move immediately camera.orthographicSize = targetSize; diff --git a/Assets/Fungus/Scripts/Components/MusicManager.cs b/Assets/Fungus/Scripts/Components/MusicManager.cs index 2337870b..214fad29 100644 --- a/Assets/Fungus/Scripts/Components/MusicManager.cs +++ b/Assets/Fungus/Scripts/Components/MusicManager.cs @@ -78,7 +78,7 @@ namespace Fungus { AudioSource audio = GetComponent(); - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { audio.pitch = pitch; if (onComplete != null) diff --git a/Assets/Fungus/Scripts/Components/SayDialog.cs b/Assets/Fungus/Scripts/Components/SayDialog.cs index 8acf3704..1f015c92 100644 --- a/Assets/Fungus/Scripts/Components/SayDialog.cs +++ b/Assets/Fungus/Scripts/Components/SayDialog.cs @@ -144,7 +144,7 @@ namespace Fungus targetAlpha = 1f; fadeCoolDownTimer = 0.1f; } - else if (fadeWhenDone && fadeCoolDownTimer == 0f) + else if (fadeWhenDone && Mathf.Approximately(fadeCoolDownTimer, 0f)) { targetAlpha = 0f; } diff --git a/Assets/Fungus/Scripts/Components/SpriteFader.cs b/Assets/Fungus/Scripts/Components/SpriteFader.cs index 7d7eb119..f43fff83 100644 --- a/Assets/Fungus/Scripts/Components/SpriteFader.cs +++ b/Assets/Fungus/Scripts/Components/SpriteFader.cs @@ -96,7 +96,7 @@ namespace Fungus } // Early out if duration is zero - if (duration == 0f) + if (Mathf.Approximately(duration, 0f)) { spriteRenderer.color = targetColor; if (onComplete != null)