-
Notifications
You must be signed in to change notification settings - Fork 0
/
GeneriqueHandler.cs
135 lines (99 loc) · 3.32 KB
/
GeneriqueHandler.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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using UnityEngine.UI;
public class GeneriqueHandler : MonoBehaviour {
public Transform subtitles;
public Transform focus;
public Camera subtitlesCam;
public float maxDistanceToCamera = 1.0f;
public float moveFactor = .5f;
public Canvas Lecanvas;
public Camera LaCamera;
float velocity = 0;
Vector3 trackPosition;
Vector3 origFocus;
public Image imagepanel;
public Sprite Name;
public Sprite Leave;
public CanvasGroup group;
public GameObject Sound;
public bool fadeIn = false;
public bool fadeOut = false;
void Awake()
{
trackPosition = subtitlesCam.transform.position;
origFocus = focus.position;
if (enabled && gameObject.activeSelf)
{
subtitlesCam.enabled = true;
transform.GetChild(0).gameObject.SetActive(true);
}
else
{
subtitlesCam.enabled = false;
transform.GetChild(0).gameObject.SetActive(false);
}
}
void Update()
{
// subtitlesCam.transform.position = Camera.main.transform.position;
focus.position = subtitlesCam.transform.position + (origFocus - Camera.main.transform.position);
subtitles.position = Vector3.Lerp(subtitles.position, trackPosition, moveFactor);
subtitles.LookAt(focus);
float distance = (trackPosition - subtitlesCam.transform.position).magnitude;
if (distance > maxDistanceToCamera)
trackPosition = subtitlesCam.transform.position;
if (fadeIn)
{
group.alpha = group.alpha + Time.deltaTime;
if (group.alpha >= 0.5F)
{
group.alpha = 0.5F;
fadeIn = false;
}
}
if (fadeOut)
{
group.alpha = group.alpha - Time.deltaTime;
if (group.alpha <= 0)
{
group.alpha = 0;
fadeOut = false;
}
}
}
/// Appelé lorsque le script ou l'objet est activé. Lance automatiquement la lecture vidéo des sous-titres
void OnEnable()
{
subtitlesCam.enabled = true;
transform.GetChild(0).gameObject.SetActive(true);
trackPosition = subtitlesCam.transform.position;
focus.position = subtitlesCam.transform.position + (origFocus - Camera.main.transform.position);
subtitles.position = trackPosition;
subtitles.LookAt(focus);
}
/// Appelé lors de la désactivation de l'objet ou du script. Masque les sous-titres.
void OnDisable()
{
subtitlesCam.enabled = false;
this.gameObject.GetComponentInChildren<Canvas>().enabled = false;
}
public IEnumerator Gen()
{
yield return new WaitForSeconds(3);
AkSoundEngine.PostEvent("generique", Sound);
yield return new WaitForSeconds(8);
fadeIn = true;
yield return new WaitForSeconds(7);
fadeOut = true;
yield return new WaitForSeconds(3.5f);
imagepanel.sprite = Name;
fadeIn = true;
yield return new WaitForSeconds(11f);
fadeOut = true;
yield return new WaitForSeconds(4f);
imagepanel.sprite = Leave;
fadeIn = true;
}
}