Merge branch 'andrew' into darrel
This commit is contained in:
commit
d5a5432f4b
8 changed files with 187 additions and 19 deletions
BIN
MoCha/Assets/Prefabs/Progress Bar.prefab
Normal file
BIN
MoCha/Assets/Prefabs/Progress Bar.prefab
Normal file
Binary file not shown.
10
MoCha/Assets/Prefabs/Progress Bar.prefab.meta
Normal file
10
MoCha/Assets/Prefabs/Progress Bar.prefab.meta
Normal file
|
@ -0,0 +1,10 @@
|
||||||
|
fileFormatVersion: 2
|
||||||
|
guid: 441f50f7e865a4e9c937038cedf667ee
|
||||||
|
timeCreated: 1524703581
|
||||||
|
licenseType: Free
|
||||||
|
NativeFormatImporter:
|
||||||
|
externalObjects: {}
|
||||||
|
mainObjectFileID: 100100000
|
||||||
|
userData:
|
||||||
|
assetBundleName:
|
||||||
|
assetBundleVariant:
|
Binary file not shown.
174
MoCha/Assets/Scripts/GetGoals.cs
Normal file
174
MoCha/Assets/Scripts/GetGoals.cs
Normal file
|
@ -0,0 +1,174 @@
|
||||||
|
using System;
|
||||||
|
using System.Globalization;
|
||||||
|
using System.Collections;
|
||||||
|
using System.Collections.Generic;
|
||||||
|
using UnityEngine;
|
||||||
|
using UnityEngine.UI;
|
||||||
|
|
||||||
|
//Pretty much a copy of GetData...
|
||||||
|
namespace PedometerU.Tests {
|
||||||
|
|
||||||
|
public class GetGoals : MonoBehaviour {
|
||||||
|
|
||||||
|
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
|
||||||
|
private Vector2 barPos;
|
||||||
|
private Vector2 barSize = new Vector2(227,20);
|
||||||
|
|
||||||
|
//Pedometer
|
||||||
|
private Pedometer pedometer;
|
||||||
|
int userSteps;
|
||||||
|
int userPoints;
|
||||||
|
double userDistance;
|
||||||
|
int stepsGoal = 100;
|
||||||
|
public Text stepText;
|
||||||
|
public Text pointsText;
|
||||||
|
private int savedSteps;
|
||||||
|
private int savedPoints;
|
||||||
|
|
||||||
|
void OnStep (int steps, double distance) {
|
||||||
|
userDistance = (distance * 3.28084);
|
||||||
|
userSteps = steps + savedSteps;
|
||||||
|
PlayerPrefs.SetInt("currentSteps",userSteps);
|
||||||
|
stepText.text = userSteps.ToString ();
|
||||||
|
|
||||||
|
userPoints = steps*5 + savedPoints;
|
||||||
|
PlayerPrefs.SetInt("totalPoints",userPoints);
|
||||||
|
pointsText.text = "Points: " + userPoints.ToString ();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void OnDisable () {
|
||||||
|
// Release the pedometer
|
||||||
|
pedometer.Dispose();
|
||||||
|
pedometer = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
//saved value from last session loads in on START
|
||||||
|
//write usersteps + saved val to pref in ONSTEP
|
||||||
|
|
||||||
|
void Start () {
|
||||||
|
savedSteps = PlayerPrefs.GetInt("currentSteps");
|
||||||
|
savedPoints = PlayerPrefs.GetInt("totalPoints");
|
||||||
|
// Create a new pedometer
|
||||||
|
pedometer = new Pedometer(OnStep);
|
||||||
|
// Reset UI
|
||||||
|
stepText.text = savedSteps.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;
|
||||||
|
|
||||||
|
//OnStep(savedSteps, 0);
|
||||||
|
Debug.Log(savedSteps);
|
||||||
|
|
||||||
|
|
||||||
|
//goalText.text = prefKey;
|
||||||
|
goalText.color = new Color(0f, 0f, 0f);
|
||||||
|
|
||||||
|
barPos = new Vector2(goalText.transform.position.x - 105, goalText.transform.position.y - 30);
|
||||||
|
|
||||||
|
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||||
|
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
|
||||||
|
Debug.Log(goalDayStr);
|
||||||
|
|
||||||
|
if(prefKey == "daily")
|
||||||
|
savePersistantGoalDate("daily");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Texture the progress bar using these parameters
|
||||||
|
public Texture2D emptyTex;
|
||||||
|
public Texture2D fullTex;
|
||||||
|
|
||||||
|
//on a button press? begin a goal?
|
||||||
|
void startGoal()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void savePersistantGoalDate(string key)
|
||||||
|
{
|
||||||
|
PlayerPrefs.SetString(key, goalDayStr);
|
||||||
|
}
|
||||||
|
|
||||||
|
bool checkNewDay(string key)
|
||||||
|
{
|
||||||
|
string checkDay = PlayerPrefs.GetString(key);
|
||||||
|
if(checkDay == currentDayStr)
|
||||||
|
return false;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void OnGUI() {
|
||||||
|
//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();
|
||||||
|
GUI.EndGroup();
|
||||||
|
}
|
||||||
|
|
||||||
|
void Update() {
|
||||||
|
//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)
|
||||||
|
{
|
||||||
|
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 ();
|
||||||
|
|
||||||
|
//destroy the goal and set a new one?
|
||||||
|
savedPoints += stepsGoal*10;
|
||||||
|
PlayerPrefs.SetInt("totalPoints", savedPoints);
|
||||||
|
pointsText.text = "Points: " + PlayerPrefs.GetInt("totalPoints").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");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
fileFormatVersion: 2
|
fileFormatVersion: 2
|
||||||
guid: 5f138b644c262457385474b2256308a7
|
guid: 040f99a891f1b4fed92f5a44e33fc47f
|
||||||
timeCreated: 1524165858
|
timeCreated: 1524166714
|
||||||
licenseType: Free
|
licenseType: Free
|
||||||
MonoImporter:
|
MonoImporter:
|
||||||
externalObjects: {}
|
externalObjects: {}
|
|
@ -1,16 +0,0 @@
|
||||||
using System.Collections;
|
|
||||||
using System.Collections.Generic;
|
|
||||||
using UnityEngine;
|
|
||||||
|
|
||||||
public class Goals : MonoBehaviour {
|
|
||||||
|
|
||||||
// Use this for initialization
|
|
||||||
void Start () {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// Update is called once per frame
|
|
||||||
void Update () {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1 +1 @@
|
||||||
m_EditorVersion: 2017.3.1f1
|
m_EditorVersion: 2017.4.0f1
|
||||||
|
|
Reference in a new issue