summaryrefslogtreecommitdiff
path: root/Client/Assembly-CSharp/PlayerParticles.cs
blob: 4f7cf4ade306356ee6f5f28b1c1bb7b1f71900b0 (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
using System;
using UnityEngine;

public class PlayerParticles : MonoBehaviour
{
	public PlayerParticleInfo[] Sprites;

	public FloatRange velocity;

	public FloatRange scale;

	public ObjectPoolBehavior pool;

	public float StartRadius;

	public Camera FollowCamera;

	private RandomFill<PlayerParticleInfo> fill;

	public void Start()
	{
		this.fill = new RandomFill<PlayerParticleInfo>();
		this.fill.Set(this.Sprites);
		int num = 0;
		while (this.pool.NotInUse > 0)
		{
			PlayerParticle playerParticle = this.pool.Get<PlayerParticle>();
			PlayerControl.SetPlayerMaterialColors(num++, playerParticle.myRend);
			this.PlacePlayer(playerParticle, true);
		}
	}

	public void Update()
	{
		while (this.pool.NotInUse > 0)
		{
			PlayerParticle part = this.pool.Get<PlayerParticle>();
			this.PlacePlayer(part, false);
		}
	}

	private void PlacePlayer(PlayerParticle part, bool initial)
	{
		Vector3 vector = UnityEngine.Random.insideUnitCircle;
		if (!initial)
		{
			vector.Normalize();
		}
		vector *= this.StartRadius;
		float num = this.scale.Next();
		part.transform.localScale = new Vector3(num, num, num);
		vector.z = -num * 0.001f;
		if (this.FollowCamera)
		{
			Vector3 position = this.FollowCamera.transform.position;
			position.z = 0f;
			vector += position;
			part.FollowCamera = this.FollowCamera;
		}
		part.transform.localPosition = vector;
		PlayerParticleInfo playerParticleInfo = this.fill.Get();
		part.myRend.sprite = playerParticleInfo.image;
		part.myRend.flipX = BoolRange.Next(0.5f);
		Vector2 vector2 = -vector.normalized;
		vector2 = vector2.Rotate(FloatRange.Next(-45f, 45f));
		part.velocity = vector2 * this.velocity.Next();
		part.angularVelocity = playerParticleInfo.angularVel.Next();
		if (playerParticleInfo.alignToVel)
		{
			part.transform.localEulerAngles = new Vector3(0f, 0f, Vector2.up.AngleSigned(vector2));
		}
	}
}