Reworked (bad)notification system

- Reduced huge amount of fluff logic, loops, conditionals
- Fixed infinite loop within 4+ calls to SendNotification()
-- Replaced with new function MakePopup(string contents)
-- Spawns a prefab, can call as much as you want (overlapping issue)
-Add combining of colliding Popups with similar contents (exp)
-- Add a tag passed into MakePopup() as argument used to combine similar
values ( and increase time left to Destroy(), raise speed of transform
to move away from other popups)
- Popups rotate within a range of -4 to 4 for trendy not-perfect look
*shrug*
This commit is contained in:
Shaun Reed 2017-09-05 18:12:08 -04:00
parent 33664d2735
commit 1bcca0e925
16 changed files with 93 additions and 162 deletions

Binary file not shown.

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 28a82baf8aadfa844a76fc5dd71094f8
timeCreated: 1504643709
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 10e2d344b53a4c64b854b8b3904b369e
folderAsset: yes
timeCreated: 1504644496
licenseType: Free
DefaultImporter:
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: e37a904fb373d0244a3345167006b83d
timeCreated: 1504644537
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 4cf0708b040fc2c4aa29a200bec6056f
timeCreated: 1504644516
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: acc04bbf04d68f24fa01177bb3ed86b8
timeCreated: 1504644530
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -0,0 +1,9 @@
fileFormatVersion: 2
guid: 3296a1925269b9c4699c0f4de17d0366
timeCreated: 1504644532
licenseType: Free
NativeFormatImporter:
mainObjectFileID: 100100000
userData:
assetBundleName:
assetBundleVariant:

Binary file not shown.

View File

@ -20,15 +20,21 @@ public class ExperienceBar : MonoBehaviour {
private float lerpSpeed;
[SerializeField]
private int clicks;
[SerializeField]
private GameObject eventSystem;
private float clicksNeeded = 10;
private float previousExpRequired;
private float barMovement;
private float barPosition;
private float Increment = 10;
private string notify;
// Use this for initialization
void Start () {
eventSystem = GameObject.Find("EventSystem");
fillAmount = currentExp / currentRequirement;
}
@ -60,6 +66,9 @@ public class ExperienceBar : MonoBehaviour {
++clicks;
currentExp = currentExp + Increment;
fillAmount = currentExp / currentRequirement;
notify = "+" + Increment + "EXP";
eventSystem.GetComponent<GameManager>().MakePopup(notify);
//Debug.Log("fillAmount = " + fillAmount);
}

View File

@ -24,38 +24,15 @@ 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
void Update () {
}
void OnEnable()
{
Load();
}
void OnApplicationPause()
{
Save();
}
public GameObject popup;
public GameObject popupSpawn;
public string notify;
void OnApplicationFocus(bool pauseStatus)
{
Debug.Log("OnApplicationFocused");
if (pauseStatus)
{
//your app is NO LONGER in the background
@ -73,28 +50,6 @@ public class GameManager : MonoBehaviour {
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()
{
BinaryFormatter bf = new BinaryFormatter();
@ -145,7 +100,7 @@ public class GameManager : MonoBehaviour {
if (idleExp >= 0.0f)
{
string notification = ("+" + idleExp + "EXP");
SendNotification(notification);
MakePopup(notification);
}
Debug.Log("Loaded");
@ -179,109 +134,11 @@ public class GameManager : MonoBehaviour {
return secondsPassed;
}
public void UpdatePopups()
public void MakePopup(string content)
{
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;
}
}
notify = content;
Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform );
Debug.Log("Popup Created");
}
public string GetNotify()

View File

@ -12,27 +12,38 @@ public class PopupNotification : MonoBehaviour {
public string localNotify;
// Use this for initialization
void OnEnable () {
void OnEnable ()
{
active = true;
double randomRotation = GetRandomNumber(-4.0, 4.0);
transform.Rotate(0.0f, 0.0f, (float)randomRotation);
Debug.Log("Rotation set to :" + randomRotation);
origin = this.transform.localPosition;
localNotify = GameObject.Find("EventSystem").GetComponent<GameManager>().GetNotify();
}
// Update is called once per frame
void FixedUpdate () {
// Update is called once per frame
void FixedUpdate()
{
timer += 0.02f;
this.gameObject.transform.Translate(new Vector3(0, 10f * Time.deltaTime, 0));
this.gameObject.transform.Translate(new Vector3(0, 50f * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
if(timer >= 3)
if (timer >= 3)
{
this.gameObject.SetActive(false);
active = false;
timer = 0.0f;
this.gameObject.transform.localPosition = origin;
Destroy(this.gameObject);
}
}
public double GetRandomNumber(double min, double max)
{
System.Random random = new System.Random();
return random.NextDouble() * (max - min) + min;
}
}

Binary file not shown.