Fixed idleExp not working on android
Fixed idleExp only working through unity editor, now works on application built to an android device through OnApplicationFocus()
This commit is contained in:
parent
0bae48932e
commit
a04e1e1225
|
@ -28,6 +28,8 @@ public class GameManager : MonoBehaviour {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void OnEnable()
|
void OnEnable()
|
||||||
{
|
{
|
||||||
Load();
|
Load();
|
||||||
|
@ -38,6 +40,20 @@ public class GameManager : MonoBehaviour {
|
||||||
Save();
|
Save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void OnApplicationFocus(bool pauseStatus)
|
||||||
|
{
|
||||||
|
if (pauseStatus)
|
||||||
|
{
|
||||||
|
//your app is NO LONGER in the background
|
||||||
|
Load();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
//your app is now in the background
|
||||||
|
Save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void OnApplicationQuit()
|
void OnApplicationQuit()
|
||||||
{
|
{
|
||||||
Save();
|
Save();
|
||||||
|
@ -62,7 +78,7 @@ public class GameManager : MonoBehaviour {
|
||||||
data.speed = currentSpeed;
|
data.speed = currentSpeed;
|
||||||
data.increment = currentIncrement;
|
data.increment = currentIncrement;
|
||||||
data.rotationsPerSec = rotationPerSec;
|
data.rotationsPerSec = rotationPerSec;
|
||||||
data.currentTime = DateTime.Now;
|
data.currentTime = System.DateTime.Now;
|
||||||
|
|
||||||
bf.Serialize(file, data);
|
bf.Serialize(file, data);
|
||||||
file.Close();
|
file.Close();
|
||||||
|
@ -85,9 +101,8 @@ public class GameManager : MonoBehaviour {
|
||||||
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp = data.experience;
|
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp = data.experience;
|
||||||
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement = data.requirement;
|
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement = data.requirement;
|
||||||
|
|
||||||
DateTime loadTime = DateTime.Now;
|
DateTime loadTime = System.DateTime.Now;
|
||||||
int secondsPassed = GetIdleTime(data.currentTime, loadTime);
|
int secondsPassed = GetIdleTime(data.currentTime, loadTime);
|
||||||
float radianSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed * Mathf.Deg2Rad;
|
|
||||||
float idleExp = (data.rotationsPerSec * secondsPassed) * data.increment;
|
float idleExp = (data.rotationsPerSec * secondsPassed) * data.increment;
|
||||||
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
|
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue