-
Notifications
You must be signed in to change notification settings - Fork 0
/
ShipThrusterAnimator.cs
105 lines (94 loc) · 3.41 KB
/
ShipThrusterAnimator.cs
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
using UnityEngine;
using System.Collections.Generic;
namespace ExpeditionTakeoff;
[ExecuteInEditMode]
public class ShipThrusterAnimator : MonoBehaviour
{
[SerializeField]
private GameObject[] _targetThrusters;
[Range(0f, 1f)][SerializeField] private float rightRightThruster;
[Range(0f, 1f)][SerializeField] private float rightTopThruster;
[Range(0f, 1f)][SerializeField] private float rightBottomThruster;
[Range(0f, 1f)][SerializeField] private float rightBackThruster;
[Range(0f, 1f)][SerializeField] private float rightFrontThruster;
[Range(0f, 1f)][SerializeField] private float leftFrontThruster;
[Range(0f, 1f)][SerializeField] private float leftBackThruster;
[Range(0f, 1f)][SerializeField] private float leftBottomThruster;
[Range(0f, 1f)][SerializeField] private float leftTopThruster;
[Range(0f, 1f)][SerializeField] private float leftLeftThruster;
[SerializeField] private bool syncYThrusters;
[SerializeField] private bool syncZThrusters;
private TitleShipAudioController _audioController;
private float _thrusterLightIntensity = 0.3f;
private float _thrusterLightRange = 150f;
private float[] _thrusterValues = [];
private List<Light> _thrusterLights = [];
private void Start()
{
for (int i = 0; i < _targetThrusters.Length; i++)
{
_thrusterLights.Add(_targetThrusters[i].GetComponentInChildren<Light>());
_thrusterLights[i].intensity = _thrusterLightIntensity;
_thrusterLights[i].range = _thrusterLightRange;
}
}
private void Update()
{
_thrusterValues =
[
rightRightThruster,
rightTopThruster,
rightBottomThruster,
rightBackThruster,
rightFrontThruster,
leftFrontThruster,
leftBackThruster,
leftBottomThruster,
leftTopThruster,
leftLeftThruster
];
if (_targetThrusters.Length == 0 || _thrusterValues.Length != _targetThrusters.Length)
{
Debug.LogError("Check the thruster/value lists, something is wrong with them.");
return;
}
if (syncYThrusters)
{
leftBottomThruster = rightBottomThruster;
leftTopThruster = rightTopThruster;
}
if (syncZThrusters)
{
leftFrontThruster = rightFrontThruster;
leftBackThruster = rightBackThruster;
}
for (int i = 0; i < _targetThrusters.Length; i++)
{
_targetThrusters[i].transform.localScale = Vector3.one * _thrusterValues[i];
if (_thrusterValues[i] != 0f)
{
_thrusterLights[i].enabled = true;
_thrusterLights[i].range = _thrusterLightRange * _thrusterValues[i];
_targetThrusters[i].GetComponent<MeshRenderer>().enabled = true;
}
else
{
_thrusterLights[i].enabled = false;
_targetThrusters[i].GetComponent<MeshRenderer>().enabled = false;
}
}
}
private void OnDisable()
{
ExpeditionTakeoff.Instance.StopAllCoroutines();
}
public float GetThrustMagnitude()
{
float total = 0f;
foreach (float value in _thrusterValues)
{
total += value;
}
return Mathf.Min(total, 2f) / 2f;
}
}