2018-04-25 13:47:56 -05:00
|
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Collections;
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
using UnityEngine;
|
|
|
|
|
using UnityEngine.UI;
|
2018-04-26 10:38:28 -05:00
|
|
|
|
using System.Text;
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
|
|
|
|
//Pretty much a copy of GetData...
|
2018-04-26 00:18:01 -05:00
|
|
|
|
namespace PedometerU.Tests {
|
2018-04-26 01:18:08 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
public class GetGoals : MonoBehaviour {
|
|
|
|
|
|
|
|
|
|
public Image background;
|
|
|
|
|
public Image fill;
|
|
|
|
|
private string[] items = { "circle_eye", "crazy_hair", "circle_head", "gap_mouth", "pig_nose", "crown" };
|
|
|
|
|
|
|
|
|
|
public Text goalText;
|
|
|
|
|
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
|
|
|
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
|
|
|
public string prefKey;
|
|
|
|
|
|
|
|
|
|
//Progress Bar...
|
|
|
|
|
public float barDisplay; //current progress
|
2018-04-27 17:33:53 -05:00
|
|
|
|
//private Vector2 barPos;
|
2018-04-26 22:58:14 -05:00
|
|
|
|
private Vector2 barSize = new Vector2(5000, 10);
|
|
|
|
|
|
|
|
|
|
//Pedometer
|
|
|
|
|
private Pedometer pedometer;
|
|
|
|
|
int userSteps;
|
|
|
|
|
int userPoints;
|
2018-04-27 17:33:53 -05:00
|
|
|
|
//double userDistance;
|
2018-04-26 22:58:14 -05:00
|
|
|
|
int stepsGoal = 100;
|
|
|
|
|
public Text stepText;
|
|
|
|
|
public Text pointsText;
|
|
|
|
|
private int savedSteps;
|
|
|
|
|
private int savedPoints;
|
|
|
|
|
|
|
|
|
|
void OnStep (int steps, double distance) {
|
2018-04-27 17:33:53 -05:00
|
|
|
|
//userDistance = (distance * 3.28084);
|
2018-04-26 22:58:14 -05:00
|
|
|
|
userSteps = steps + savedSteps;
|
|
|
|
|
PlayerPrefs.SetInt("currentSteps",userSteps);
|
|
|
|
|
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
|
|
|
|
|
|
|
|
|
|
userPoints = steps*5 + savedPoints;
|
|
|
|
|
PlayerPrefs.SetInt("totalPoints",userPoints);
|
|
|
|
|
pointsText.text = "Points: " + userPoints.ToString ();
|
|
|
|
|
}
|
2018-04-26 00:18:01 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
private void OnDisable () {
|
|
|
|
|
// Release the pedometer
|
|
|
|
|
pedometer.Dispose();
|
|
|
|
|
pedometer = null;
|
2018-04-26 04:38:54 -05:00
|
|
|
|
}
|
2018-04-26 22:58:14 -05:00
|
|
|
|
|
|
|
|
|
//saved value from last session loads in on START
|
|
|
|
|
//write usersteps + saved val to pref in ONSTEP
|
|
|
|
|
|
|
|
|
|
void Start ()
|
2018-04-26 04:38:54 -05:00
|
|
|
|
{
|
2018-04-26 22:58:14 -05:00
|
|
|
|
fill.type = Image.Type.Filled;
|
|
|
|
|
fill.fillMethod = Image.FillMethod.Horizontal;
|
|
|
|
|
fill.type = Image.Type.Sliced;
|
|
|
|
|
savedSteps = PlayerPrefs.GetInt("currentSteps");
|
|
|
|
|
savedPoints = PlayerPrefs.GetInt("totalPoints");
|
|
|
|
|
// Create a new pedometer
|
|
|
|
|
pedometer = new Pedometer(OnStep);
|
|
|
|
|
// Reset UI
|
|
|
|
|
stepText.text = savedSteps.ToString () + "/" + stepsGoal.ToString();
|
|
|
|
|
if(PlayerPrefs.HasKey("totalPoints"))
|
|
|
|
|
{
|
|
|
|
|
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetInt("totalPoints", 0);
|
|
|
|
|
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
|
|
|
|
|
}
|
|
|
|
|
userSteps = savedSteps;
|
|
|
|
|
userPoints = savedPoints;
|
2018-04-26 01:36:56 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
//OnStep(savedSteps, 0);
|
|
|
|
|
Debug.Log(savedSteps);
|
2018-04-26 01:18:08 -05:00
|
|
|
|
|
2018-04-26 01:36:56 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
//goalText.text = prefKey;
|
|
|
|
|
goalText.color = new Color(0f, 0f, 0f);
|
|
|
|
|
Debug.Log(background.rectTransform.anchoredPosition.x.ToString() + " " + background.rectTransform.anchoredPosition.y.ToString());
|
2018-04-26 12:40:50 -05:00
|
|
|
|
|
2018-04-27 17:33:53 -05:00
|
|
|
|
//barPos = new Vector2(background.transform.position.x, 1895 - background.transform.position.y);
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
|
|
|
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
|
|
|
Debug.Log(goalDayStr);
|
2018-04-25 19:59:40 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
if(prefKey == "daily")
|
|
|
|
|
savePersistantGoalDate("daily");
|
|
|
|
|
}
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
2018-04-25 19:59:40 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
//Texture the progress bar using these parameters
|
|
|
|
|
public Texture2D emptyTex;
|
|
|
|
|
public Texture2D fullTex;
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
//on a button press? begin a goal?
|
|
|
|
|
void startGoal()
|
|
|
|
|
{
|
|
|
|
|
}
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
void savePersistantGoalDate(string key)
|
|
|
|
|
{
|
|
|
|
|
PlayerPrefs.SetString(key, goalDayStr);
|
|
|
|
|
}
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
bool checkNewDay(string key)
|
|
|
|
|
{
|
|
|
|
|
string checkDay = PlayerPrefs.GetString(key);
|
|
|
|
|
if(checkDay == currentDayStr)
|
|
|
|
|
return false;
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
/*
|
|
|
|
|
void OnGUI() {
|
|
|
|
|
Debug.Log (background.rectTransform.rect.width);
|
|
|
|
|
barSize = new Vector2 (background.rectTransform.rect.width, background.rectTransform.rect.height);
|
|
|
|
|
//draw the background:
|
|
|
|
|
GUI.BeginGroup(new Rect(barPos.x, barPos.y, barSize.x, barSize.y));
|
|
|
|
|
GUI.Box(new Rect(0,0, barSize.x, barSize.y), emptyTex);
|
|
|
|
|
|
|
|
|
|
//draw the filled-in part:
|
|
|
|
|
GUI.BeginGroup(new Rect(0,0, barSize.x * barDisplay, barSize.y));
|
|
|
|
|
GUI.Box(new Rect(0,0, barSize.x, barSize.y), fullTex);
|
|
|
|
|
GUI.EndGroup();
|
2018-04-25 13:47:56 -05:00
|
|
|
|
GUI.EndGroup();
|
2018-04-26 22:58:14 -05:00
|
|
|
|
}
|
|
|
|
|
*/
|
2018-04-26 12:40:50 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
// Was used for testing.
|
2018-04-27 12:04:11 -05:00
|
|
|
|
//private float tempcounter = 0.1f;
|
2018-04-26 01:18:08 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
public void updateProgressBar()
|
2018-04-25 13:47:56 -05:00
|
|
|
|
{
|
2018-04-27 12:04:11 -05:00
|
|
|
|
//Debug.Log (background.rectTransform.rect.width + " " + background.rectTransform.rect.height);
|
2018-04-26 22:58:14 -05:00
|
|
|
|
barSize.x = background.rectTransform.rect.width;
|
|
|
|
|
barSize.y = background.rectTransform.rect.height;
|
2018-04-25 13:47:56 -05:00
|
|
|
|
|
2018-04-27 12:04:11 -05:00
|
|
|
|
//tempcounter += 0.0005f;
|
2018-04-25 19:59:40 -05:00
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
// resize the fill.
|
|
|
|
|
RectTransform temp = fill.rectTransform;
|
2018-04-27 12:04:11 -05:00
|
|
|
|
temp.sizeDelta = new Vector2 (barSize.x * barDisplay, barSize.y);
|
2018-04-26 22:58:14 -05:00
|
|
|
|
temp.anchoredPosition = new Vector2 (temp.rect.width * 0.5f - (barSize.x * 0.5f),0);
|
2018-04-25 19:59:40 -05:00
|
|
|
|
}
|
|
|
|
|
|
2018-04-26 22:58:14 -05:00
|
|
|
|
void Update()
|
2018-04-25 19:59:40 -05:00
|
|
|
|
{
|
2018-04-26 22:58:14 -05:00
|
|
|
|
updateProgressBar ();
|
|
|
|
|
//needs current points counting toward this goal (daily?)
|
|
|
|
|
//needs the total required points for this goal
|
|
|
|
|
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
|
|
|
|
//barDisplay = Time.time*0.05f; //put actual progress here (current/total)
|
|
|
|
|
barDisplay = (float)userSteps/(float)stepsGoal;
|
|
|
|
|
|
|
|
|
|
//failed to complete goal
|
|
|
|
|
if(currentDayStr != goalDayStr)
|
2018-04-25 19:59:40 -05:00
|
|
|
|
{
|
2018-04-26 22:58:14 -05:00
|
|
|
|
Debug.Log(currentDayStr);
|
|
|
|
|
Debug.Log(goalDayStr);
|
|
|
|
|
|
|
|
|
|
Debug.Log("DAY HAS PASSED!!");
|
|
|
|
|
|
|
|
|
|
//make it so user dismisses the goal instead!
|
|
|
|
|
//Destroy(this);
|
|
|
|
|
//destroy the goal and set a new one?
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
//goal complete
|
|
|
|
|
if(barDisplay >= 1.0f)
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("Goal complete! +100pts!");
|
|
|
|
|
userSteps = 0;
|
|
|
|
|
PlayerPrefs.SetInt("currentSteps", userSteps);
|
|
|
|
|
savedSteps = 0;
|
|
|
|
|
//OnStep(0,0);
|
|
|
|
|
stepText.text = userSteps.ToString () + "/" + stepsGoal.ToString();
|
|
|
|
|
|
|
|
|
|
//destroy the goal and set a new one?
|
|
|
|
|
savedPoints += stepsGoal*10;
|
|
|
|
|
PlayerPrefs.SetInt("totalPoints", savedPoints);
|
|
|
|
|
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").ToString ();
|
|
|
|
|
|
|
|
|
|
//Random item
|
|
|
|
|
StringBuilder invList = new StringBuilder ();
|
|
|
|
|
invList.Append(PlayerPrefs.GetString ("inventory"));
|
|
|
|
|
invList.Append(items[(int)Math.Round(UnityEngine.Random.value*6.0f)]).Append(" ");
|
|
|
|
|
PlayerPrefs.SetString ("inventory", invList.ToString());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//only applies if "daily" goal
|
|
|
|
|
if(prefKey == "daily")
|
|
|
|
|
{
|
|
|
|
|
if(checkNewDay(prefKey))
|
|
|
|
|
{
|
|
|
|
|
Debug.Log("You failed your goal"); //not true if progress is actually complete!
|
|
|
|
|
goalDayStr = currentDayStr;
|
|
|
|
|
savePersistantGoalDate("daily");
|
|
|
|
|
}
|
2018-04-25 19:59:40 -05:00
|
|
|
|
}
|
2018-04-25 13:47:56 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
2018-04-26 01:18:08 -05:00
|
|
|
|
|
|
|
|
|
}
|