This repository has been archived on 2025-04-11. You can view files and clone it, but cannot push or open issues or pull requests.
mochapine64backup/MoCha/Assets/Scripts/GetGoals.cs

84 lines
2.1 KiB
C#

using System;
using System.Globalization;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
//Pretty much a copy of GetData...
public class GetGoals : MonoBehaviour {
public Text objectText;
public string currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy/mm");
public string goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy/mm");
public string prefKey;
void Start () {
objectText = GetComponent<Text> ();
currentDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
goalDayStr = System.DateTime.Now.ToString("MM/dd/yyyy");
}
//Progress Bar...
public float barDisplay; //current progress
public Vector2 barPos = new Vector2(20,190);
public Vector2 barSize = new Vector2(60,20);
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)
if(currentDayStr != goalDayStr)
{
//check if goal is complete or not, the day is over
barDisplay = 1.0f;
Debug.Log("DAY HAS PASSED!!");
}
if(checkNewDay("daily"))
{
Debug.Log("You failed your goal"); //not true if progress is actually complete!
goalDayStr = currentDayStr;
savePersistantGoalDate("daily");
}
}
}