Skip to content

Commit 8ff78e6

Browse files
authored
Merge pull request #3 from SimonDarksideJ/SingletonRestartFix
Fix restart issue with FizzyoFramework
2 parents 6446175 + 8a5a12f commit 8ff78e6

File tree

2 files changed

+57
-43
lines changed

2 files changed

+57
-43
lines changed

Assets/Fizzyo/Scripts/FizzyoFramework/FizzyoFramework.cs

Lines changed: 26 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -92,10 +92,10 @@ public static FizzyoFramework Instance
9292
Debug.LogWarning("[Singleton] Instance '" + typeof(FizzyoFramework) +
9393
"' already destroyed on application quit." +
9494
" Won't create again - returning null.");
95-
// return null;
95+
// return null;
9696
}
9797

98-
// lock (_lock)
98+
// lock (_lock)
9999
{
100100
if (_instance == null)
101101
{
@@ -187,7 +187,8 @@ void Start()
187187
private void Update()
188188
{
189189
//update the breath recoginiser
190-
if (Device != null) {
190+
if (Device != null)
191+
{
191192
Recogniser.AddSample(Time.deltaTime, Device.Pressure());
192193
}
193194

@@ -245,19 +246,19 @@ private void Update()
245246
/// false if data is not loaded and playing offline
246247
/// </returns>
247248
public bool Load()
248-
{
249+
{
249250
//Login to server
250251

251252
if (showLoginAutomatically)
252253
{
253254
LoginReturnType loginResult = User.Login();
254255

255256

256-
if (loginResult != LoginReturnType.SUCCESS)
257-
{
258-
PlayOffline();
259-
return false;
260-
}
257+
if (loginResult != LoginReturnType.SUCCESS)
258+
{
259+
PlayOffline();
260+
return false;
261+
}
261262
}
262263
else
263264
{
@@ -281,20 +282,26 @@ public bool Load()
281282
/// Sets up the player preferences to allow the user to play offline
282283
/// </summary>
283284
private static void PlayOffline()
284-
{
285-
// ResetPlayerPrefs();
286-
}
285+
{
286+
// ResetPlayerPrefs();
287+
}
287288

288-
/// <summary>
289-
/// Resets all of the player preferences
290-
/// </summary>
289+
/// <summary>
290+
/// Resets all of the player preferences
291+
/// </summary>
291292

292293

293294

294-
public void OnDestroy()
295-
{
296-
applicationIsQuitting = true;
297-
}
295+
public void OnDestroy()
296+
{
297+
applicationIsQuitting = true;
298+
}
299+
300+
private void OnEnable()
301+
{
302+
applicationIsQuitting = false;
303+
304+
}
298305

299306

300307
}
Lines changed: 31 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,35 @@
1-
using System.Collections;
2-
using System.Collections.Generic;
3-
using UnityEngine;
4-
using Fizzyo;
5-
6-
public class PlayerBehaviour : MonoBehaviour {
7-
8-
//Speed to move character at
9-
public float speed = 0.04f;
10-
public float flyHeight = 3.0f;
1+
using System.Collections;
2+
using System.Collections.Generic;
3+
using UnityEngine;
4+
using Fizzyo;
5+
using UnityEngine.SceneManagement;
6+
7+
public class PlayerBehaviour : MonoBehaviour {
8+
9+
//Speed to move character at
10+
public float speed = 0.04f;
11+
public float flyHeight = 3.0f;
1112
Vector3 destPos;
1213
// Use this for initialization
1314
void Start () {
1415
destPos = transform.position;
15-
}
16-
17-
// Update is called once per frame
18-
void Update () {
19-
//move the player forward
20-
float x = transform.position.x + speed;
21-
//set height of the player using the player breath intensity
22-
float y = FizzyoFramework.Instance.Device.Pressure() * flyHeight;
23-
//Device.Pressure() can return negative numbers if the player is breathing in. Clamp the player height to be above 0
24-
y = Mathf.Max(y, 0);
25-
26-
transform.position = new Vector3(x,y, 0);
27-
}
28-
}
16+
}
17+
18+
// Update is called once per frame
19+
void Update () {
20+
//move the player forward
21+
float x = transform.position.x + speed;
22+
//set height of the player using the player breath intensity
23+
float y = FizzyoFramework.Instance.Device.Pressure() * flyHeight;
24+
//Device.Pressure() can return negative numbers if the player is breathing in. Clamp the player height to be above 0
25+
y = Mathf.Max(y, 0);
26+
27+
transform.position = new Vector3(x,y, 0);
28+
29+
if (Input.GetKeyDown(KeyCode.Q))
30+
{
31+
Debug.Log("Level Restarted");
32+
SceneManager.LoadScene("ExampleLevel");
33+
}
34+
}
35+
}

0 commit comments

Comments
 (0)