miepzerino
2023-12-19 61930cf21d3eb145df11ea2b719ae7be66c56d24
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
92
93
using System;
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.SceneManagement;
 
public class PauseMenu : MonoBehaviour
{
    public static bool GameIsPaused = false;
 
    public GameObject pauseMenuUI;
    public GameObject settingsMenuUI;
    public GameObject pausePanel;
    public GameObject saveGameText;
    Animator animator;
 
    private void Awake()
    {
        animator = GetComponent<Animator>();
        GameIsPaused = false;
    }
 
    public void OnEscapedPressed(InputAction.CallbackContext context)
    {
        if (context.started)
        {
            ResumeOrPauseGame(GameIsPaused);
        }
    }
 
    private void ResumeOrPauseGame(bool resume)
    {
        if (resume)
        {
            Resume();
        }
        else
        {
            Pause();
        }
    }
 
    private void Resume()
    {
        // TODO make it dynamic (whichever UI is activ set it to falsen when unpaused)
        pausePanel.SetActive(false);
        Time.timeScale = 1f;
        GameIsPaused = false;
    }
 
    private void Pause()
    {
        settingsMenuUI.SetActive(false);
        pauseMenuUI.SetActive(true);
        pausePanel.SetActive(true);
        Time.timeScale = 0f;
        GameIsPaused = true;
    }
    public void OnResumeClicked()
    {
        Resume();
    }
 
    public void OnGameSaveClicked()
    {
        PlayerController playerController = GameObject.Find("Player").GetComponent<PlayerController>();
        SaveSystem.SavePlayer(playerController);
        animator.SetTrigger("GameSaved");
    }
 
    public void OnSettingsSaveClicked()
    {
        animator.SetTrigger("GameSettingsSaved");
    }
 
    public void OnGamedLoaded()
    {
        animator.SetTrigger("GameLoaded");
    }
 
    public void OnMenuClicked()
    {
 
    }
 
    public void OnExitClicked()
    {
        Resume();
        SceneManager.LoadScene("MainMenu");
    }
 
}