1- using System ;
1+ // Copyright (c) Microsoft Corporation. All rights reserved.
2+ // Licensed under the MIT License. See LICENSE in the project root for license information.
3+
4+ using System ;
25using System . Collections . Generic ;
3- using System . Linq ;
4- using System . Text ;
56using UnityEngine ;
67
78namespace Fizzyo
@@ -20,7 +21,6 @@ namespace Fizzyo
2021 /// </summary>
2122 public class FizzyoAnalytics
2223 {
23-
2424 // Various session parameters
2525 public int breathCount ;
2626 public int goodBreathCount ;
@@ -32,18 +32,22 @@ public class FizzyoAnalytics
3232 /// <summary>
3333 /// Add this to your game to update the score to send in the session.
3434 /// </summary>
35- public int Score {
36- get { return _score ; }
37- set {
38- if ( value >= _score ) {
39- _score = value ;
40- }
41- }
35+ public int Score
36+ {
37+ get { return _score ; }
38+ set
39+ {
40+ if ( value >= _score )
41+ {
42+ _score = value ;
43+ }
44+ }
4245 }
4346
4447 private int _setCount ;
48+
4549 /// <summary>
46- /// Add this to your game to update the breathing setcount to send in the session.
50+ /// Add this to your game to update the breathing set-count to send in the session.
4751 /// </summary>
4852 public int SetCount { get { return _setCount ; } set { _setCount = value ; } }
4953
@@ -56,29 +60,29 @@ public int Score {
5660 /// <param name="breathCount">
5761 /// Integer holding the amount of breaths that are to be completed in each set
5862 /// </param>
59-
6063 private void Start ( )
6164 {
62- //Set start time
63- ///
64- System . DateTime epochStart = new System . DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , System . DateTimeKind . Utc ) ;
65- startTime = ( int ) ( System . DateTime . UtcNow - epochStart ) . TotalSeconds ;
65+ //Set start time
66+ ///
67+ System . DateTime epochStart = new System . DateTime ( 1970 , 1 , 1 , 0 , 0 , 0 , System . DateTimeKind . Utc ) ;
68+ startTime = ( int ) ( System . DateTime . UtcNow - epochStart ) . TotalSeconds ;
6669 }
70+
6771 private void OnApplicationFocus ( bool focus )
6872 {
6973 if ( focus )
7074 {
71-
75+
7276 }
7377 else
7478 {
75-
79+
7680 }
7781 }
78-
79- ///<summary>
80- ///Add this to the logic which manages quitting the application to Create and Post sessions.
81- ///</summary>
82+
83+ ///<summary>
84+ ///Add this to the logic which manages quitting the application to Create and Post sessions.
85+ ///</summary>
8286 public void PostOnQuit ( )
8387 {
8488 Debug . Log ( "[FizzyoAnalytics] About to quit: creating session to upload." ) ;
@@ -90,8 +94,7 @@ public void PostOnQuit()
9094
9195 ///<summary>
9296 ///Sets all the fields of the session before upload.
93- ///</summary>
94-
97+ ///</summary>
9598 void CreateSession ( )
9699 {
97100 //All of the stats comes from the Breath Recognizer
@@ -100,27 +103,25 @@ void CreateSession()
100103 badBreathCount = FizzyoFramework . Instance . Recogniser . BadBreaths ;
101104 endTime = ( Int32 ) ( DateTime . UtcNow . Subtract ( new DateTime ( 1970 , 1 , 1 ) ) ) . TotalSeconds ;
102105 Debug . Log ( "Good breath count = " + goodBreathCount ) ;
103- Debug . Log ( "Bearth count = " + breathCount ) ;
106+ Debug . Log ( "Breath count = " + breathCount ) ;
104107 Debug . Log ( "Bad breath count = " + badBreathCount ) ;
105108 Debug . Log ( "Highest score = " + _score ) ;
106109 Debug . Log ( "Time in Unix epoch: " + endTime ) ;
107-
108110 }
109111
110- ///<summary>
111- ///Once the game shuts down, information from the session is sent to the server.
112- ///
113- ///It will send:
114- /// 1. Amount of sets in this session
115- /// 2. Amounts of breaths in this session
116- /// 3. Amount of good breaths in this session
117- /// 4. Amount of bad breaths in this session
118- /// 5. User-s highest score for this session
119- /// 6. Start time of the session
120- /// 7. End time of the session.
121- /// Note: Time represented as Unix Epoch time.
122- /// </summary>
123-
112+ ///<summary>
113+ ///Once the game shuts down, information from the session is sent to the server.
114+ ///
115+ ///It will send:
116+ /// 1. Amount of sets in this session
117+ /// 2. Amounts of breaths in this session
118+ /// 3. Amount of good breaths in this session
119+ /// 4. Amount of bad breaths in this session
120+ /// 5. User-s highest score for this session
121+ /// 6. Start time of the session
122+ /// 7. End time of the session.
123+ /// Note: Time represented as Unix Epoch time.
124+ /// </summary>
124125 public FizzyoRequestReturnType PostAnalytics ( )
125126 {
126127 ///https://api.fizzyo-ucl.co.uk/api/v1/games/<id>/sessions
@@ -140,27 +141,19 @@ public FizzyoRequestReturnType PostAnalytics()
140141 headers [ "Authorization" ] = "Bearer " + FizzyoFramework . Instance . User . AccessToken ;
141142
142143 byte [ ] rawData = form . data ;
143-
144+
144145 WWW sendPostAnalytics = new WWW ( postAnalytics , rawData , headers ) ;
145-
146+
146147 while ( ! sendPostAnalytics . isDone ) { } ;
147148
148149 if ( sendPostAnalytics . error != null )
149150 {
150151 Debug . Log ( "[FizzyoAnalytics] Posting analytics failed. " ) ;
151152 return FizzyoRequestReturnType . FAILED_TO_CONNECT ;
152-
153+
153154 }
154155 Debug . Log ( "[FizzyoAnalytics] Posting analytics successful." ) ;
155156 return FizzyoRequestReturnType . SUCCESS ;
156157 }
157-
158-
159-
160-
161- }
162-
163-
164-
165158 }
166-
159+ }
0 commit comments