Added basic notification system

-Works with minimal calls to SendNotification(), infinite loop possible
on multiple calls
-Add to MoreExp()
--Add case for multiple notifications of same type combining value
--If notification timer > maxTime
---expRate = expNotifyValue / secondsPassed
---Display Exp/s instead of continuously growing value
This commit is contained in:
Shaun Reed 2017-09-04 19:53:18 -04:00
parent cc86eabeef
commit 33664d2735
5 changed files with 204 additions and 2 deletions

Binary file not shown.

View File

@ -60,7 +60,7 @@ public class ExperienceBar : MonoBehaviour {
++clicks; ++clicks;
currentExp = currentExp + Increment; currentExp = currentExp + Increment;
fillAmount = currentExp / currentRequirement; fillAmount = currentExp / currentRequirement;
Debug.Log("fillAmount = " + fillAmount); //Debug.Log("fillAmount = " + fillAmount);
} }
public void LevelUp() public void LevelUp()

View File

@ -1,6 +1,7 @@
using System.Collections; using System.Collections;
using System.Collections.Generic; using System.Collections.Generic;
using UnityEngine; using UnityEngine;
using UnityEngine.UI;
using System; using System;
using System.IO; using System.IO;
using System.Runtime.Serialization.Formatters.Binary; using System.Runtime.Serialization.Formatters.Binary;
@ -23,6 +24,19 @@ public class GameManager : MonoBehaviour {
} }
public string notify;
public bool wait;
public bool activeOne;
public bool activeTwo;
public bool activeThree;
public bool activeFour;
public float idleExp;
public GameObject popupOne;
public GameObject popupTwo;
public GameObject popupThree;
public GameObject popupFour;
public float timer;
// Update is called once per frame // Update is called once per frame
void Update () { void Update () {
@ -59,6 +73,28 @@ public class GameManager : MonoBehaviour {
Save(); Save();
} }
public void Start()
{
popupOne.SetActive(false);
popupTwo.SetActive(false);
popupThree.SetActive(false);
popupFour.SetActive(false);
}
void FixedUpdate()
{
UpdatePopups();
timer += 0.02f;
if(timer > 9999.0f)
{
timer = 0.0f;
}
}
public void Save() public void Save()
{ {
BinaryFormatter bf = new BinaryFormatter(); BinaryFormatter bf = new BinaryFormatter();
@ -103,9 +139,15 @@ public class GameManager : MonoBehaviour {
DateTime loadTime = System.DateTime.Now; DateTime loadTime = System.DateTime.Now;
int secondsPassed = GetIdleTime(data.currentTime, loadTime); int secondsPassed = GetIdleTime(data.currentTime, loadTime);
float idleExp = (data.rotationsPerSec * secondsPassed) * data.increment; idleExp = (data.rotationsPerSec * secondsPassed) * data.increment;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp; GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
if (idleExp >= 0.0f)
{
string notification = ("+" + idleExp + "EXP");
SendNotification(notification);
}
Debug.Log("Loaded"); Debug.Log("Loaded");
Debug.Log("idleExp: " + idleExp); Debug.Log("idleExp: " + idleExp);
} }
@ -137,4 +179,114 @@ public class GameManager : MonoBehaviour {
return secondsPassed; return secondsPassed;
} }
public void UpdatePopups()
{
if (GameObject.Find("Pop-up Panel 1") == null)
{
activeOne = false;
}
else
{
activeOne = true;
}
if (GameObject.Find("Pop-up Panel 2") == null)
{
activeTwo = false;
}
else
{
activeTwo = true;
}
if (GameObject.Find("Pop-up Panel 3") == null)
{
activeThree = false;
}
else
{
activeThree = true;
}
if (GameObject.Find("Pop-up Panel 4") == null)
{
activeFour = false;
}else
{
activeFour = true;
}
}
public void SendNotification(string notification)
{
/*
List<GameObject> popups = new List<GameObject>();
GameObject[] allPopups = GameObject.Find("Notification Panel").GetComponentsInChildren<GameObject>(true);
foreach (GameObject obj in allPopups)
{
popups.Add(obj.GetComponent<GameObject>());
}
*/
//Debug.Log("Number of Popups: " + popups.Count);
for (;;)
{
Debug.Log("For1");
if (wait == true)
{
Debug.Log("For1.1");
continue;
}else
{
Debug.Log("For1.1");
notify = notification;
break;
}
}
for (;;)
{
Debug.Log("For2");
if (activeOne == false)
{
popupOne.SetActive(true);
wait = false;
break;
} else if (activeTwo == false)
{
popupTwo.SetActive(true);
wait = false;
break;
} else if (activeThree == false)
{
popupThree.SetActive(true);
wait = false;
break;
} else if (activeFour == false)
{
popupFour.SetActive(true);
wait = false;
break;
} else
{
wait = true;
continue;
}
}
}
public string GetNotify()
{
return notify;
}
} }

View File

@ -0,0 +1,38 @@
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class PopupNotification : MonoBehaviour {
public bool active = false;
public Vector3 origin;
public float timer = 0.0f;
public string localNotify;
// Use this for initialization
void OnEnable () {
active = true;
origin = this.transform.localPosition;
localNotify = GameObject.Find("EventSystem").GetComponent<GameManager>().GetNotify();
}
// Update is called once per frame
void FixedUpdate () {
timer += 0.02f;
this.gameObject.transform.Translate(new Vector3(0, 10f * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
if(timer >= 3)
{
this.gameObject.SetActive(false);
active = false;
timer = 0.0f;
this.gameObject.transform.localPosition = origin;
}
}
}

View File

@ -0,0 +1,12 @@
fileFormatVersion: 2
guid: f65f56ebba8d5fd49ac926af557e92d7
timeCreated: 1504554538
licenseType: Free
MonoImporter:
serializedVersion: 2
defaultReferences: []
executionOrder: 0
icon: {instanceID: 0}
userData:
assetBundleName:
assetBundleVariant: