-
Notifications
You must be signed in to change notification settings - Fork 32
/
KethaneDetectorAnimatorUnity.cs
44 lines (36 loc) · 1.26 KB
/
KethaneDetectorAnimatorUnity.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
using UnityEngine;
namespace Kethane.PartModules
{
public class KethaneDetectorAnimatorUnity : PartModule, IDetectorAnimator
{
public bool IsDetecting { private get; set; }
public float PowerRatio { private get; set; }
[KSPField(isPersistant = false)]
public string DeployAnimation;
[KSPField(isPersistant = false)]
public string RunningAnimation;
private AnimationState[] deployStates;
private AnimationState[] runningStates;
public override void OnStart(PartModule.StartState state)
{
deployStates = this.part.SetUpAnimation(DeployAnimation);
runningStates = this.part.SetUpAnimation(RunningAnimation);
foreach (var runningState in runningStates)
{
runningState.wrapMode = WrapMode.Loop;
}
}
public override void OnUpdate()
{
foreach (var state in deployStates)
{
state.normalizedTime = Mathf.Clamp01(state.normalizedTime);
state.speed = IsDetecting ? PowerRatio : -1;
}
foreach (var state in runningStates)
{
state.speed = IsDetecting ? PowerRatio : 0;
}
}
}
}