blob: d845eae4e9a4dc63f70b5b3d81882b241bd7e5e6 (
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
|
using UnityEngine;
public class Screenshaker : GameFeeler
{
public bool ignoreTimeScale;
public float spring = 100f;
public float damper = 100f;
public float shakeforce = 10f;
public float threshold;
private Vector2 velocity;
private float clamp = 100f;
private void Update()
{
float num = Mathf.Clamp(ignoreTimeScale ? Time.unscaledDeltaTime : TimeHandler.deltaTime, 0f, 0.015f);
velocity -= velocity.normalized * Mathf.Pow(velocity.magnitude, 0.8f) * damper * num;
velocity -= (Vector2)base.transform.localPosition * num * spring;
base.transform.position += (Vector3)velocity * num;
}
private void ShakeInternal(Vector2 direction)
{
if (!(direction.magnitude < threshold))
{
direction = Vector2.ClampMagnitude(direction, clamp);
velocity += direction * shakeforce;
}
}
public override void OnGameFeel(Vector2 feelDirection)
{
if (!ignoreTimeScale)
{
feelDirection = Vector2.ClampMagnitude(feelDirection, clamp);
ShakeInternal(feelDirection);
}
}
public override void OnUIGameFeel(Vector2 feelDirection)
{
if (ignoreTimeScale)
{
feelDirection = Vector2.ClampMagnitude(feelDirection, clamp);
ShakeInternal(feelDirection);
}
}
}
|