playerpref steps

This commit is contained in:
asleal2 2018-04-26 01:18:08 -05:00
parent f3c4d0b610
commit c2ed30d441

View file

@ -7,22 +7,19 @@ using UnityEngine.UI;
//Pretty much a copy of GetData... //Pretty much a copy of GetData...
namespace PedometerU.Tests { namespace PedometerU.Tests {
public class GetGoals : MonoBehaviour { public class GetGoals : MonoBehaviour {
public Text goalText; public Text goalText;
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
public string prefKey; public string prefKey;
public float goalValue; public float goalValue;
//Progress Bar... //Progress Bar...
public float barDisplay; //current progress public float barDisplay; //current progress
private Vector2 barPos; private Vector2 barPos;
Vector2 barSize = new Vector2(227,20); private Vector2 barSize = new Vector2(227,20);
//Pedometer //Pedometer
private Pedometer pedometer; private Pedometer pedometer;
@ -30,11 +27,12 @@ public class GetGoals : MonoBehaviour {
double userDistance; double userDistance;
int totalSteps = 30; int totalSteps = 30;
public Text stepText; public Text stepText;
void OnStep (int steps, double distance) { void OnStep (int steps, double distance) {
userSteps = steps; userSteps = steps;
stepText.text = steps.ToString (); stepText.text = steps.ToString ();
userDistance = (distance * 3.28084); userDistance = (distance * 3.28084);
PlayerPrefs.setInt("currentSteps",userSteps);
} }
private void OnDisable () { private void OnDisable () {
@ -47,8 +45,8 @@ public class GetGoals : MonoBehaviour {
// Create a new pedometer // Create a new pedometer
pedometer = new Pedometer(OnStep); pedometer = new Pedometer(OnStep);
// Reset UI // Reset UI
OnStep(0, 0); OnStep(PlayerPrefs.getInt("currentSteps"), 0);
//goalText.text = prefKey; //goalText.text = prefKey;
goalText.color = new Color(0f, 0f, 0f); goalText.color = new Color(0f, 0f, 0f);
@ -103,7 +101,8 @@ public class GetGoals : MonoBehaviour {
//needs the total required points for this goal //needs the total required points for this goal
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy"); currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
//barDisplay = Time.time*0.05f; //put actual progress here (current/total) //barDisplay = Time.time*0.05f; //put actual progress here (current/total)
barDisplay = (float)userSteps/(float)totalSteps; barDisplay = (float)userSteps/(float)totalSteps;
//failed to complete goal //failed to complete goal
if(currentDayStr != goalDayStr) if(currentDayStr != goalDayStr)
{ {
@ -137,4 +136,5 @@ public class GetGoals : MonoBehaviour {
} }
} }
} }
}
}