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

public class PlayerAnimator : MonoBehaviour
{
	public float Speed = 2.5f;

	public VirtualJoystick joystick;

	public SpriteRenderer UseButton;

	public FingerBehaviour finger;

	public AnimationClip RunAnim;

	public AnimationClip IdleAnim;

	private Vector2 velocity;

	[HideInInspector]
	private SpriteAnim Animator;

	[HideInInspector]
	private SpriteRenderer rend;

	public int NearbyConsoles;

	private void Start()
	{
		this.Animator = base.GetComponent<SpriteAnim>();
		this.rend = base.GetComponent<SpriteRenderer>();
		this.rend.material.SetColor("_BackColor", Palette.ShadowColors[0]);
		this.rend.material.SetColor("_BodyColor", Palette.PlayerColors[0]);
		this.rend.material.SetColor("_VisorColor", Palette.VisorColor);
	}

	public void FixedUpdate()
	{
		base.transform.Translate(this.velocity * Time.fixedDeltaTime);
		this.UseButton.enabled = (this.NearbyConsoles > 0);
	}

	public void LateUpdate()
	{
		if (this.velocity.sqrMagnitude >= 0.1f)
		{
			if (this.Animator.GetCurrentAnimation() != this.RunAnim)
			{
				this.Animator.Play(this.RunAnim, 1f);
			}
			this.rend.flipX = (this.velocity.x < 0f);
			return;
		}
		if (this.Animator.GetCurrentAnimation() == this.RunAnim)
		{
			this.Animator.Play(this.IdleAnim, 1f);
		}
	}

	public IEnumerator WalkPlayerTo(Vector2 worldPos, bool relax, float tolerance = 0.01f)
	{
		worldPos.y += 0.3636f;
		if (!(this.joystick is DemoKeyboardStick))
		{
			this.finger.ClickOn();
		}
		for (;;)
		{
			Vector2 vector2;
			Vector2 vector = vector2 = worldPos - base.transform.position;
			if (vector2.sqrMagnitude <= tolerance)
			{
				break;
			}
			float d = Mathf.Clamp(vector.magnitude * 2f, 0.01f, 1f);
			this.velocity = vector.normalized * this.Speed * d;
			this.joystick.UpdateJoystick(this.finger, this.velocity, true);
			yield return null;
		}
		if (relax)
		{
			this.finger.ClickOff();
			this.velocity = Vector2.zero;
			this.joystick.UpdateJoystick(this.finger, this.velocity, false);
		}
		yield break;
	}
}