Tanoda
BlurTheScene.cs
Go to the documentation of this file.
1using System.Collections;
2using System.Collections.Generic;
3using UnityEngine.UI;
4using UnityEngine;
5using System.Diagnostics;
6
7public class BlurTheScene : MonoBehaviour
8{
9 public GameObject canvas;
10 public GameObject blurImage, blurImage2;
11 public GameObject blur;
12 public GameObject Sound2;
13 public GameObject Sound3;
14 public GameObject Sound4;
15 public GameObject[] Elements;
16 public GameObject OtherElements;
17 public static BlurTheScene Instance;
18 public Text Command;
19
20 float random = 40.0f;
21 //public GameObject showBlur()
22 //{
23 // blurImage.SetActive(true);
24 // StartCoroutine(SetAlpha(0, 0.3f));
25 // return blurImage;
26 //}
27 public void Start()
28 {
29 Instance = this;
30
31 }
32
33 public void Update()
34 {
35
36
37 for (int i = 0; i < Elements.Length; i++)
38 {
39 random = Random.Range(10.0f, 200.0f);
40 var previousScale = Elements[i].GetComponent<RectTransform>().sizeDelta;
41 //if (Elements[i].GetComponent<RectTransform>().sizeDelta.y >= random*0.95f && Elements[i].GetComponent<RectTransform>().sizeDelta.y <= random*1.05f )
42 //{
43 // random = Random.Range(10.0f, 200.0f);
44 //}
45
46
47 previousScale.y = Mathf.Lerp(previousScale.y, random, Time.deltaTime * 10);
48 Elements[i].GetComponent<RectTransform>().sizeDelta = previousScale;
49
50 }
51
52 }
53 private void OnDisable()
54 {
55
56 }
57 public void showBlur(Process p, string text)
58 {
59 canvas.SetActive(true);
60 OtherElements.SetActive(true);
61 StartCoroutine(SetAlpha(0, 1f, false));
62 StartCoroutine(Speaker(p));
63 Command.text = text;
64 }
65
66 public void hideBlur()
67 {
68 OtherElements.SetActive(false);
69 StartCoroutine(SetAlpha(1f, 0, true));
70
71 }
72
73 IEnumerator SetAlpha(float startAlpha, float endAlpha, bool hide)
74 {
75 UnityEngine.Debug.Log("szia");
76 yield return null;
77 float time = 0;
78 float duration = 0.5f;
79 var cggo = blurImage.GetComponent<CanvasGroup>();
80 var blurgo = blur.GetComponent<Image>().material;
81 var imageAlpha = blurImage2.GetComponent<Image>().material.GetColor("_Color");
82 while (time <= duration)
83 {
84 time += Time.deltaTime;
85 cggo.alpha = Mathf.Lerp(startAlpha, endAlpha, time / duration);
86 blurgo.SetFloat("_BumpAmt", cggo.alpha * 10);
87 imageAlpha.a = cggo.alpha * 155;
88 //alpha.a = Mathf.Lerp(startAlpha, endAlpha, time / duration);
89 yield return null;
90 }
91 if (hide)
92 {
93 canvas.SetActive(false);
94 }
95 }
96
97 IEnumerator Speaker(Process p)
98 {
99 while (!p.HasExited)
100 {
101 if (!Sound2.activeInHierarchy)
102 {
103 Sound2.SetActive(true);
104 yield return new WaitForSeconds(0.5f);
105 }
106 if (!Sound3.activeInHierarchy)
107 {
108 Sound3.SetActive(true);
109 yield return new WaitForSeconds(0.5f);
110 }
111 if (!Sound4.activeInHierarchy)
112 {
113 Sound4.SetActive(true);
114 yield return new WaitForSeconds(0.5f);
115 }
116 if (Sound2.activeInHierarchy && Sound3.activeInHierarchy && Sound4.activeInHierarchy)
117 {
118 Sound2.SetActive(false);
119 Sound3.SetActive(false);
120 Sound4.SetActive(false);
121 yield return new WaitForSeconds(0.5f);
122 }
123 }
124 }
125}
UnityEngine.Random Random
System.Drawing.Image Image
Definition: TestScript.cs:37
GameObject[] Elements
Definition: BlurTheScene.cs:15
GameObject Sound2
Definition: BlurTheScene.cs:12
GameObject OtherElements
Definition: BlurTheScene.cs:16
GameObject blurImage2
Definition: BlurTheScene.cs:10
void showBlur(Process p, string text)
Definition: BlurTheScene.cs:57
GameObject canvas
Definition: BlurTheScene.cs:9
void Update()
Definition: BlurTheScene.cs:33
GameObject Sound4
Definition: BlurTheScene.cs:14
GameObject blurImage
Definition: BlurTheScene.cs:10
static BlurTheScene Instance
Definition: BlurTheScene.cs:17
void Start()
Definition: BlurTheScene.cs:27
void hideBlur()
Definition: BlurTheScene.cs:66
GameObject blur
Definition: BlurTheScene.cs:11
GameObject Sound3
Definition: BlurTheScene.cs:13