123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204 |
- using DataTools;
- using System;
- using UnityEngine;
- using UnityEngine.UI;
- using WebTools.Customizes.Behaviours;
- using WebTools.Currencies.Behaviours;
- using System.Collections.Generic;
- using WebTools.Reward;
- public class GigButton : MonoBehaviour
- {
- public event Action<GigButton> OnDestroyButton;
- [Header("DATAUSER")]
- [SerializeField] private DataUser dataUser;
- [SerializeField] private Text actionName;
- [SerializeField] private Text motivation;
- [SerializeField] private Image slider;
- [SerializeField] private GigRewardButton rewardButton;
- [SerializeField] private AudioClip clickSound;
- [SerializeField] private AudioClip cameraSound;
- [SerializeField] private int rewardsCount = 5;
- private DataTools.Gig currentGig;
- private DataTools.GigAction myAction;
- private CharacterAnimations characterAnimations;
- private Transform locationInWorld;
- private Vector3 position;
- private float sliderFragment;
- public DataTools.GigAction MyAction
- {
- get
- {
- return myAction;
- }
- }
- private void Start()
- {
- characterAnimations = FindObjectOfType<CharacterAnimations>();
- position = Vector3.zero;
- }
- public void Setup(DataTools.Gig currentGig, DataTools.GigAction action)
- {
- this.currentGig = currentGig;
- myAction = new DataTools.GigAction(action.EnergyCost, action.Stars, action.Tag);
- myAction.Id = action.Id;
- actionName.text = action.Id;
- Debug.Log("Action ID " + action.Id);
- motivation.text = myAction.EnergyCost.ToString();
- sliderFragment = 1f / myAction.EnergyCost;
- Debug.Log("sliderFragment " + sliderFragment);
- }
- public void SetupLocation(Location location)
- {
- Interior interior = location.GetComponent<Interior>();
- locationInWorld = interior.ActionsBtn.GetComponentInChildren<Transform>().Find(myAction.Tag);
- if(locationInWorld == null)
- {
- Debug.Log(myAction.Tag + " ActionBtn position not found in Interior, assigning random position.");
- SetRandomLocation(interior);
- }
- }
- public void SetupLocation(Transform location)
- {
- locationInWorld = location;
- }
- private void SetRandomLocation(Interior interior)
- {
- List<Transform> actionBtnTransforms = new List<Transform>(interior.ActionsBtn.GetComponentsInChildren<Transform>());
- actionBtnTransforms.Remove(interior.ActionsBtn.transform);
- if (actionBtnTransforms.Count > 0)
- {
- locationInWorld = actionBtnTransforms[UnityEngine.Random.Range(0, actionBtnTransforms.Count)];
- locationInWorld.gameObject.SetActive(false);
- }
- else
- {
- Debug.LogWarning("There's no action btn in this location.");
- }
- }
- private void LateUpdate()
- {
- if(locationInWorld != null)
- {
- position.x = locationInWorld.position.x;
- position.y = locationInWorld.position.y;
- position.z = -5;
- transform.position = position;
- }
- }
- public void Clicked()
- {
- if(dataUser.UserData.CurrencyData.Motivation > 0)
- {
- if((currentGig == null) || ((currentGig.Type == DataTools.GigType.Photoshoot) || (currentGig.Type == DataTools.GigType.FashionShow)))
- {
- if (currentGig != null)
- {
- float flashChance = 0.2f;
- float random = UnityEngine.Random.value;
- if (random < flashChance)
- {
- SoundManager.Instance.UIAudioPlay(cameraSound);
- FlashEffect.Flash();
- CatWalkFlashEffect.Flash();
- }
- }
- else
- {
- SoundManager.Instance.UIAudioPlay(clickSound);
- }
- }
- else
- {
- SoundManager.Instance.UIAudioPlay(clickSound);
- }
- PlayAnimation();
- dataUser.UserData.StarsEarned += 1;
- dataUser.UserData.CurrencyData.Motivation--;
- myAction.EnergyCost--;
- motivation.text = myAction.EnergyCost.ToString();
- slider.fillAmount -= sliderFragment;
- dataUser.UpdateUserStars();
- dataUser.UpdateUserCurrencyData();
- PanelCurrenciesBehaviour.Instance.UpdateTimer();
- if (WebTools.Phone.PanelPhoneBehaviour.Instance.isActiveAndEnabled)
- {
- WebTools.Phone.PanelPhoneBehaviour.Instance.TogglePhone();
- }
- GameGlobal.Instance.PannigLocked = false;
- CommentsManager.Instance.TryTriggerComment();
- bool t = GameGlobal.Instance.PannigLocked;
- if(myAction.EnergyCost == 0)
- {
- CreateRewards();
- if (OnDestroyButton != null)
- {
- OnDestroyButton(this);
- }
- Destroy(gameObject);
- }
- }
- else
- {
- PanelCurrenciesBehaviour.Instance.ShowPanelNotMotivation("1", "Motivation");
- PanelCurrenciesBehaviour.Instance.UpdateTimer();
- }
- }
- private void PlayAnimation()
- {
- if (characterAnimations == null)
- {
- characterAnimations = FindObjectOfType<CharacterAnimations>();
- }
- if (characterAnimations != null)
- {
- characterAnimations.PlayAnimation(myAction.Id);
- }
- }
- private void CreateRewards()
- {
- for(int i = 0; i < rewardsCount; i++)
- {
- GigRewardButton gigReward = Instantiate(rewardButton);
- gigReward.transform.position = transform.position;
- }
- }
- }
|