improvements to notifications

Handles popup collision
-Levelups tossed to the left
-Exp values combined into one popup
--Add EXP/s or EXP/min?
This commit is contained in:
Shaun Reed 2017-09-05 21:41:56 -04:00
parent 1bcca0e925
commit 22c303d686
5 changed files with 155 additions and 23 deletions

Binary file not shown.

Binary file not shown.

View File

@ -29,7 +29,8 @@ public class ExperienceBar : MonoBehaviour {
private float previousExpRequired;
private float barMovement;
private float barPosition;
private float Increment = 10;
[SerializeField]
public float expIncrement = 10.0f;
private string notify;
// Use this for initialization
@ -41,7 +42,7 @@ public class ExperienceBar : MonoBehaviour {
// Update is called once per frame
void Update () {
fillAmount = currentExp / currentRequirement;
this.gameObject.GetComponentInChildren<Text>().text = (int)currentExp + " / " + (int)currentRequirement;
if (currentLevelText.GetComponent<Text>().text != currentLevel.ToString()){
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
@ -56,7 +57,7 @@ public class ExperienceBar : MonoBehaviour {
if (expBarSprite.fillAmount >= 1.0f)
{
LevelUp();
clicksNeeded = (currentRequirement - currentExp) / Increment;
clicksNeeded = (currentRequirement - currentExp) / expIncrement;
fillAmount = 0;
}
}
@ -64,10 +65,10 @@ public class ExperienceBar : MonoBehaviour {
public void ExpMore()
{
++clicks;
currentExp = currentExp + Increment;
currentExp = currentExp + expIncrement;
fillAmount = currentExp / currentRequirement;
notify = "+" + Increment + "EXP";
eventSystem.GetComponent<GameManager>().MakePopup(notify);
notify = "+" + expIncrement + "EXP";
eventSystem.GetComponent<GameManager>().RewardPopup(expIncrement, 1);
//Debug.Log("fillAmount = " + fillAmount);
}
@ -75,11 +76,15 @@ public class ExperienceBar : MonoBehaviour {
public void LevelUp()
{
++currentLevel;
expIncrement += 10;
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
previousExpRequired = currentRequirement;
currentExp -= previousExpRequired;
currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RaiseRotationSpeed();
notify = "Level " + currentLevel + "!";
eventSystem.GetComponent<GameManager>().RewardPopup(currentLevel, 2);
}
public void ResetExp()
@ -88,17 +93,24 @@ public class ExperienceBar : MonoBehaviour {
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
currentExp = 0;
fillAmount = 0;
expIncrement = 10.0f;
currentRequirement = 100;
clicksNeeded = 10;
clicks = 0;
notify = "EXP Reset";
eventSystem.GetComponent<GameManager>().MakeStringPopup(notify, 1);
}
public void ExpLess()
{
--clicks;
currentExp = currentExp - Increment;
currentExp = currentExp - expIncrement;
fillAmount = (currentExp / currentRequirement);
Debug.Log("fillAmount = " + fillAmount);
notify = "-" + expIncrement + "EXP";
eventSystem.GetComponent<GameManager>().RewardPopup(-expIncrement, 1);
}
public float GetExperience()

View File

@ -18,7 +18,8 @@ public class GameManager : MonoBehaviour {
public float experience;
public float requirement;
public float speed;
public float increment;
public float speedIncrement;
public float expIncrement;
public float rotationsPerSec;
public DateTime currentTime;
@ -61,13 +62,15 @@ public class GameManager : MonoBehaviour {
float rotationPerSec = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().rotationPerSec;
float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed;
float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
float currentExpIncrement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().expIncrement;
PlayerData data = new PlayerData();
data.level = currentLevel;
data.experience = currentExp;
data.requirement = currentRequirement;
data.speed = currentSpeed;
data.increment = currentIncrement;
data.speedIncrement = currentIncrement;
data.expIncrement = currentExpIncrement;
data.rotationsPerSec = rotationPerSec;
data.currentTime = System.DateTime.Now;
@ -87,20 +90,20 @@ public class GameManager : MonoBehaviour {
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().rotationPerSec = data.rotationsPerSec;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = data.speed;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement = data.increment;
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement = data.speedIncrement;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().expIncrement = data.expIncrement;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentLevel = data.level;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp = data.experience;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentRequirement = data.requirement;
DateTime loadTime = System.DateTime.Now;
int secondsPassed = GetIdleTime(data.currentTime, loadTime);
idleExp = (data.rotationsPerSec * secondsPassed) * data.increment;
idleExp = (data.rotationsPerSec * secondsPassed) * data.expIncrement;
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
if (idleExp >= 0.0f)
{
string notification = ("+" + idleExp + "EXP");
MakePopup(notification);
RewardPopup(idleExp, 1);
}
Debug.Log("Loaded");
@ -134,16 +137,31 @@ public class GameManager : MonoBehaviour {
return secondsPassed;
}
public void MakePopup(string content)
public int notificationType;
public float noteValue;
/*
* type 1 = exp
* type 2 = level
*
*
*
*
*/
public void RewardPopup(float value, int type)
{
notify = content;
notificationType = type;
noteValue = value;
Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform );
Debug.Log("Popup Created");
}
public string GetNotify()
public void MakeStringPopup(string content, int type)
{
return notify;
notify = content;
notificationType = type;
Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform);
Debug.Log("Popup Created");
}
}

View File

@ -6,20 +6,33 @@ using UnityEngine.UI;
public class PopupNotification : MonoBehaviour {
public bool move = false;
public bool active = false;
public Vector3 origin;
public float timer = 0.0f;
public float maxTimer = 3.0f;
public float speed = 50.0f;
public string localNotify;
public int notificationType;
public float localValue;
// Use this for initialization
void OnEnable ()
{
active = true;
//Get & set random rotation
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();
//Debug.Log("Rotation set to :" + randomRotation);
//
notificationType = GameObject.Find("EventSystem").GetComponent<GameManager>().notificationType;
//localNotify = GameObject.Find("EventSystem").GetComponent<GameManager>().notify;
localValue = GameObject.Find("EventSystem").GetComponent<GameManager>().noteValue;
CheckNotificationType();
}
// Update is called once per frame
@ -28,15 +41,70 @@ public class PopupNotification : MonoBehaviour {
timer += 0.02f;
this.gameObject.transform.Translate(new Vector3(0, 50f * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
if (timer >= 3)
if (timer >= maxTimer)
{
active = false;
timer = 0.0f;
Destroy(this.gameObject);
}
if(move == true)
{
this.gameObject.transform.Translate(new Vector3(-5.0f, speed * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
}
else
{
this.gameObject.transform.Translate(new Vector3(0, speed * Time.deltaTime, 0));
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
}
}
void OnCollisionEnter (Collision col)
{
if(col.gameObject.GetComponent<PopupNotification>().notificationType == 1 && notificationType == 1)
{
//if both colliding popus are EXP related
if ((maxTimer - timer) > (col.gameObject.GetComponent<PopupNotification>().maxTimer - col.gameObject.GetComponent<PopupNotification>().timer))
{
//If this Popup has more time left than colliding popup
localValue += col.gameObject.GetComponent<PopupNotification>().localValue;
maxTimer += 0.5f;
CheckNotificationType();
Destroy(col.gameObject);
}//else do nothing, let other popup handle it
}
else if (col.gameObject.GetComponent<PopupNotification>().notificationType == 2 && notificationType == 2)
{
//if both colliding popus are level related
if (localValue > col.gameObject.GetComponent<PopupNotification>().localValue)
{
//If this popup is of higher level
Destroy(col.gameObject);
}//Destroy collider, show most recent level
maxTimer += 1.0f;
CheckNotificationType();
}
else if (col.gameObject.GetComponent<PopupNotification>().notificationType != notificationType)
{
//if both colliding popus are not related
if (notificationType == 2)
{
move = true;
}//else do nothing, let other popup handle it
}
}
public double GetRandomNumber(double min, double max)
@ -45,5 +113,39 @@ public class PopupNotification : MonoBehaviour {
return random.NextDouble() * (max - min) + min;
}
public void CheckNotificationType()
{
//If notification is of type EXP
if (notificationType == 1)
{
if (localValue == 0)
{
Debug.Log("Null EXP value, popup discarded :" + localValue);
Destroy(this.gameObject);
}
if (localValue > 0)
{
//If adding EXP
localNotify = "+" + localValue + "EXP";
}
else if (localValue < 0)
{
//If subtracting EXP
localNotify = localValue + "EXP";
}
}
else if (notificationType == 2)
{
//If notification is of type Level Gained
localNotify = "Level " + localValue + "!";
}
this.gameObject.GetComponentInChildren<Text>().text = localNotify;
}
}