-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCanvasManager.cs
More file actions
111 lines (90 loc) · 2.9 KB
/
CanvasManager.cs
File metadata and controls
111 lines (90 loc) · 2.9 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
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
using UnityEngine;
using UnityEngine.UI;
using System.Collections;
using System.Collections.Generic;
public class CanvasManager : MonoBehaviour {
public CanvasGroup bloodPowerCanvas;
public CanvasGroup dialACode;
[Header("Phone View")]
public CanvasGroup phoneCanvas;
public CanvasGroup notification;
public CanvasGroup containerCanvas;
private const float NOTIFICATION_DELAY = 5f;
private static CanvasManager instance;
public static CanvasManager Instance {
get {
if(instance == null) {
instance = GameObject.FindObjectOfType<CanvasManager>();
}
return instance;
}
}
void Start(){
DisplayDialACode(false);
SetVisible(bloodPowerCanvas, true);
SetVisible(notification, false);
SetVisible(containerCanvas, false);
SetVisible(phoneCanvas, false);
}
public void DisplayDialACode(bool on = true) {
if(dialACode != null)
SetVisible(dialACode, on);
}
// public void TogglePhoneCanvas(){
// bool on = !phoneCanvas.interactable;
// SetVisible(phoneCanvas, on);
// if(!on){
// UIManager.Instance.CloseInventory();
//// SetVisible(containerCanvas, false);
// }
//// ToggleCanvas(phoneCanvas, true);
// }
public void DisplayPhoneCanvas(bool on = true){
// if(!on)
// UIManager.Instance.CloseInventory();
SetVisible(phoneCanvas, on);
}
void ToggleCanvas(CanvasGroup canvas, Dialogue dialogue){
bool on = !canvas.interactable;
SetVisible(canvas, on);
// CustomInputManager.EnableControls(on);
}
public void ToggleCanvas(CanvasGroup canvas) {
bool on = !canvas.interactable;
SetVisible(canvas, on);
}
public void SetVisible(CanvasGroup canvas, bool on) {
canvas.alpha = on ? 1f : 0f;
canvas.interactable = canvas.blocksRaycasts = on;
}
public void EnableBloodCanvas(bool on){
bloodPowerCanvas.alpha = on ? 1f : 0f;
}
public void ShowNotification(string message){
SetVisible(notification, true);
notification.GetComponentInChildren<Text>().color = Color.white;
notification.GetComponentInChildren<Text>().text = message;
StartCoroutine(SetVisibleDelayed(notification, false, NOTIFICATION_DELAY));
}
public void ShowNotification(string message, Globals.Conviction conviction, int step = 0){
// Debug.Log("Notifying " + message);
SetVisible(notification, true);
Color color = GameModel.GetConvictionColor(conviction);
notification.GetComponentInChildren<Text>().color = color;
notification.GetComponentInChildren<Text>().text = message;
StartCoroutine(SetVisibleDelayed(notification, false, NOTIFICATION_DELAY));
}
IEnumerator SetVisibleDelayed(CanvasGroup canvas, bool on, float sec){
yield return new WaitForSeconds(sec);
SetVisible(canvas, on);
}
public void DisplayContainer(bool on = true){
SetVisible(containerCanvas, on);
}
void ClearContainerItems(){
ItemUI[] containerItems = UIManager.ContainerPanel.GetComponentsInChildren<ItemUI>();
foreach (ItemUI child in containerItems) {
GameObject.Destroy(child.gameObject);
}
}
}