-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDoEvent.cs
115 lines (104 loc) · 2.62 KB
/
DoEvent.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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
using System.Collections;
using System.Collections.Generic;
using UnityEngine.Events;
using UnityEngine;
using UnityEngine.SceneManagement;
public class DoEvent : MonoBehaviour
{
[SerializeField] private UnityEvent _Event = null;
[SerializeField] private bool _OnStart = false;
[SerializeField] private bool _OnUpdate = false;
[SerializeField] private bool _OnButtonPressed = false;
private bool _AsyncLoading = false;
void Start()
{
if (_OnStart)
DoEvents();
}
void Update()
{
if (_OnUpdate)
DoEvents();
if (_OnButtonPressed)
if (Input.anyKey)
DoEvents();
}
private void DoEvents()
{
_Event.Invoke();
}
//Set Object true/false
public void SetGameobject_InActive(GameObject targetobject)
{
targetobject.SetActive(false);
}
public void SetGameobject_Active(GameObject targetobject)
{
targetobject.SetActive(true);
}
public void SetGameObject_Negative(GameObject targetobject)
{
if (targetobject.activeSelf)
targetobject.SetActive(false);
else
targetobject.SetActive(true);
}
//Load/Reload Scenes
public void LoadScene(int sceneid)
{
SceneManager.LoadScene(sceneid);
}
public void LoadScene(string scenename)
{
SceneManager.LoadScene(scenename);
}
public void ReloadScene()
{
SceneManager.LoadScene(SceneManager.GetActiveScene().buildIndex);
}
public void AsyncReloadScene()
{
if (!_AsyncLoading)
{
_AsyncLoading = true;
StartCoroutine(LoadSceneAsync(SceneManager.GetActiveScene().buildIndex));
}
}
public void AsyncLoadScene(int sceneid)
{
if (!_AsyncLoading)
{
_AsyncLoading = true;
StartCoroutine(LoadSceneAsync(sceneid));
}
}
public void AsyncLoadScene(string scenename)
{
if (!_AsyncLoading)
{
_AsyncLoading = true;
StartCoroutine(LoadSceneAsync(scenename));
}
}
private IEnumerator LoadSceneAsync(string scenename)
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(scenename);
while (!asyncLoad.isDone)
{
yield return null;
}
}
private IEnumerator LoadSceneAsync(int sceneid)
{
AsyncOperation asyncLoad = SceneManager.LoadSceneAsync(sceneid);
while (!asyncLoad.isDone)
{
yield return null;
}
}
//Quit
public void Quit()
{
Application.Quit();
}
}