-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuManager.cs
More file actions
70 lines (56 loc) · 2.23 KB
/
MenuManager.cs
File metadata and controls
70 lines (56 loc) · 2.23 KB
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
using Unity.VisualScripting;
using UnityEngine;
using UnityEngine.UI;
public class MenuManager : MonoBehaviour
{
[SerializeField] private LeanTweenType easeType = LeanTweenType.easeInOutCubic;
[SerializeField] private float leaveAnimDuration = 0.5f;
[SerializeField] private float offsetZ = 10;
[SerializeField] private Button factButton;
private GameObject factPanel;
[SerializeField] private Button settingsButton;
[SerializeField] private GameObject settingsPanel;
[SerializeField] private Button totemShopButton;
[SerializeField] private GameObject totemShopPanel;
[SerializeField] private GameObject[] decorationLeaves;
private BalanceManager balance;
private void Start()
{
factPanel = FindObjectOfType<FactManager>().gameObject;
balance = FindObjectOfType<BalanceManager>();
AnimateLeaves();
factButton.onClick.AddListener(() => ProcessFactPurchase(10f));
settingsButton.onClick.AddListener(() => UIManager.Instance.PopUpAnim(settingsPanel, Vector3.one));
totemShopButton.onClick.AddListener(() => UIManager.Instance.PopUpAnim(totemShopPanel, Vector3.one));
}
private void AnimateLeaves()
{
foreach(var leave in decorationLeaves)
{
LeanTween.rotateZ(leave, leave.transform.rotation.z + offsetZ, leaveAnimDuration).setEase(easeType).setLoopPingPong();
}
}
public void QuitButton()
{
Application.Quit();
}
private void ProcessFactPurchase(float factPrice)
{
if (balance == null) { Debug.Log("BalanceManager is null"); return; }
if(balance.isSufficient(-factPrice))
{
balance.AddBalance(-factPrice); // price of the fact
UIManager.Instance.PopUpAnim(factPanel, Vector3.one);
factPanel.GetComponent<FactManager>().SetUpFact(); // Generate new fact
}
else
{
UIManager.Instance.PopUpAnim(balance.insufficientBalancePopUp, Vector3.one);
Debug.Log("Insufficient balance");
}
}
public void OpenLevelSelectPanel(GameObject panel)
{
UIManager.Instance.PopUpAnim(panel, Vector3.one);
}
}