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:
parent
1bcca0e925
commit
22c303d686
Binary file not shown.
Binary file not shown.
|
@ -29,7 +29,8 @@ public class ExperienceBar : MonoBehaviour {
|
||||||
private float previousExpRequired;
|
private float previousExpRequired;
|
||||||
private float barMovement;
|
private float barMovement;
|
||||||
private float barPosition;
|
private float barPosition;
|
||||||
private float Increment = 10;
|
[SerializeField]
|
||||||
|
public float expIncrement = 10.0f;
|
||||||
private string notify;
|
private string notify;
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
|
@ -41,7 +42,7 @@ public class ExperienceBar : MonoBehaviour {
|
||||||
// Update is called once per frame
|
// Update is called once per frame
|
||||||
void Update () {
|
void Update () {
|
||||||
fillAmount = currentExp / currentRequirement;
|
fillAmount = currentExp / currentRequirement;
|
||||||
|
this.gameObject.GetComponentInChildren<Text>().text = (int)currentExp + " / " + (int)currentRequirement;
|
||||||
|
|
||||||
if (currentLevelText.GetComponent<Text>().text != currentLevel.ToString()){
|
if (currentLevelText.GetComponent<Text>().text != currentLevel.ToString()){
|
||||||
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)
|
if (expBarSprite.fillAmount >= 1.0f)
|
||||||
{
|
{
|
||||||
LevelUp();
|
LevelUp();
|
||||||
clicksNeeded = (currentRequirement - currentExp) / Increment;
|
clicksNeeded = (currentRequirement - currentExp) / expIncrement;
|
||||||
fillAmount = 0;
|
fillAmount = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -64,10 +65,10 @@ public class ExperienceBar : MonoBehaviour {
|
||||||
public void ExpMore()
|
public void ExpMore()
|
||||||
{
|
{
|
||||||
++clicks;
|
++clicks;
|
||||||
currentExp = currentExp + Increment;
|
currentExp = currentExp + expIncrement;
|
||||||
fillAmount = currentExp / currentRequirement;
|
fillAmount = currentExp / currentRequirement;
|
||||||
notify = "+" + Increment + "EXP";
|
notify = "+" + expIncrement + "EXP";
|
||||||
eventSystem.GetComponent<GameManager>().MakePopup(notify);
|
eventSystem.GetComponent<GameManager>().RewardPopup(expIncrement, 1);
|
||||||
|
|
||||||
//Debug.Log("fillAmount = " + fillAmount);
|
//Debug.Log("fillAmount = " + fillAmount);
|
||||||
}
|
}
|
||||||
|
@ -75,11 +76,15 @@ public class ExperienceBar : MonoBehaviour {
|
||||||
public void LevelUp()
|
public void LevelUp()
|
||||||
{
|
{
|
||||||
++currentLevel;
|
++currentLevel;
|
||||||
|
expIncrement += 10;
|
||||||
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
||||||
previousExpRequired = currentRequirement;
|
previousExpRequired = currentRequirement;
|
||||||
currentExp -= previousExpRequired;
|
currentExp -= previousExpRequired;
|
||||||
currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
|
currentRequirement = Mathf.Pow(currentRequirement, 1.05f);
|
||||||
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RaiseRotationSpeed();
|
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().RaiseRotationSpeed();
|
||||||
|
notify = "Level " + currentLevel + "!";
|
||||||
|
eventSystem.GetComponent<GameManager>().RewardPopup(currentLevel, 2);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ResetExp()
|
public void ResetExp()
|
||||||
|
@ -88,17 +93,24 @@ public class ExperienceBar : MonoBehaviour {
|
||||||
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
currentLevelText.GetComponent<Text>().text = currentLevel.ToString();
|
||||||
currentExp = 0;
|
currentExp = 0;
|
||||||
fillAmount = 0;
|
fillAmount = 0;
|
||||||
|
expIncrement = 10.0f;
|
||||||
currentRequirement = 100;
|
currentRequirement = 100;
|
||||||
clicksNeeded = 10;
|
clicksNeeded = 10;
|
||||||
clicks = 0;
|
clicks = 0;
|
||||||
|
notify = "EXP Reset";
|
||||||
|
eventSystem.GetComponent<GameManager>().MakeStringPopup(notify, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ExpLess()
|
public void ExpLess()
|
||||||
{
|
{
|
||||||
--clicks;
|
--clicks;
|
||||||
currentExp = currentExp - Increment;
|
currentExp = currentExp - expIncrement;
|
||||||
fillAmount = (currentExp / currentRequirement);
|
fillAmount = (currentExp / currentRequirement);
|
||||||
Debug.Log("fillAmount = " + fillAmount);
|
Debug.Log("fillAmount = " + fillAmount);
|
||||||
|
notify = "-" + expIncrement + "EXP";
|
||||||
|
eventSystem.GetComponent<GameManager>().RewardPopup(-expIncrement, 1);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public float GetExperience()
|
public float GetExperience()
|
||||||
|
|
|
@ -18,7 +18,8 @@ public class GameManager : MonoBehaviour {
|
||||||
public float experience;
|
public float experience;
|
||||||
public float requirement;
|
public float requirement;
|
||||||
public float speed;
|
public float speed;
|
||||||
public float increment;
|
public float speedIncrement;
|
||||||
|
public float expIncrement;
|
||||||
public float rotationsPerSec;
|
public float rotationsPerSec;
|
||||||
public DateTime currentTime;
|
public DateTime currentTime;
|
||||||
|
|
||||||
|
@ -61,13 +62,15 @@ public class GameManager : MonoBehaviour {
|
||||||
float rotationPerSec = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().rotationPerSec;
|
float rotationPerSec = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().rotationPerSec;
|
||||||
float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed;
|
float currentSpeed = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed;
|
||||||
float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
|
float currentIncrement = GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentIncrement;
|
||||||
|
float currentExpIncrement = GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().expIncrement;
|
||||||
|
|
||||||
PlayerData data = new PlayerData();
|
PlayerData data = new PlayerData();
|
||||||
data.level = currentLevel;
|
data.level = currentLevel;
|
||||||
data.experience = currentExp;
|
data.experience = currentExp;
|
||||||
data.requirement = currentRequirement;
|
data.requirement = currentRequirement;
|
||||||
data.speed = currentSpeed;
|
data.speed = currentSpeed;
|
||||||
data.increment = currentIncrement;
|
data.speedIncrement = currentIncrement;
|
||||||
|
data.expIncrement = currentExpIncrement;
|
||||||
data.rotationsPerSec = rotationPerSec;
|
data.rotationsPerSec = rotationPerSec;
|
||||||
data.currentTime = System.DateTime.Now;
|
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>().rotationPerSec = data.rotationsPerSec;
|
||||||
GameObject.FindGameObjectWithTag("Player").GetComponent<SpinningCube>().currentSpeed = data.speed;
|
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>().currentLevel = data.level;
|
||||||
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 = System.DateTime.Now;
|
DateTime loadTime = System.DateTime.Now;
|
||||||
int secondsPassed = GetIdleTime(data.currentTime, loadTime);
|
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;
|
GameObject.FindGameObjectWithTag("ExpGained").GetComponent<ExperienceBar>().currentExp += idleExp;
|
||||||
|
|
||||||
if (idleExp >= 0.0f)
|
if (idleExp >= 0.0f)
|
||||||
{
|
{
|
||||||
string notification = ("+" + idleExp + "EXP");
|
RewardPopup(idleExp, 1);
|
||||||
MakePopup(notification);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Debug.Log("Loaded");
|
Debug.Log("Loaded");
|
||||||
|
@ -134,16 +137,31 @@ public class GameManager : MonoBehaviour {
|
||||||
return secondsPassed;
|
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 );
|
Instantiate(popup, popupSpawn.transform.position, popupSpawn.transform.rotation, GameObject.Find("Notification Panel").gameObject.transform );
|
||||||
Debug.Log("Popup Created");
|
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");
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,20 +6,33 @@ using UnityEngine.UI;
|
||||||
|
|
||||||
public class PopupNotification : MonoBehaviour {
|
public class PopupNotification : MonoBehaviour {
|
||||||
|
|
||||||
|
public bool move = false;
|
||||||
public bool active = false;
|
public bool active = false;
|
||||||
public Vector3 origin;
|
public Vector3 origin;
|
||||||
public float timer = 0.0f;
|
public float timer = 0.0f;
|
||||||
|
public float maxTimer = 3.0f;
|
||||||
|
public float speed = 50.0f;
|
||||||
public string localNotify;
|
public string localNotify;
|
||||||
|
public int notificationType;
|
||||||
|
public float localValue;
|
||||||
|
|
||||||
|
|
||||||
// Use this for initialization
|
// Use this for initialization
|
||||||
void OnEnable ()
|
void OnEnable ()
|
||||||
{
|
{
|
||||||
active = true;
|
active = true;
|
||||||
|
|
||||||
|
//Get & set random rotation
|
||||||
double randomRotation = GetRandomNumber(-4.0, 4.0);
|
double randomRotation = GetRandomNumber(-4.0, 4.0);
|
||||||
transform.Rotate(0.0f, 0.0f, (float)randomRotation);
|
transform.Rotate(0.0f, 0.0f, (float)randomRotation);
|
||||||
Debug.Log("Rotation set to :" + randomRotation);
|
//Debug.Log("Rotation set to :" + randomRotation);
|
||||||
origin = this.transform.localPosition;
|
|
||||||
localNotify = GameObject.Find("EventSystem").GetComponent<GameManager>().GetNotify();
|
//
|
||||||
|
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
|
// Update is called once per frame
|
||||||
|
@ -28,15 +41,70 @@ public class PopupNotification : MonoBehaviour {
|
||||||
|
|
||||||
timer += 0.02f;
|
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;
|
active = false;
|
||||||
timer = 0.0f;
|
timer = 0.0f;
|
||||||
|
|
||||||
Destroy(this.gameObject);
|
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)
|
public double GetRandomNumber(double min, double max)
|
||||||
|
@ -45,5 +113,39 @@ public class PopupNotification : MonoBehaviour {
|
||||||
return random.NextDouble() * (max - min) + min;
|
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue