summaryrefslogtreecommitdiff
path: root/Thronefall_1_57/Decompile/NGS.MeshFusionPro/RigidbodyTrackingStrategy.cs
blob: 763f666c053dcd9a0e93c226445d90c9ba71ea21 (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
using UnityEngine;

namespace NGS.MeshFusionPro;

public class RigidbodyTrackingStrategy : ISourceTrackingStrategy
{
	private Rigidbody _rigidbody;

	private Transform _transform;

	private DynamicCombinedObjectPart[] _parts;

	private float _velocityThreashold = 0.5f;

	private float _angularVelocityThreashold = 0.3f;

	public float VelocityThreashold
	{
		get
		{
			return _velocityThreashold;
		}
		set
		{
			_velocityThreashold = Mathf.Max(0f, value);
		}
	}

	public float AngularVelocityThreashold
	{
		get
		{
			return _angularVelocityThreashold;
		}
		set
		{
			_angularVelocityThreashold = Mathf.Max(0f, value);
		}
	}

	public RigidbodyTrackingStrategy(Rigidbody target, DynamicCombinedObjectPart[] parts)
	{
		_rigidbody = target;
		_transform = target.transform;
		_parts = parts;
	}

	public bool OnUpdate()
	{
		float magnitude = _rigidbody.velocity.magnitude;
		float magnitude2 = _rigidbody.angularVelocity.magnitude;
		if (magnitude > _velocityThreashold || magnitude2 > _angularVelocityThreashold)
		{
			for (int i = 0; i < _parts.Length; i++)
			{
				_parts[i].Move(_transform.localToWorldMatrix);
			}
			return true;
		}
		return false;
	}
}