-
Notifications
You must be signed in to change notification settings - Fork 0
/
Rating.cs
91 lines (77 loc) · 2.47 KB
/
Rating.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;
public class Rating : MonoBehaviour
{
[Header("Screen")]
public GameObject ratingScreen;
[Header("UI Buttons")]
public GameObject levelSelectButton;
public GameObject restartButton;
public GameObject pauseButton;
public GameObject helpButton;
[Header("Colors")]
public Color normalColor;
public Color blackColor;
[HideInInspector]
public static bool isShown;
private const string showNumberKey = "RatingShowNumber";
private const string ratedKey = "Rated";
private float timer = 2.0f;
private Image canvasImage;
private AudioSource audioSource;
private void Start()
{
canvasImage = GameObject.Find("Canvas").GetComponent<Image>();
audioSource = GameObject.Find("Music Management").GetComponent<AudioSource>();
}
private void Update()
{
if (ratingScreen != null)
{
if (timer <= 0.0f && !ratingScreen.activeSelf)
{
if (SceneManager.GetActiveScene().buildIndex % PlayerPrefs.GetInt(showNumberKey, 10) == 0 && PlayerPrefs.GetInt(ratedKey, 0) == 0)
{
SetRatingSettings(true, true, true, blackColor, false, false, false, false, 0.25f, true);
}
}
else
{
timer -= Time.deltaTime;
}
}
}
public void RateLater()
{
SetRatingSettings(false, false, false, normalColor, true, true, true, true, 1f, false);
PlayerPrefs.SetInt(showNumberKey, PlayerPrefs.GetInt(showNumberKey) + 10);
}
public void GoToGamePage()
{
if (ratingScreen != null)
{
SetRatingSettings(false, false, false, normalColor, true, true, true, true, 1f, false);
}
PlayerPrefs.SetInt(ratedKey, 1);
#if UNITY_ANDROID
Application.OpenURL("market://details?id=" + Application.identifier);
#elif UNITY_IPHONE
Application.OpenURL("itms-apps://itunes.apple.com/app/" + Application.identifier);
#endif
}
private void SetRatingSettings(bool _isShown, bool _ratingScreen, bool _canvasImageEnabled, Color _canvasImage, bool _levelSelectButton, bool _restartButton, bool _pauseButton, bool _helpButton, float timeScale, bool decreaseVolume)
{
Time.timeScale = timeScale;
isShown = _isShown;
ratingScreen.SetActive(_ratingScreen);
canvasImage.enabled = _canvasImageEnabled;
canvasImage.color = _canvasImage;
levelSelectButton.SetActive(_levelSelectButton);
restartButton.SetActive(_restartButton);
pauseButton.SetActive(_pauseButton);
if (helpButton != null)
helpButton.SetActive(_helpButton);
audioSource.volume = decreaseVolume ? 0.25f : 1.0f;
}
}