blob: bb238dab857726e2bf5ab8844e7b5e879dc5a58c (
plain)
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
136
137
138
139
140
141
142
143
144
145
|
using System.Collections;
using SoundImplementation;
using UnityEngine;
using UnityEngine.Events;
public class MapTransition : MonoBehaviour
{
[Header("Settings")]
public UnityEvent switchMapEvent;
public AnimationCurve curve;
public AnimationCurve gravityCurve;
public static MapTransition instance;
private const float mapPadding = 90f;
public static bool isTransitioning;
private void Awake()
{
instance = this;
}
private void Start()
{
}
public void SetStartPos(Map map)
{
map.transform.position = Vector3.right * 90f;
}
public void Enter(Map map)
{
MoveObject(map.gameObject, Vector3.zero);
StartCoroutine(DelayEvent(0.1f));
SoundPlayerStatic.Instance.PlayLevelTransitionIn();
SoundMusicManager.Instance.PlayIngame(isCard: false);
}
public void Exit(Map map)
{
SoundPlayerStatic.Instance.PlayLevelTransitionOut();
map.MapMoveOut();
MoveObject(map.gameObject, Vector3.right * -90f);
StartCoroutine(ClearObjectsAfterSeconds(1f));
}
private void MoveObject(GameObject target, Vector3 targetPos)
{
for (int i = 0; i < target.transform.childCount; i++)
{
Toggle(target.transform.GetChild(i).gameObject, enabled: false);
StartCoroutine(Move(target.transform.GetChild(i).gameObject, targetPos - target.transform.position, (i == 0) ? target.GetComponent<Map>() : null));
}
}
private void Toggle(GameObject obj, bool enabled)
{
Rigidbody2D component = obj.GetComponent<Rigidbody2D>();
if ((bool)component)
{
component.simulated = enabled;
if (enabled)
{
StartCoroutine(LerpDrag(component));
}
}
Collider2D component2 = obj.GetComponent<Collider2D>();
if ((bool)component2)
{
component2.enabled = enabled;
}
CodeAnimation component3 = obj.GetComponent<CodeAnimation>();
if ((bool)component3)
{
component3.enabled = enabled;
}
}
private IEnumerator DelayEvent(float delay)
{
yield return new WaitForSecondsRealtime(delay);
switchMapEvent.Invoke();
}
private IEnumerator Move(GameObject target, Vector3 distance, Map targetMap = null)
{
isTransitioning = true;
float maxRandomDelay = 0.25f;
float randomDelay = Random.Range(0f, maxRandomDelay);
yield return new WaitForSecondsRealtime(randomDelay);
Vector3 targetStartPos = target.transform.position;
float t = curve.keys[curve.keys.Length - 1].time;
float c = 0f;
while (c < t)
{
c += Time.unscaledDeltaTime;
target.transform.position = targetStartPos + distance * curve.Evaluate(c);
yield return null;
}
target.transform.position = targetStartPos + distance;
Toggle(target, enabled: true);
yield return new WaitForSecondsRealtime(maxRandomDelay - randomDelay);
isTransitioning = false;
if ((bool)targetMap)
{
targetMap.hasEntered = true;
}
}
private IEnumerator LerpDrag(Rigidbody2D target)
{
target.gravityScale = 0f;
float t = gravityCurve.keys[gravityCurve.keys.Length - 1].time;
float c = 0f;
while (c < t && (bool)target)
{
target.gravityScale = gravityCurve.Evaluate(c);
c += Time.unscaledDeltaTime;
yield return null;
}
if ((bool)target)
{
target.gravityScale = 1f;
}
}
private IEnumerator ClearObjectsAfterSeconds(float time)
{
yield return new WaitForSecondsRealtime(time);
ClearObjects();
}
public void ClearObjects()
{
RemoveAfterSeconds[] array = Object.FindObjectsOfType<RemoveAfterSeconds>();
for (int i = 0; i < array.Length; i++)
{
Object.Destroy(array[i].gameObject);
}
}
}
|