123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174 |
- using System.Collections;
- using System.Collections.Generic;
- using UnityEngine;
- using DataTools;
- using WebTools.Currencies.Behaviours;
- namespace WebTools.Reward
- {
- public enum RewardType
- {
- Dollar,
- Motivation,
- Glam,
- Experience
- }
- public class RewardBase : MonoBehaviour
- {
- [Header("DATAUSER")]
- [SerializeField]
- private DataUser dataUser;
- [SerializeField]
- private Rigidbody2D mRigidBody;
- [SerializeField]
- private SpriteRenderer sprite;
- [SerializeField]
- private List<int> spriteChangeValues;
- [SerializeField]
- private List<Sprite> glam;
- [SerializeField]
- protected int glamValue = 1;
- [SerializeField]
- private List<Sprite> dollar;
- [SerializeField]
- protected int dollarValue = 2;
- [SerializeField]
- private List<Sprite> motivation;
- [SerializeField]
- protected int motivationValue = 2;
- [SerializeField]
- private Sprite experience;
- [SerializeField]
- protected int experienceValue = 2;
- [SerializeField]
- private float launchPower = 1;
- [SerializeField]
- private float lifeSpan = 3;
- [SerializeField]
- private RewardText rewardText;
- [SerializeField]
- private AudioSource touchSound;
- [SerializeField]
- private GameObject explosionPrefab;
- private DataTools.Currency currency;
- private bool isRewardClaimed;
- private Vector3 scale;
- private RewardType rewardType;
- private int rewardValue;
- private int GetSpriteIndexByValue(int value)
- {
- if(value <= spriteChangeValues[0])
- return 0;
- else if(value <= spriteChangeValues[1])
- return 1;
- else if(value <= spriteChangeValues[2])
- return 2;
- else
- return 3;
- }
- protected virtual void Start()
- {
- GameObject canvas = GameObject.Find("Canvas");
- transform.SetParent(canvas.transform, true);
- transform.localScale = Vector3.one * 50.0f;
- scale = transform.localScale;
- Launch();
- }
- protected void Launch()
- {
- //mRigidBody.AddForce(new Vector2(Random.Range(-10f * launchPower, 10f * launchPower), launchPower));
- mRigidBody.AddForce(new Vector2(Random.Range(-3.0f * launchPower, 3.0f * launchPower), launchPower * 5.0f));
- }
- protected void SetGlam()
- {
- currency = new DataTools.Currency(glamValue, 0, 0, 0);
- sprite.sprite = glam[GetSpriteIndexByValue(glamValue)];
- rewardType = RewardType.Glam;
- rewardValue = glamValue;
- }
- protected void SetDollar()
- {
- currency = new DataTools.Currency(0, 0, dollarValue, 0);
- sprite.sprite = dollar[GetSpriteIndexByValue(dollarValue)];
- rewardType = RewardType.Dollar;
- rewardValue = dollarValue;
- }
- protected void SetMotivation()
- {
- currency = new DataTools.Currency(0, 0, 0, motivationValue);
- sprite.sprite = motivation[GetSpriteIndexByValue(motivationValue)];
- rewardType = RewardType.Motivation;
- rewardValue = motivationValue;
- }
- protected void SetExperience()
- {
- currency = new DataTools.Currency(0, experienceValue, 0, 0);
- sprite.sprite = experience;
- rewardType = RewardType.Experience;
- rewardValue = experienceValue;
- }
- protected virtual void Update()
- {
- if (!isRewardClaimed)
- {
- lifeSpan -= Time.deltaTime;
- if (lifeSpan <= 0)
- GetReward();
- }
- }
- private void GetReward()
- {
- if (!isRewardClaimed)
- {
- dataUser.UserData.CurrencyData.AddReward(currency.Glam, currency.Experience, currency.Dollars, currency.Motivation);
- dataUser.UpdateUserCurrencyData();
- PanelCurrenciesBehaviour.Instance.UpdateTimer();
- }
- isRewardClaimed = true;
- GameObject explosion = Instantiate(explosionPrefab, transform.position, transform.rotation);
- rewardText.Show(rewardValue, rewardType);
- touchSound.Play();
- Destroy(explosion,0.5f);
- Destroy(gameObject);
- }
- private void OnMouseUp()
- {
- GetReward();
- }
- }
- }
|