summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/FollowerCamera.cs
blob: 31845426a659bca4bfb00819c9b4e248e1f91303 (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
using System;
using System.Collections;
using UnityEngine;

internal class FollowerCamera : MonoBehaviour
{
	public MonoBehaviour Target;

	public Vector2 Offset;

	public bool Locked;

	public float shakeAmount;

	public float shakePeriod = 1f;

	public void FixedUpdate()
	{
		if (this.Target && !this.Locked)
		{
			base.transform.position = Vector3.Lerp(base.transform.position, this.Target.transform.position + this.Offset, 5f * Time.deltaTime);
			if (this.shakeAmount > 0f)
			{
				float num = Mathf.PerlinNoise(0.5f, Time.time * this.shakePeriod) * 2f - 1f;
				float num2 = Mathf.PerlinNoise(Time.time * this.shakePeriod, 0.5f) * 2f - 1f;
				base.transform.Translate(num * this.shakeAmount, num2 * this.shakeAmount, 0f);
			}
		}
	}

	public void ShakeScreen(float duration, float severity)
	{
		base.StartCoroutine(this.CoShakeScreen(duration, severity));
	}

	private IEnumerator CoShakeScreen(float duration, float severity)
	{
		WaitForFixedUpdate wait = new WaitForFixedUpdate();
		for (float t = duration; t > 0f; t -= Time.fixedDeltaTime)
		{
			float d = t / duration;
			this.Offset = UnityEngine.Random.insideUnitCircle * d * severity;
			yield return wait;
		}
		this.Offset = Vector2.zero;
		yield break;
	}

	internal void SetTarget(MonoBehaviour target)
	{
		this.Target = target;
		base.transform.position = this.Target.transform.position + this.Offset;
	}
}